0

I'm in the following situation:

  1. JSF (MyFaces 2.1.7 and RichFaces 3.3.3)
  2. A session Scoped Bean TEST_PAGE
  3. Users who will use BACK button to no end
  4. State Saving on Server

Scenario:

  • User click a link to navigate to page with Session Scoped bean (TEST_PAGE)
  • User clicks another link
  • User presses back button of brwoser which puts them back in TEST_PAGE
  • User Tries to Search in this page

On search the backing bean throws exceptions since there are many null values. Reason being is that when they pressed "Search", the page is in RESTORE_VIEW phase.

I tried disabling caching on the page, to force user to refresh the page on back button, but backlash caused by many users complaining "why can't I use back button, I could do it before!" and resulted in Help Desk Tickets since they think the application is crashing on "Confirm Form Resubmission" page chrome/IE/Firefox show, hence managers want me to look for alternatives.

My questions:

It is possible to detect the current Phase_ID of RESTORE_VIEW and not do any processing in this phase to avoid the exceptions, but that alone and just retuning gives user a partial page view. Is it possible to put the page in RENDER_RESPONSE in this scenario and do the processing then? This should refresh the page.

Question Part 2

Since the recommendation (or common/good) practive is to disable cache on dynamic pages i have done so and will have to re-educate the stubborn users.

However i have the following issue.

When pressing Back button on a page with disabled cache, the browser shows the "Confirm Form Resubmission" (chrome) where users either can press Refresh / F5 or Enter key.

If Refresh/ F5 is the action, everything is ok where i detect RESTORE_VIEW phase and avoid any processing in that PHASE and let the processing be done in RENDER_RESPONSE phase. However if Enter is pressed, The PhaseID is in RENDER_RESPONSE(6) but values of few drop-down controls is null which causes the page to fail. So i put in checks to detect such conditions and show a FaceMessage to tell the user to Refresh the page.

Question is, Can i force the page to Refresh instead of forcing the user to do it? The Navigation case for this page is in format:

     <navigation-rule>
      <navigation-case>
       <from-outcome>/app/ord/r1</from-outcome>
       <to-view-id>/jsp/ordersHistory.jsp</to-view-id>
      </navigation-case>
     </navigation-rule>

I've seen code snippets online where faces-redirect=true is used to force reload a page but i couldn't get that to work! Any suggestions?

Community
  • 1
  • 1
ke3pup
  • 1,835
  • 4
  • 36
  • 66

1 Answers1

5

Disabling the browser cache on dynamic pages is the way to go.

As to the new problems caused after this, this is likely caused by poor webapp design. Redesign your webapp to use GET instead of POST for plain vanilla page-to-page navigation (i.e. use just <h:link> or <h:outputLink> instead of <h:commandLink>). Implement the POST-Redirect-GET pattern for POST requests which needs to send the response to a different page, or change them to return to the same page and conditionally show the results, if possible by ajax. Check if some forms can't better be GET forms (for example, search forms like Google). Rethink if that bean really needs to be a session scoped one, you usually use the session scope for logged-in user and its preferences only, not for request or view scoped data.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • thanks for your comments. I am going with Disabling Cache for Dynamic pages as otherwise the result are unpredictable. I Updated the question and added a related part 2. Can you please comment? – ke3pup Jun 10 '12 at 12:14
  • 1
    See the answer in "How to avoid re-execution of last form submit action when the page is refreshed?" link. Add a ``. – BalusC Jun 10 '12 at 12:55