Book Image

Oracle APEX Cookbook : Second Edition

Book Image

Oracle APEX Cookbook : Second Edition

Overview of this book

Table of Contents (21 chapters)
Oracle APEX Cookbook Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a list of values


When you use forms with items that are Foreign Keys to other tables, it would be handy to derive the Primary Key from the lookup table instead of having to enter this ID manually in the text field. Or, when dealing with lots of similar, predefined data, you don't want to enter the same values over and over again. In those cases, you would want to use items such as listboxes, quick picks, or lists of values which display the data of the lookup items where the user can easily pick the right value.

In this recipe, we'll create a list of values. A list of values can not only be a list of predefined static values but it can also be a dynamic list with data retrieved from a table. We will create a static list of values. A list of values is a shared component so it can be used in more pages.

Getting ready

The starting point is an existing application like the one we created. To define a list of values, you don't need to have a page. However, to make use of a list of values, you must define an item with a reference to the list of values. We will make a list of values on the JOB column.

How to do it...

There are two ways to start the Create List of Values wizard. The first one is in the Edit page.

On the right-hand side of the screen, under Shared Components, click on the Add icon under List Of Values.

The second one is via Shared Components:

  1. In the Applic ation Builder, navigate to Shared Components | List Of Values. On the List Of Values page, click on the Create button.

  2. You can create a list of values from scratch or you can copy an existing list of values and make some modifications to the newly created list of values. In our case, we will create a list of values from scratch. Click on Next.

  3. Enter a name for the list of values, Jobs for example, and select Dynamic or Static. Choose Static and click on Next.

    In the next step, you can enter the desired values. There are two types of values: the display value and the return value. The display value indicates how it is displayed and the return value is the value which will be returned into the text item the list of values is called from:

    After you have entered the values, click on the Create List of Values button.

    The list of values is created and can now be used by items. To assign an existing item to the list of values, go to the page where you want to include your list of values. In this case, we go to the tabular form based on the EMP table that we created in the Creating a simple form page recipe.

  4. Click on the R egions section on the Report link. Click on the pencil icon near the Job column.

  5. In the Tabular Form Element section, select select list (named lov) at the Display As field.

  6. Next, in the List Of Values section, at the Named Lov field, select the list of values you just created.

  7. Click on the Apply Changes button.

  8. Run the form to see the result. It should look like the following:

How it works...

The list of values serves as a source for items types such as a list box or pop-up list of values. A list of values contains two columns: a display column and a column with the return value. This return value will be the actual data which will be stored in the item which is assigned to the list of values.

A list item can also be created directly upon a report column or item, but then is not reusable.

There's more...

Another possibility is to use a previously defined list of values as a basis when creating a new item. This is useful in situations where you want to reuse a list of values on more than one occasion. A question that requires the answer Yes or No for example, can return on many pages in an application:

  1. Go to the page where you want to have the item.

  2. Right-click on the Items section of the region where the item should go and select Create Page Item.

  3. In the Select Item Type dialog, click on the Select List.

  4. In the next step, enter a name for the item. You may also enter a sequence number and the region where the item should appear. Click on Next.

  5. In this step, provide some additional information such as the label, the height, and the alignment. Click on Next.

  6. Next, define what APEX should do when you select some value from the list. You can redirect the user to another page or you can submit the page. Another option in this step is the indication whether APEX should allow multiselection. Leave this option to No and click on Next.

  7. In the next step, enter the name of the existing list of values that you want to use in the Named LOV field. Leave the other options and click on Next.

  8. In the last step, define the source of the item. Leave the options and click on the Create Item button.