7 Replies Latest reply: Aug 10, 2011 10:23 PM by 868368 RSS

    Assigning Value to APEX PAGE ITEM

    868368
      Hi all,

      In Javascript I have assigned value to a page item P2_NAMES
      $("#P2_NAMES").val(Names);               //(Names is a variable used int he script)                   
      console.log($("#P2_NAMES").val());      //(to print in console of firebug)
                          
      The problem is that the console displays the correct output but to my surprise the page passed a blank value to the next page when posted.

      When I click "Session" Button(Apex Bar in the bottom of the screen) after I run the page - I do not see the values reflected in the table of apex page items. Meaning the value assignment hasn't taken place but the console shows the output.

      I also made sure that the "Source used" for the apex page item be "Always, replacing any existing value in session state".

      Masters, Help !!!
        • 1. Re: Assigning Value to APEX PAGE ITEM
          Kiran Pawar
          Hi Shiva,

          Try this:
          $x_Value("#P2_NAMES",Names);
          It is one of the functions in JavaScript APIs for apex which is used for setting value of a DOM node:

          http://download.oracle.com/docs/cd/E17556_01/doc/apirefs.40/e15519/javascript_api.htm#CHDDEFJJ

          Hope it helps!
          Regards,
          Kiran
          • 2. Re: Assigning Value to APEX PAGE ITEM
            868368
            Thank You so much. But Still Doesn't work :(

            You're right. I can use $x.Value("#name",value); .

            The Jquery $().val(); and $x.Value(,); both seem to work as I can see from the console log output - But I cant figure out why the value of the page item is not reflected in list of page item values in the session(can see on clicking session button on apex bar) . If I use the page item to pass value to next page, it sends "" (blank) only.

            I tried dynamic actions like "Set Value" before page submit. still doesn't work.
            • 3. Re: Assigning Value to APEX PAGE ITEM
              Kiran Pawar
              Hi Shiva,

              >
              You're right. I can use $x.Value("#name",value);
              >
              Please check the syntax of the function in the reference link given in above post.
              Also you can use:
              $x('P2_NAMES').value=Names;
              The following threads indicate that you to have set item value using AJAX to reflect it in session state:

              {thread:id=959416}

              {thread:id=1070131}

              Also the following function can help:

              http://download.oracle.com/docs/cd/E17556_01/doc/apirefs.40/e15519/javascript_api.htm#CHDFBJGD

              Hope it helps!
              Regards,
              Kiran
              • 4. Re: Assigning Value to APEX PAGE ITEM
                868368
                Hey Kiran

                Thanks for following up. Really appreciate it.

                Jquery is not the problem. Something to do with session state. Btw, P2_NAME is a hidden page item(I don't think that matters).
                I checked firebug console and the firebug HTML. It works just fine.

                1. I can see in the HTML/Source:
                <input id="P2_NAME" type="hidden" value="shiva" name="p_t01"
                2. But in the "Session" - It's blank!
                     
                Page: 110
                Item: 2
                Name: P2_NAME
                Display: Hidden
                Item Value:
                Status:
                Encrypted: No

                Source Value used : Always, replacing any existing value in session state
                Source Type used : Static Assignment (value equals Source Attribute)

                3. When I refer to this item as &P2_NAME. in my url - It sends blank too.
                • 5. Re: Assigning Value to APEX PAGE ITEM
                  Zulqarnain
                  Hi Shiva

                  Page Items are sent to session state on submit or if done through Ajax call only. As Kiran pointed out to some documents/threads, you need to use JavaScript or Dynamic Action to send the Item values to the session state. Only after that you will be able to see it in Session.

                  ----
                  Zulqarnain
                  MaxApex Hosting
                  http://www.maxapex.com
                  • 6. Re: Assigning Value to APEX PAGE ITEM
                    Kiran Pawar
                    Hi Shiva,

                    There is also a function in APEX_UTIL package that will help to set session state of
                    a Page Item or Application Item :

                    http://download.oracle.com/docs/cd/E17556_01/doc/apirefs.40/e15519/apex_util.htm#CHDBGEEC

                    But you have to write a PL/SQL process to set the session state:
                    BEGIN
                        APEX_UTIL.SET_SESSION_STATE('my_item','myvalue');
                    END;
                    If through JavaScript you can achieve it through: AJAX.

                    If without submitting the page then: Advanced Dynamic Action of type Execute PL/SQL Code executing above code block

                    Hope it helps!
                    Regards,
                    Kiran
                    • 7. Re: Assigning Value to APEX PAGE ITEM
                      868368
                      Hi All,

                      Hope this is useful for people with similar problem :

                      It was a very simple solution which missed my attention - To set values to application items on a
                      page (Before going to next page or refreshing same page) (without ajax),
                      we need to use a SUBMIT request (either using apex branch or using apex f?p url syntax) (you may assert any name for the request).

                      Also when passing values to next page and using that page items set value in the javascript make sure "Save session state" is unchecked if using a apex branch.

                      Thanks Kiran for your support. I learnt there are many ways to insert values to application items from your feedback.