user1457141
user1457141

Reputation: 1

JSF How to save the current state before navigating to other page on error cases

I have a multi page application form (jsf 1.2) with next and prev buttons for navigation. These pages should adhere the below requirements.

1) User should be allowed to move back and forth on those pages even with partially filled pages. The mandatory field validation should not stop him moving between screens.

2) Also the data he entered on a page should be restored back on his return to that page.

On an error case, jsf will postback to the same view always, but I solved this by using navigation handler inside a phase listeners after process validation callback.

But how could I save the current state before rendering the new page. I tried calling saveState on UIView before render phase, but that didn't work. How can I solve this?

What is the best way to address these requirements. I would very much appreciate an answer for this. Thanks.

Constraints : I have to address this in jsf 1.2, can't go for jsf 2.0 conversational state or third party solutions like tomahawk savestate :(

Upvotes: 0

Views: 1148

Answers (1)

Luiggi Mendoza
Luiggi Mendoza

Reputation: 85779

If you just have to stick with JSF 1.2, then you can't. You have to save all the data you handle in the bean into the session, and recover everything in the bean constructor. If you can use a third party library, I'll recommend you RichFaces 3.3.3, it has a KeepAlive annotation that you can put on your request managed bean and turn it into a ViewBean (by saving the whole request bean in session and loading it if you're in the same view).

Example of KeepAlive annotation (as simple as it looks):

@KeepAlive
public class MyViewWannaBeBean {
    private String name;
    public MyViewWannaBeBean() {
    }
    //getters and setters...
}

Define the bean in the faces-config.xml like a request managed bean

<managed-bean>
    <managed-bean-name>myViewWannaBe</managed-bean-name>
    <managed-bean-class>mypackage.MyViewWannaBeBean</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

Upvotes: 0

Related Questions