Accessing the row selector of a tabular form

Maybe you already had the “joy” to find out that accessing the “Row Selector” column of an updateable tabular form isn’t that straightforward as expected. Because the corresponding g_f01 array isn’t indexed by row number as the other column-arrays of the tabular form.

Instead it contains as many values as you have checked rows. The value of the array entry contains the “real” row number for which it has been checked. So you can have the situation that g_f01 has a count of 2, but your g_f02 containing the EMPNO contains 15 rows. In the case if the g_f02 is your “driving” array, because you want to process all the records and only for the checked ones you want to do something special, it can get really challenging for a new APEX programmer (and even for a more experienced one).

That’s why I have added new functionality to my Plug & play tabular form handling package, to make accessing the row selector as easy and straightforward as possible.

The package ApexLib_TabForm now contains the additional methods isRowSelectorChecked, setRowSelector. The hasRowChanged has been enhanced to also check for the row selector column.

Let’s demonstrate the new functions with an example!

BEGIN
    FOR ii IN 1 .. ApexLib_TabForm.getRowCount
    LOOP
        IF ApexLib_TabForm.hasRowChanged(ii, TRUE)
        THEN
            IF ApexLib_TabForm.isRowSelectorChecked(ii)
            THEN
                callAbc
                  ( pEmpNo    => ApexLib_TabForm.NV('EMPNO', ii)
                  , pEname    => ApexLib_TabForm.V ('ENAME', ii)
                  , pHireDate => ApexLib_TabForm.DV('HIRE_DATE', ii)
                  );
            ELSE
                callXyz
                  ( pEmpNo    => ApexLib_TabForm.NV('EMPNO', ii)
                  , pEname    => ApexLib_TabForm.V ('ENAME', ii)
                  , pHireDate => ApexLib_TabForm.DV('HIRE_DATE', ii)
                  );
            END IF;
        END IF;
    END LOOP;
END;

This example demonstrates several features of the ApexLib_TabForm package.

  • With getRowCount you don’t have to care that you use the correct g_fxx array to process all records. Remember: If you have a row selector, g_f01 just contains as many records as you have checked values. So you would have to use g_f02 in that case.
  • hasRowChanged compares the old- with the new checksum, to verify if the record has been changed. If the new additional boolean parameter pIncludeRowSelector is set to TRUE, the row selector column will also be checked.
  • isRowSelectorChecked will return TRUE if the checkbox has been set for that row.
  • NV, V and DV to access the column by name. You don’t have to worry anymore that when somebody is resorting the columns of the report, that it will break your code. This functions will also return the value of the column with the correct PL/SQL data type by applying the format mask which is defined for the column.

Get the source code from the original posting and try it out!

6 thoughts on “Accessing the row selector of a tabular form

  1. Hi Patrik
    We have a problem with master detail forms using APEX.
    In our master form, we have txn_id as primary key & the detail table is having (txn_id,sub_txn_id) as primary key.If i use the wizard & create master detail, it doesn’t work as expected.Both the P.K.s are sequence generated. The trouble seems to be with the restrictions of PK using master detail. Do you have any idea which can be helpful.

  2. should your example read:

    pEmpNo => ApexLib_TabForm.NV(‘EMPNO’,ii);
    Wrong Number of Variables in 0.16

    Also does this package work also for row selctor in reports (Updatable SQL) where the primary key is hidden with no refernce to the underlying schema, table, and column?

    Regards,

    Mike

  3. Hi Mike,

    thanks! I have corrected the example.

    The package will work for an updateable report where the primary key is hidden, because the APEX row selector doesn’t store the primary key as checked value, it just stores the record position (1-9999) on the screen. So when you loop through the records from 1 .. ApexLib_TabForm.getRowCount the ApexLib_TabForm.isRowSelectorChecked(ii) function will just check if the row selector is checked for the passed record number (ii). No PK, … involved in that.

    Hope that helps you
    Patrick

  4. Hi Patrick.

    Can I mark ‘CHECKED’ Row Selector Checkboxes according to a field value ?
    e.g. if i have a Boolean field ‘AdminAccess’, Currently i am displaying its value in another Check box. I want RowSelector Check box to display Checked/Unchecked as to display ‘AdminAccess’ value

    Thanks
    junaid

  5. Is there a way to do what Junald mentions? I’d like to be able to have the [row selector] checkbox checked based on the value of another column in the report. This would be for display when the page first loads, not after submit.

  6. Hi,

    I run into not being able to process report regions with a condition.
    I’ve changed the init function a little from:
    vProcess :=
    CASE rREG.CONDITION_TYPE
    WHEN ‘ITEM_IS_NULL’ THEN ApexLib_Util.getStringSessionValue(rREG.CONDITION_EXPRESSION1) IS NULL
    WHEN ‘ITEM_IS_NOT_NULL’ THEN ApexLib_Util.getStringSessionValue(rREG.CONDITION_EXPRESSION1) IS NOT NULL
    ELSE FALSE
    END;
    To

    CASE
    WHEN rREG.CONDITION_TYPE = ‘ITEM_IS_NULL’
    THEN ApexLib_Util.getStringSessionValue(rREG.CONDITION_EXPRESSION1) IS NULL

    WHEN rREG.CONDITION_TYPE = ‘ITEM_IS_NOT_NULL’
    THEN ApexLib_Util.getStringSessionValue(rREG.CONDITION_EXPRESSION1) IS NOT NULL

    WHEN upper(rREG.CONDITION_TYPE) = ‘VALUE OF ITEM IN EXPRESSION 1 = EXPRESSION 2′
    THEN nvl( ApexLib_Util.getStringSessionValue(rREG.CONDITION_EXPRESSION1), rREG.CONDITION_EXPRESSION1 )
    = nvl( ApexLib_Util.getStringSessionValue(rREG.CONDITION_EXPRESSION2), rREG.CONDITION_EXPRESSION2 )

    WHEN upper(rREG.CONDITION_TYPE) = ‘VALUE OF ITEM IN EXPRESSION 1 != EXPRESSION 2′
    THEN nvl( ApexLib_Util.getStringSessionValue(rREG.CONDITION_EXPRESSION1), rREG.CONDITION_EXPRESSION1 )
    != nvl( ApexLib_Util.getStringSessionValue(rREG.CONDITION_EXPRESSION2), rREG.CONDITION_EXPRESSION2 )

    ELSE FALSE
    END;

    to be able to process regions with a ‘value of item in expression 1 = expression 2′ or ‘value of item in expression 1 != expression 2′ condition.

    Maybe usefull to someone :)

    Greetz,
    Diana

Comments are closed.