This discussion is archived
12 Replies Latest reply: Mar 4, 2013 6:20 AM by JiriN. RSS

Dynamic action (Fire On Page Load) in apex 4.2

JiriN. Newbie
Currently Being Moderated
Hello experts,

we have upgraded our environment from v. 4.1 to v. 4.2.1.00.08.

During the testing of our appl. I found out one problem.

I have a page with tabular form based on a table. Then I have dynamic action which computes some values based on column values in each row of tabular form when the value is some column is changed. This DA should be also fired when the page is loaded ("Fire On Page Load" option).

In older version of apex the value was computed by DA (DA was fired) for all rows of tabular form on a page (e.g. 10x s when there were 10 rows), but now the value is computed only for the first row of tabular form.

Was the behavior of "Fire On Page Load" option somehow changed in the new apex version?

I have reproduced the problem on apex.oracle.com.

www.oracle.apex.com
username: kurin@centrum.cz
workspace: kurintest
passwd: kurintest
appl: 42522
page: 2

Thanks in advance for your help!

Regards,

Jiri
  • 1. Re: Dynamic action (Fire On Page Load) in apex 4.2
    AnthonyRayner Pro
    Currently Being Moderated
    Hi Jiri,

    In trying to get to the bottom of this, is it ok to make changes to your application, or perhaps I could make a copy of your page in that application and then make changes there?

    Regards,
    Anthony

    Edited by: Anthony Rayner on Feb 27, 2013 12:10 PM
  • 2. Re: Dynamic action (Fire On Page Load) in apex 4.2
    JiriN. Newbie
    Currently Being Moderated
    Hi Anthony,

    thanks for your help!

    You can do what ever you want with my application.

    -Jiri
  • 3. Re: Dynamic action (Fire On Page Load) in apex 4.2
    AnthonyRayner Pro
    Currently Being Moderated
    Thanks Jiri,

    Using your example, I have been able to reproduce this working in a 4.1.1 environment, and the same example not working in a 4.2.1 environment. I will update this thread with progress.

    Regards,
    Anthony.
  • 4. Re: Dynamic action (Fire On Page Load) in apex 4.2
    Tom Petrus Expert
    Currently Being Moderated
    Seems like a bug in dynamic_actions_core.js !
    In da.actions
        // Loop over the dynamic action's when elements. When this is called on page load, pSelector will be a jQuery selector,
        // hence why this is using 'each' to iterate. When this is called after an event handler is called, pSelector will
        // actually be a DOM element (which is also fine with 'each' although this will only iterate once).
        $( pSelector, apex.gPageContext$ ).each( function( i ) {
    
            da.doActions( pEvent, i, pBrowserEvent, pData, _getConditionResult( this ), this );
    
            // Reset cancelActions flag to false, ready for next dynamic action
            da.gCancelActions = false;
        }); // end loop over dynamic action's when elements
    This code executes correctly on load, and each item matching the selector is iterated over. However, the second parameter to da.doActions is pStartWithAction, and "i" is passed in as value. ("i" is the position value of the current object within the array of objects matching the selector eg 1,2,3,4,...)
    da.doActions = function( pEvent, pStartWithAction, pBrowserEvent, pData, pConditionResult, pTriggeringElement ) {
        var lActionCount = pEvent.actionList.length;
    
        // loop over actions
        for (var lActionIterator = pStartWithAction; lActionIterator < lActionCount; lActionIterator++ ) {
    The problem is in the for loop.
    This is a dynamic action with only 1 true action. This is the the value of lActionCount (amount of actions for the dynamic action).
    The first item (first row's SAL) will trigger correctly. This is item '0' in the array of objects (arrays are zero-index), and 0 will be passed on with pStartWithAction. Since 0 < 1 the action will fire.
    The second item is position 1, and pStartWithAction will be 1. Since 1 < 1 is false, nothing will be executed. Etcetera.

    If you'd have 2 true actions, the event would fire for both row 1 and 2.

    Everything works fine when the event is fired for each item in turn, for example changing the value in SAL, because then the array size will always ever be 1 long (and object 1's index is 0).
    I'm not sure why pStartWithAction has to set or used in this way. It seems to me it would be fine when it would always start out with 0.

    As a temporary workaround however, you could uncheck the fire-on-page-load, and create another dynamic action which fires on page load and executes javascript.
    $("td[headers='SAL'] input").change();
    Which would fire the change event and thus the dynamic action for each element in turn.
  • 5. Re: Dynamic action (Fire On Page Load) in apex 4.2
    JiriN. Newbie
    Currently Being Moderated
    Hello Tom,

    and thank you Tom for your post! I will try to implement your solution and update the thread then.

    -Jiri
  • 6. Re: Dynamic action (Fire On Page Load) in apex 4.2
    JiriN. Newbie
    Currently Being Moderated
    Unfortunately the proposed workaround does not work.

    -Jiri
  • 7. Re: Dynamic action (Fire On Page Load) in apex 4.2
    Tom Petrus Expert
    Currently Being Moderated
    Jiri,

    I changed page 2 in the application:
    - unchecked "Fire on page load" on dynamic action "DYN_SALARY"
    - created a dynamic action "workaround" which fires on page load, executes this javascript:
    $("td[headers='SAL'] input").change();
    You'll now get your popups/calculated fields.
  • 8. Re: Dynamic action (Fire On Page Load) in apex 4.2
    JiriN. Newbie
    Currently Being Moderated
    Hi Tom,

    I do not know what I did wrong, but when I recreated the workaround DA it works!

    Thanks for your help!

    Where to put the question related to different behavior of DAs in apex 4.1 and 4.2? I would like to know if this "new" behavior is a feature or a bug :).

    -Jiri
  • 9. Re: Dynamic action (Fire On Page Load) in apex 4.2
    AnthonyRayner Pro
    Currently Being Moderated
    Jiri,

    This is a regression from 4.1.1, and I filed bug #16409544 for this, which we want to fix for the next patch set. As Tom pointed out, it relates a change made to the way we iterate over the actions in our JavaScript code, which I am working on a fix for.

    Apologies you hit this, and thanks to Tom for suggesting that workaround. That was a good way around it.

    Regards,
    Anthony.
  • 10. Re: Dynamic action (Fire On Page Load) in apex 4.2
    JiriN. Newbie
    Currently Being Moderated
    Thank you guys, for a quick and useful answers!

    -Jiri
  • 11. Re: Dynamic action (Fire On Page Load) in apex 4.2
    AnthonyRayner Pro
    Currently Being Moderated
    Jiri,

    A quick update on this:
    - Bug #16409544 has now been fixed, ready for the next APEX 4.2.2 patch set.
    - When you apply the patch set, you don't need to do anything with the workaround implemented, it will still work fine. However I would suggest for you to switch back to your original implementation if possible, just for the cleanest implementation.
    - I spotted a minor optimisation you could make, that's possible in 4.2 and above. We added an 'Advanced > Static Container' attribute to the DA definition in 4.2, which gets displayed when the 'Event Scope' is 'Dynamic' as yours is. As I'm sure you know (because you did this in your example), setting this to 'Dynamic' means that the DA will continue to work after the content has been updated by PPR (sort, pagination, refresh). By default when 'Static Container' is null, internally this registers your event handling code at 'document' level in the DOM (for Desktop applications). You could set this to be something closer to your selected elements, but not part of any content that is updated by the PPR, such that the event doesn't have to bubble so far up the DOM before it is handled. So you could set it to say the region, for example '#myRegion', and then you would just need to set 'myRegion' as the 'Static ID' for the region itself. This would just make your DA's a tiny bit faster and would obviously still work after PPR.

    Tom: You were absolutely correct in your analysis, and the fix was indeed to set the pStartWithAction parameter to 0, when doActions is called in the context of iterating over the DA's 'When' elements. Thank you for your analysis and suggested workaround.

    Regards,
    Anthony.

    Edited by: Anthony Rayner on Mar 1, 2013 2:04 PM
  • 12. Re: Dynamic action (Fire On Page Load) in apex 4.2
    JiriN. Newbie
    Currently Being Moderated
    Thx, for update!

    -Jiri

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points