Forum Stats

  • 3,874,151 Users
  • 2,266,674 Discussions
  • 7,911,744 Comments

Discussions

Refreshing page item after session state changed

dantel35
dantel35 Member Posts: 6 Green Ribbon
edited Dec 19, 2017 3:48AM in APEX Discussions

Dear community members,

I have a question.

So one can set the session state of a page item using apex_util:

APEX_UTIL.set_session_state(

p_name => v_page_item

, p_value => v_some_value);

This does what it should, it actually sets the session state and this is fine (I can verify it works using the 'Session' button).

I have a Dynamic Action which does this.

But what if I want this to be visible on the page? How can I update or refresh (and redraw) the DOM value of an item with the corresponding session state? A dynamic action with a 'refresh' does not work for me. I tried using it on a region and also on individual items, it simply does not update the visible value.

The use case is I have a key->value list, where 'key' holds a page item name (without the 'PXX_'-prefix, which I add dynamically depending on the page I am on) and 'value' has the corresponding value. I want to loop through the list and update the items that are present in it (and let other items unchanged, they even might not exist on the page). This happens after a user hits a button.

Any help is appreciated.

Thanks!

Tagged:

Answers

  • dantel35
    dantel35 Member Posts: 6 Green Ribbon
    edited Dec 15, 2017 4:28AM

    Noone? Shouldn't this be something easy? It can't be true that all I can do here is to reload the whole page or hardcode every single item with 'set value' DAs.

  • Neil Clare
    Neil Clare Member Posts: 258 Silver Badge
    edited Dec 15, 2017 10:38AM

    In the dynamic action, set Page Items To Return to the item that you change.

    Given the nature of your page, this might need to include all the items on your page.

    Depending on what else your page is doing, you might be better submitting the page.

  • dantel35
    dantel35 Member Posts: 6 Green Ribbon
    edited Dec 19, 2017 3:48AM

    @Neil Clare

    Thank you very much for your suggestion. It works, but unfortunately also only by hardcoding every page item in the 'Items to return' field. Still a good way for static pages I did not know about.

    I solved the problem 'outside' of apex using javascript+jquery.

    In case any other poor soul faces a similar problem, here is what I did:

    1. I created a procedure which produces the dynamic content for a page and returns it in a json string. The top level keys of the json string match the page item names (excluding the PXX_ prefix) and the values are of course the values for the items.

    Very simplified - something like: 

    v_result_as_json := '{"given_name":"some name", "job_title":"some job title"}'; --would fill the page items P2_GIVEN_NAME and P2_JOB_TITLE

    HTP.p (v_result_as_json);

    2. In APEX I created an application process which called this procedure. In my case I called it 'load_blueprint' and it fetches two parameters.

    It looks something like:

    declare

    v_blueprint_ids VARCHAR2(4000);

    v_consider VARCHAR2(4000);

    begin

    v_blueprint_ids := APEX_APPLICATION.g_x01;

    v_consider := APEX_APPLICATION.g_x02;

    gui_creation.create_account_creation_gui(v_blueprint_ids,v_consider);

    end;

    3. On the 'load' button which shall refresh the parts of the page I need to be refreshed, I added a dynamic action which executes javascript. This script calls the application process with the needed parameters and handles the refreshing of the page items in the provided callback function

    apex.server.process ("load_blueprint", {x01 : $v(pagePrefix + "BLUEPRINTS"), x02: $v(pagePrefix + "CONSIDER")},{

    dataType: "JSON", success: function(pData){

         var jsonObject = pData;

        //iterate over the keys

        var keys = Object.keys(jsonObject);

        for(var i=0;i<keys.length;i++){

            var key = keys[i];

            var value = jsonObject[key];

            var domElementSelector = '#' + pagePrefix + key.toUpperCase();

            $(domElementSelector).each(

            function () {

                var foundID = $(this).attr('id');

                $s(foundID, value);

                $(this).trigger('change');

         }

              ) 

        }

    }});

    Does not feel like the most elegant solution, but it works.

    I wish APEX would provide something out of the box. Refreshing parts of a page should be a very common requirement. So it should be something easy like a dynamic action with a 'synchronize DOM with session state' option or something similar.

    Joe Barry-Oracle
This discussion has been closed.