This discussion is archived
8 Replies Latest reply: Jul 24, 2013 3:35 AM by KevinFitz RSS

Referencng a Page item value from another Page

KevinFitz Newbie
Currently Being Moderated

Hi,

 

I'm relatively new to Apex and I have been using the Apex 4.2 Application guide to try and understand session state among other things. Could someone clarify if the following text taken from the official user guide is accurate:

 

'When a user submits a page, the Application Express engine automatically stores values typed into fields (items) in session state. For example, suppose you have an application containing two pages. The first page of the application contains a form in which a user can enter a phone number. You defined this form by creating an item named P2_PhoneNo. On the second page, you want to display the information the user enters in the form.

When the page is submitted, Oracle Application Express captures the value entered in the phone number field and stores the value for future use. The phone number entered by the user can then be retrieved from session state by referencing the item associated with the field on the page.'

 

What this indicates to me is that I should be able to reference/use a item value entered into a field ( P1_SUPPLIER_NR on Page 1 ) on another page's Report Region SQL i.e Page 2,  as follows: 'SELECT ... WHERE supplier_nr = :P1_SUPPLIER_NR'. What I have found though, is that the value of P1_SUPPLIER_NR is always NULL on navigating to Page 2. I know how to pass a value from Page 1 to use within Page 2 but the text seems to indicate that I don't have to explicitly pass the value between the 2 Pages.

 

I'm using Apex 4.2 with the EPG and I'm referring to Page items here rather than Application items. Any comment or links to relevant blogs etc will all be gratefully received,

 

regards,

 

Kevin.

  • 1. Re: Referencng a Page item value from another Page
    Joe Upshaw Journeyer
    Currently Being Moderated

    Well, you do not have to pass it. You can reference P1_SUPPLIER_NR from a query on Page 2.However, it is better to pass it explicitly. You can't be sure of the session visibility on a page that is no longer loaded. I have gotten inconsistent behavior trying to simply reference the value on the other page.


    To do this, you create a BRANCH from Page 1 to Page 2. In there you will see a popup selector that lets you set items on Page 2 from Page 1. For example, you will specify that P2_SUPPLIER_NR is to be populated by P1_SUPPLIER_NR.

     

    -Joe

  • 2. Re: Referencng a Page item value from another Page
    KevinFitz Newbie
    Currently Being Moderated

    Thanks Joe,

     

    That's what I have been doing i.e. passing the value explicitly. However, I wanted to be able to avoid creating hidden items on the target page if I could,

     

    Kevin.

  • 3. Re: Referencng a Page item value from another Page
    Tom Petrus Expert
    Currently Being Moderated

    It could just be a matter of session state. How are you going to page 2? Is it a redirect or does a page submit happen? If you are on the page and change P1_SUPPLIER_NR but perform a redirect, then the session state for this item will be NULL as it simply has not been submitted to the session state at any point. If you where to submit the page and use a branch to redirect to page 2 then P1_SUPPLIER_NR would be submitted to the session state.

  • 4. Re: Referencng a Page item value from another Page
    KevinFitz Newbie
    Currently Being Moderated

    Hi Tom,

     

    Are you describing a situation where the Form on Page 1 is initially empty? In my case, a button is pressed to navigate from Page 1 ( Supplier form ) to Page 2 (product Report) where the form fields are populated with values from an existing supplier. On using button action 'Redirect to Page 2 or  'Submit' ( and a branch to Page 2 ), respectively, it seems the value of P1_SUPPLIER_NR is 'retained' for use in Page 2. So, the bottom line seems to be that I can reference P1_SUPPLIER_NR on Page 2, which conflicts with what I thought I was seeing,

     

    Kevin.

  • 5. Re: Referencng a Page item value from another Page
    Tom Petrus Expert
    Currently Being Moderated

    You do not have to explicitly pass along values. As Joe also mentioned, it is perfectly possible to reference items on other pages. It's just that you should be aware of doing so and what consequence it may have. It could very well be a deliberate choice and work great. After all, an item is just a bind variable with a value within the session.

    The reason for the difference between redirect and submit+branch is simply session state, as I mentioned previously. Take a look at this thread aswell, which in essence is the same issue: Re: Passing an Item Value to another page via button set to redirect to page

    The redirect is simply client side. Say you put something in an item and then click the link, then you will navigate to that link's url, but the changed item's value will not be put in session state. This does happen with a submit+branch (which is a server-side redirect). The value in the session state is important when you want to reference the value of this item on another page, since you reference the session state then either by using the bind variable or substitution syntax.

  • 6. Re: Referencng a Page item value from another Page
    Joe Upshaw Journeyer
    Currently Being Moderated

    Kevin,

     

    So, I think, at this point, your question has been answered, albeit perhaps not the answer you were hoping for.

     

    In order for the value from Page 1 to be available to Page 2, the requirement is that it has to be set in the session. As a self-described newbie, the most straightforward way to do this is to branch from page 1 to page 2 following a submit operation. There are other means, via JavaScript, to set it in the session but, if your goal is less work, then this probably isn't he answer for you.

     

    For what it's worth, branching and setting corresponding items on the resulting page is the more standard way of doing things.

     

    -Joe

  • 7. Re: Referencng a Page item value from another Page
    KevinFitz Newbie
    Currently Being Moderated

    Thanks for all the contributions

  • 8. Re: Referencng a Page item value from another Page
    KevinFitz Newbie
    Currently Being Moderated

    Thanks for the contributions - I'm happy to go along with doing things the standard way!

Legend

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