Setting default item settings with apex_ui_default_update

When you create a form or a report, most of the time this is done with the help of a wizard. It is very easy for the most common things but if you want a different width of a text item, other than the default width, you have to do this afterwards. When you have a lot of items on your screen this could be very cumbersome. In this recipe, we will show you how to set the default width of columns with the APEX_UI_DEFAULT_UPDATE.UPD_ITEM_DISPLAY_WIDTH procedure. We will set the default width of column EVENT in table APP_EVENTS to 200.

Getting ready

Before you can use this function, the table needs to be included in the APEX dictionary. The view APEX_UI_DEFAULTS_COLUMNS holds the columns and their default width. You can add your table to this dictionary view by doing the following:

  1. In APEX, go to SQL workshop.
  2. Click Utilities.
  3. Click User interface defaults.
  4. Click the Manage table dictionary button.
  5. Click the Synchronize button on the right side of the screen.
  6. You will see a small report which shows the objects with defaults and the objects without defaults. Click the Synchronize defaults button. When APEX is ready, you will see a success message. All the tables in the schema that is linked to your workspace are now in the APEX dictionary.
  7. You can also synchronize in SQL plus. Log in as the table owner and issue the following command:
    exec apex_ui_default_update.synch_table('APP_EVENTS'),
    

[1346_07_11.txt]

The only difference is that in the APEX builder, all tables will be included at once and in SQL plus you have to do this for every table separately (OK, you could write a script).

If you ignore these steps, the table with the columns you wish to set the default width for might not be in the APEX dictionary, and the steps in the next paragraph will lead to a "ORA-20001: UI Default update failed - there is no associated table" error message.

How to do it...

  1. Go to SQL plus or an IDE where you can enter SQL commands. Log in to the schema where your tables for the APEX application reside.
  2. Enter the following command:
    begin
    apex_ui_default_update.upd_item_display_width(
    p_table_name => 'APP_EVENTS'
    ,p_column_name => 'EVENT'
    ,p_display_width => 200);
    end;
    /
    [1346_07_12.txt]
    

    This small procedure calls the APEX_UI_DEFAULT_UPDATE.UPD_ITEM_DISPLAY_WIDTH function and sets the display width of column EVENT in table APP_EVENTS to 200.

  3. To demonstrate the default width of the EVENT column, go to the application builder, go to your application, and click the Create page button.
  4. Select Form.
  5. Select Form on a table or view.
  6. Select the table or view owner and click Next.
  7. In the Table/view name text field, enter the name of the table, in this case APP_EVENTS. Click Next.
  8. Change the page number or the page name or the region title or change nothing at all and click Next.
  9. Select Do not use tabs and click Next.
  10. In the Primary key list box, select the primary key column of the APP_EVENTS table. In this case it is ID, so select ID and click Next.
  11. Select Existing sequence. In the Sequence list box, select the sequence used for this column. In this case, select APP_AET_SEQ and click Next.
  12. Select All columns and click Next.
  13. If you want, you can change the button labels. When you're done, click Next.
  14. Enter the page numbers where this page should navigate to after clicking on the buttons. You can also use the current page number. Click Next.
  15. Click Finish.
  16. Run the page and you will see that the Event text item has a width of 200.

How it works...

The call to the function actually updates the APEX dictionary view. You can see that when you do a query on APEX_UI_DEFAULT_COLUMNS where table_name is APP_EVENTS and column name is EVENT:

select table_name
, column_name
, label
, display_width
, display_in_form
from apex_ui_defaults_columns
where table_name = 'APP_EVENTS'
and column_name = 'EVENT';

[1346_07_13.txt]

The result is as follows:

How it works...

The display width is adjusted to 200.

There's more...

The APEX_UI_DEFAULT_UPDATE package contains more functions to set default values of tables or columns, for example form region title, item format mask and labels.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.234.188