3 Replies Latest reply on Jun 18, 2011 11:44 AM by fac586

    Can APEX_ITEM be used to generate a Form page?

    TamasSzecsy
      Hi,

      I would like to use APEX_ITEM to generate in APEX 4.0 a Form region at runtime, based on some meta tables that describe the columns, labels, datatypes etc..

      It seems that people use APEX_ITEM for generating updatable tabular form and I start to question my original concept. I created a PL/SQL Anonymous block region, that contains the following code segment:

      htp.p(
      APEX_ITEM.SELECT_LIST (
      3,
      'Y',
      'Yes;Y,No;N',
      'Y',
      '',
      '',
      'readonly=readonly',
      'P1_MARRIED',
      'Married'
      )
      );

      When I run my form and click my 'Session' link at the botom of the page, the P1_MARRIED item would not show up in the item list of the page. Am I missing something or this 'Generate a Form region at runtime' concept is based on my missunderstanding of APEX_ITEM API?

      Regards, Tamas
        • 1. Re: Can APEX_ITEM be used to generate a Form page?
          fac586
          When I run my form and click my 'Session' link at the botom of the page, the P1_MARRIED item would not show up in the item list of the page. Am I missing something or this 'Generate a Form region at runtime' concept is based on my missunderstanding of APEX_ITEM API?
          It is not possible to dynamically generate actual APEX page items.

          <tt>apex_item</tt> API methods can be used in reports and PL/SQL regions to render controls on the page, but these do not exist as page items. Such controls submit their values in a different way, using associative arrays defined in the <tt>apex_application</tt> package, and validating and processing them is therefore different from page items. See Referencing Arrays in the APEX API Reference for information on how to access values of items created using <tt>apex_item</tt> methods. These array values are not stored permanently in session state in the same way as page items, and are therefore not available in the Session State pop-up.

          The <tt>p_item_id</tt> parameter in <tt>apex_item</tt> API methods generates an idHTML <tt>id</tt> attribute for use as a CSS, jQuery or DOM selector within the rendered page. It serves no purpose (and cannot be referenced or accessed) server-side.

          In summary: Yes, <tt>apex_item</tt> can be used to generate a form page, but the result is not a form page comprised of APEX page items.
          • 2. Re: Can APEX_ITEM be used to generate a Form page?
            TamasSzecsy
            Thanks, that was enlightening!

            So if I understand it well, it means that:

            1.) I have to give my region 'Form like' layout by using htp.p appropriately.
            2.) What concerns the update processing, it means I should handle the region as a 1-record report i.e. using Fxx arrays but always referencing the first member of each Fxx array only: APEX_APPLICATION.G_Fxx (1)
            3.) I am OK, provided that I generate maximum 50 items on a page, since 50 is a hard-coded limit that can not be gotten around. (I will have to work out solution for this, since i have 53 columns in the given table)
            • 3. Re: Can APEX_ITEM be used to generate a Form page?
              fac586
              Tamas Szecsy wrote:
              Thanks, that was enlightening!

              So if I understand it well, it means that:

              1.) I have to give my region 'Form like' layout by using htp.p appropriately.
              Yes. A custom named column report template is another useful approach.
              2.) What concerns the update processing, it means I should handle the region as a 1-record report i.e. using Fxx arrays but always referencing the first member of each Fxx array only: APEX_APPLICATION.G_Fxx (1)
              Yes, unless there are actually any 1:M elements (home, work, and mobile phone numbers/email addresses for example), where the same type of element is repeated. (This might also help with point 3...)

              Note also that disabled items are not submitted, and only checked checkboxes are submitted
              3.) I am OK, provided that I generate maximum 50 items on a page, since 50 is a hard-coded limit that can not be gotten around. (I will have to work out solution for this, since i have 53 columns in the given table)
              Dividing the form into several wizard-style pages as used in the APEX Application Builder is probably the best solution to this. It enables you to keep the sub-form pages simple, clean and short, so users don't have to scroll up and down. Save the submitted values from each sub-form page in APEX collections, and display a final report based on the collection(s) for the user to review before saving the information to the database table.

              Alternatively, some of these columns might be common across all the form permutations, and implementable using standard page items.