I believe the View Scoped data will be lost when you navigate to the next page in the wizard)
That's correct. The view scope lives as long as you're interacting with the same view and get trashed whenever a new view get created. You're looking for the "conversation scope". This isn't available by any of the JSF managed bean scopes. This is however available by CDI @ConversationScoped
. So if your environment happen to support CDI, you could make use of it:
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;
@Named
@ConversationScoped
public class Wizard implements Serializable {
@Inject
private Conversation conversation;
@PostConstruct
public void init() {
conversation.begin();
}
public void submitFirstStep() {
// ...
}
// ...
public String submitLastStep() {
// ...
conversation.end();
return "someOtherPage?faces-redirect=true";
}
// ...
}
The conversation is managed by the automatically inserted cid
request parameter.
If you'd like to stick to the JSF view scope, then your best bet is to create a single page wherein you render the multiple steps conditionally:
<h:panelGroup rendered="#{wizard.step == 1}">
<ui:include src="/WEB-INF/wizard/step1.xhtml" />
</h:panelGroup>
<h:panelGroup rendered="#{wizard.step == 2}">
<ui:include src="/WEB-INF/wizard/step2.xhtml" />
</h:panelGroup>
<h:panelGroup rendered="#{wizard.step == 3}">
<ui:include src="/WEB-INF/wizard/step3.xhtml" />
</h:panelGroup>
Or, you could use a 3rd party component library like PrimeFaces which has a <p:wizard>
component for exactly this purpose.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…