This discussion is archived
1 2 Previous Next 17 Replies Latest reply: Jul 24, 2013 5:40 AM by Howard (... in Training) RSS

Button Display Symptom

Howard (... in Training) Pro
Currently Being Moderated

I have 3 regions on a page and the 2nd region has 4 buttons and an SQL query report which displays data from EMP.

 

There are two page item:

  HIDE_SHOW -- which is Show to show the data and Hide to hide the data.

  P1_SAL_LIMIT -- which limits the employees shown by salary: 0 (default), 1500 or 2000

The buttons are:

  Show -- which, when pressed, shows the report (Not the entire region just the data lines of the report.)

              (The Show button displays when  :HIDE_SHOW = 'Hide'. Note the data is hidden when this button displays.)

  Hide -- which, when pressed, hides the report

              (The Hide button displays when  :HIDE_SHOW = 'Show' and the data is being displayed.)

  SAL > 1500 -- Which show only employees with sal > 1500

  SAL > 2000 -- which show only employees with sal > 2000

The Query is

  select ename,job,sal

    from emp

   where :HIDE_SHOW = 'Show' and SAL > :P1_SAL_LIMIT

What works:

  Show, Hide and Sal > 1500 work fine together.  Note: the Sal > 1500 button sets :HIDE_SHOW to 'Show' so one can see the data.

 

But I need to do a computation when a Sal button is pressed, so here is what I tried.  The SAL > 2000 button is set up with Dynamic Actions (PL/SQL block and page refresh).  Note: I need to do a branch to (the same) page or a refresh rather than a page submit because of activity which may be pending in the other regions on the page. 


What I need /expected when Sal > 2000 is pressed: Tthe Hide button will display because :HIDE_SHOW is set to 'Show' and data is being displayed.

Problem when Sal > 2000 is pressed:  Even though I set :HIDE_SHOW to 'Show' in the computation, pressing Sal > 2000 has no effect on the Show button.

 

It's a Session State problem, right?  But I'm not sure how to solve it without a Submit.   I added a Set Value to the DAs but that did not solve the problem.

 

How do I get the "Show" button to react to the change in the value of :HIDE_SHOW?

 

You can see it set up here:

WS:  APEX_EXAMPLES_01

demo / demo

Application 16604 (Button Control), p. 1

 

Thanks,

Howard

  • 1. Re: Button Display Symptom
    jrimblas Expert
    Currently Being Moderated

    First, I may be very confused by what your trying to accomplish, so just correct me if I get it wrong.

    Looks to me like you need control your hide and show buttons with DA and NOT with Conditions.  That way you can hide and show the buttons as the result of a DA.

    Because, if a button is hidden with a condition you cannot bring it back until you re-load the page.

     

    So, I'll go ahead and remove the conditions from your buttons.  Add a new DA that handles the Hide/Show buttons on page load.

    And we'll see if that gets you 90% there.

     

    Thanks

    -Jorge

  • 2. Re: Button Display Symptom
    Howard (... in Training) Pro
    Currently Being Moderated

    Jorge

     

    Thank you.  I will try this when I get back to work.  (I'll today.)   As long as this doesn't cause the other regions to submit, it should work for me.

     

    Howard

  • 3. Re: Button Display Symptom
    Howard (... in Training) Pro
    Currently Being Moderated

    @Jorge,

     

    You are correct that I assume

    ... [I] ... need [to] control ... hide and show buttons with DA and NOT with Conditions.

     

    Let me restate the problem.  [Using Oracle 11.2, Apex 4.1.]  I have three regions that I am trying to refresh independently.  The reason for this is that I want to hide/show the data rows in the regions independently.  Note: I want just the data to be hidden because I want to show the region header, region buttons, etc. all the time.  So, I need to prevent the usual Submit / fresh of the entire page.   To make the example on apex.oracle.com closer to what I'm trying to do, I've placed similar functionality to Region 2 into Region 1.  I think I have everything right.  I've set the computations Conditional to "Never" for now.   Give it a try.

     

    I don't get what I'm looking for.  Activity in Region 1 often causes P1_SAL_LIMIT2 to be reset to 0 in Region 2.  Activity in Region 2 often causes P1_SAL_LIMIT1 to be reset to 0 in Region 1.  There are ways to code around this but ...

     

    If I step back and examine the problem, I can describe it is as:

    Problem:  Region 1 and Region 2 are not operating independently. 

     

    The DAs seems to work as I want -  they refresh independent.   But the SAL > 1500 buttons affect both regions.  A Hide in either region affects both regions.

     

    How can I make activity in region 1 and 2 operate independently?

     

    Thanks,

    Howard

  • 4. Re: Button Display Symptom
    jrimblas Expert
    Currently Being Moderated

    The problem was that the HIDE_SHOWn items don't have their values saved to Session State, so when you re-direct to p1 they "forget" their previous values.

    You either set those values in session state, or carry them with when you redirect.  I've chosen to carry them with on the Redirect.  Take a look.

    All I did was change all 4 hide/show buttons.

     

    You'll have exactly the same situation with the SAL_LIMIT items.  I didn't change those, so you'll see the regions "forget" what they were set to.

     

    Did I get it?

     

    Thanks

    -Jorge

  • 5. Re: Button Display Symptom
    Howard (... in Training) Pro
    Currently Being Moderated

    @Jorge,

     

    THANKS!   I added that to Sal > 1500.   Great ... so far.

     

    Question though:  Say I refresh Region 1.  What is happening to cause it to "forget" the value(s) in the other region?  My idea was to leave Region 2 alone so ... (drum roll) NOTHING CHANGES there.

     

    Because I intend to add more functionality, I don't want to have to add this "value passing" to every button.  How do I get these values into session state for any (all) of the three different types of buttons?

    1) Show/Hide

    2) Sal > 1500

    3) Sal > 2000, Sal > 3000

    I assume a different method will be needed in each case.   I should know this but I guess the only way I know is to save values into Session State is to cause a Submit.  This whole effort has been to avoid that!

     

    Howard

  • 6. Re: Button Display Symptom
    jrimblas Expert
    Currently Being Moderated

    The technique is identical for all the buttons, just remove the parameters and set the values in session state via a Set Value in the DA.

     

    This can all be done with DA. I just don't have the time to fix it all at the moment.  Do the exact same thing for the Show/Hide buttons as you did for the "Big_Computation_Here".

    If you can't get it working let me know and I'll work on it.

     

    Thanks

    -Jorge

  • 7. Re: Button Display Symptom
    fac586 Guru
    Currently Being Moderated

    Howard(...inTraining) wrote:

     

    I assume a different method will be needed in each case.   I should know this but I guess the only way I know is to save values into Session State is to cause a Submit.  This whole effort has been to avoid that!

    For regions that are refreshed via dynamic actions, use the Page Items to Submit property in the region's Source properties. Alas, this seems to be missing from the documentation. The on-line help says:

    Enter a comma separated list of page items on the current page to be set into session state when the region gets refreshed with a partial page refresh. The region can be refreshed with partial page refresh either during pagination (if 'Enable Partial Page Refresh' is set to Yes) or with the Dynamic Action, Refresh.

     

     

    These page items can then be used in the "Region Source" SQL statement to restrict the query result.

    You may need to combine a number of True Actions in Click DAs on the buttons, with actions that set the page values in the browser, with a final Refresh action that will cause the items specified for the region to be submitted and the region to be refreshed.

  • 8. Re: Button Display Symptom
    Howard (... in Training) Pro
    Currently Being Moderated

    @Jorge,

     

    I started a few changes but decided it would only be playing "whack a mole" at this point.  I don't know what needs to be removed from what I/we currently have so that this new approach works.  And, in each region, what needs to be placed in Session?  And what doesn't need to be placed in Session?  I don't have a "fixed point" from which to start this.  So, I'll wait until you have time.

     

    Still:  When one region refreshes, "What is happening to cause it to "forget" the value(s) in the other region?"  Okay, they are not in Session -- that's secondary.  Firstly, I'm not refreshing that region (am I?), so why is it doing anything in that other region that causes it to need values in Session for that region?  I need a model of what's happening in order to understand this.

     

    Thanks,

    Howard

  • 9. Re: Button Display Symptom
    jrimblas Expert
    Currently Being Moderated

    Howard(...inTraining) wrote:

     

     

    Still:  When one region refreshes, "What is happening to cause it to "forget" the value(s) in the other region?"  Okay, they are not in Session -- that's secondary.  Firstly, I'm not refreshing that region (am I?), so why is it doing anything in that other region that causes it to need values in Session for that region?  I need a model of what's happening in order to understand this.

     

    Thanks,

    Howard

    You're redirecting back to the page, that refreshes the page.  If the items have values in session state, they will re-render with those values.  If their values where not set in session state you will lose those values when you redirect.

     

    Ha! Scratch that, what I said was correct, but the real reason the values were not being remembered by the page is that you created them with "Always, replacing any existing value in session state" !!! You always want to use that option for DB fields, almost NEVER for items not tied to an item.  You're killing me here!  Ha!

    I also changed the display items to "Save Session State" otherwise they can't remember the setting between reloads.

     

    One more thing... you can't name the buttons the same and then try to tie different DA to them, unless they really are the same.  You had SAL2 as the button name on both regions!

     

    Thanks

    -Jorge

     

    Message was edited by: jrimblas

  • 10. Re: Button Display Symptom
    jrimblas Expert
    Currently Being Moderated

    Ok, done.  Take a look at p3.

     

    Howard, this didn't need to take this long.  I should have started your example from scratch. Most of the time was spent cleaning up the names and organizing things.

    Check out what I did for the Salary button.  I added a data-sal attribute that holds their filter value. This allows me to have the same DA for both buttons within a region and get the SAL_LIMIT right from within the DA.

     

    The page doesn't need to redirect or refresh, it's all done with the DA.

     

    Let me know if you have questions. Hope this is all useful.

    Thanks

    -Jorge

  • 11. Re: Button Display Symptom
    Howard (... in Training) Pro
    Currently Being Moderated

    @Jorge,

     

    Thanks.  I took a look this morning.  The Hide / Show buttons do not seem to be working.  I don't think the two regions are independent yet.  Hide in Region 1 causes both regions to be hidden.

     

    Maybe you didn't intend to fix everything and I need to do more work on it.  I'll make a copy on page 4 so I don't tweak that you have on page 3.  But I have some other things I need to do before I work more on this.

     

    Thanks loads.

     

    Intro:  Even this simple one-page example thems like it needs a complex solution.

    Question:  Have you used APEX for a while -- long enough to have maintained programs from say 18 months or earlier?  Do you find these "fragile"?  By that I mean: Hard to maintain because you can't rememeber how you wired up everything in the first place?   I fear if anyone tries to maintain what I have written -- even assuming it were written correctly, it will collapse if they change out even one thing.  

     

    Howard

  • 12. Re: Button Display Symptom
    jrimblas Expert
    Currently Being Moderated

    Yes, you're right, the Show buttons were not quite working, sorry, I was concentrating on the filters.  I fixed the hide show for the first region.  Region 2 is mostly there and you can replicate the functionality for that one. However, the Sal filter buttons for region 2 do work and you can see how it all works independently.  Please concentrate on the techniques.


    The basic steps for the filters are:

    1. Set the filter limit

    2. Set the Hide_Show variable

    3. Hide the Show button

    4. Show the Hide button

    5. Refresh the report.


    Notice the computations. They are needed to initialize the values.


    I also changed things so they don't trigger off the change of value of an item.  That just seems obscure to me when the user cannot directly change the item.  It seems better to trigger off button clicks. That's what the "Report 1 SHOW button" and "Report 1 HIDE button" DA are for.  If you look at them I think they are really easy to follow (Show button, Hide the other button, Set the Hide_Show filter, Refresh report)


    When you break it down into individual steps and give meaningful names to your elements (items, regions, da, etc..) I think it all becomes a lot more maintainable.

    I have definitely seen unmaintainable applications since I started with APEX way back on HTMLDB 1.6.  That said, they are mostly easy to maintain when things are well thought out and steps are broken down into easy understandable actions.


    Good luck!

    Thanks

    -Jorge



     

  • 13. Re: Button Display Symptom
    Howard (... in Training) Pro
    Currently Being Moderated

    Arrrgggghhhhh!   I'm getting there.

    I copied your p. 3 to p. 4.  And modified Region 2 to match what was in Region 1.

    1.  Why doesn't the code for the DAs for the Sal buttons show with the buttons in the tree structure as the DAs do for Hide/Show?

    2.  For the computations, why are they conditioned on NOT NULL.  I would think you want to change a NULL value. 
    3.  When p. 3 (and 4) are first displayed, both Show and Hide are visible in Region 2.  I can't see a difference in the code.

    4.  Why is the Sal Limit1 label bold and Sal Limit2 not bold.

    5.  The Reset All values buttons tend to get protection errors.

    6.  Is there a simpler way to do this?  This seems like a lot of non-trivial code.

     

    Thanks,

    Howard

  • 14. Re: Button Display Symptom
    jrimblas Expert
    Currently Being Moderated

    1.  Why doesn't the code for the DAs for the Sal buttons show with the buttons in the tree structure as the DAs do for Hide/Show?

    Because those are now based of a jQuery selector finding the class .sal1Button

    You only get that link when you reference and element.

     

    2.  For the computations, why are they conditioned on NOT NULL.  I would think you want to change a NULL value. 

    Ooops, you're absolutely correct.  You know... those, set correctly, were important for the example that would redirect the page.

    3.  When p. 3 (and 4) are first displayed, both Show and Hide are visible in Region 2.  I can't see a difference in the code.

    The DA "Set Initial Hide1/Show1 Button State" hides the HIDE button based on the value of P3_HIDE_SHOW1

    4.  Why is the Sal Limit1 label bold and Sal Limit2 not bold.

    That was all you   It's because of the Label template.  Sal Limit 2 has no template.

    5.  The Reset All values buttons tend to get protection errors.

    6.  Is there a simpler way to do this?  This seems like a lot of non-trivial code.

     

    5. I think that's because it submits the page and the Sal Limits are saving session state and are set to protected.

     

    6.  Maybe... but making things simple requires thoughtful planning.  This is a fairly complicated set of rules you specified here and they are all happening without refreshing the page.  So all those DA need to run on the client browser.

     

    Thanks

    -Jorge

1 2 Previous Next

Legend

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