tags:

views:

357

answers:

2

I have two forms. On Form 1, I have this screen layout:

<detail section>
hyperlink 1
hyperlink 2
etc
<detail section>

When I click a link on Form 1, for example, hyperlink 1, this takes me to Form 2. From Form 2, I have a link called "Go Back" to go back to Form 1. Usually, I would just use

history.back(); or
history.back(-1);

to navigate back. However, doing this means JSF resets all my form's values when I get back to Form 1 from Form 2. I want to return to the previous Form 1's view i.e. showing the detail section with data as opposed to a blank detail section.

I have also tried this - for each hyperlink in the detail section on Form 1, I have this code:

<h:outputLink value="two.jsf">

And in Form 2, I have this code:

<h:outputLink value="two.jsf">

The above parameters will be passed back to Form 1 for processing. While this is working, I'm not sure if this is the best way to do it with JSF 1.2.

Any expert here know of a better (more robust) method of creating a "Go Back" button? Example demo codes would be greatly appreciated as I have been stuck on this one for about a week now...

A: 

You may map your managed bean with the session scope.

Actually, this issue with the "back button" is common place in JSF, and is also one of the framework main complaints.

As a solution, you may try something like an Ajax timer which will update your managed bean from time to time, avoiding this problem with the back button.

Kico Lobo
Thanks, Kico Lobo. The only thing I don't like about the session scope approach is when I move to another area of the website and come back, I can still see the results of Form 1 due to it's being in session scope. I like the Ajax suggestion though. Is this the only way to tackle this problem? Someone suggest this<navigation-rule> <display-name>back</display-name> <from-view-id>/one.jsp</from-view-id> <navigation-case> <from-outcome>to</from-outcome> <to-view-id>/two.jsp</to-view-id> <redirect /> </navigation-case></navigation-rule>But I don't know how to use it.
icepax
You may map these other navivations rules to your application, but it still does not solves the main problem, which is the use of the back button on the browser.
Kico Lobo
I see. I tried the browser's Back button and it asks me to resubmit (clicking the browser's back button actually takes me back to Form 1 showing previous submitted values - which is what I want). I gather then that JSF uses HTTP POSTs instead of GETs. How awful! Hopefully, this will be fixed in JSF 2.0 and later.
icepax
Also, I have written the codes below:public String goBack() throws IOException { FacesContext context = FacesContext.getCurrentInstance(); ExternalContext ec = context.getExternalContext(); Application app = context.getApplication(); ViewHandler viewHandler = app.getViewHandler(); String url = viewHandler.getActionURL(context, "/one.jsp"); try { ec.redirect(url); } catch (IOException e) { throw new FacesException(e); } return null;}Putting this codes in the action method of a h:commandLink does not work...
icepax
A: 

Solve it! But I'm still coming to grip that JSF 1.x queries are all using HTTP POST instead of POST-GET as required. This is probably a sticking point with the implementation. Hopefully, JSF 2.x will address this - it would make doing JSF a whole lot easier and more intuitive. I'm sure a few programmers have teared their hair out because of this -:)

icepax