I have a web application which basically process entries of the user when the commandButton is hit, then receives a response/result message of the transaction and should be displayed in another JSF page.
Here’s a sample what I want to do: I’m using JSF2 and primefaces
registration.xhtml – starting point for the transaction
RegistrationBean – backing bean used by registration.xhtml
– has the “create” (also processes the data entered and supposedly sets up the ResultBean) method invoked via the commanButton on registration.xhtml then return string for navigation (to result.xhtml)
result.xhtml – result UI of the transaction
ResultBean – holds values needed by the result.xhtml
I’ve been searching for samples over the internet and seem can’t find one. Is there a way to accomplish this? And if none, maybe a workaround? I’m a beginner using this. Any help would be greatly appreciated. Thanks in advance!
See below for sample code.
registration.xhtml:
<h:form style="position: absolute" id="basicPartyRegistration">
<h:panelGroup>
<h:commandButton id="createButton1" action="#{partyRegistration.create}" value="Create">
</h:commandButton>
<h:button outcome="welcome" value="Main Page" id="mainPageButton" />
</h:panelGroup>
<br />
<h:panelGroup>
<p:panelGrid columns="2">
<h:outputText value="Receiver:" />
<h:inputText id="receiver"
value="#{partyRegistration.partyRegistrationInfo.receiverGLN}"
size="15" maxlength="13" />
<h:outputText value="TransmittingData:" />
<h:inputText id="transmittingDataPool"
value="#{partyRegistration.partyRegistrationInfo.transmittingDataPool}"
size="15" maxlength="13" />
<h:outputText value="PartyData:" />
<h:inputText id="partyData"
value="#{partyRegistration.partyRegistrationInfo.partyDataPool}"
size="15" maxlength="13" />
</p:panelGrid>
.....
.....
RegistrationBean:
@ManagedBean (name = "partyRegistration")
@viewScoped //Changed to @ConversationScoped
public class RegistrationBean implements Serializable{
private String receiver
private String transmittingData;
private String partyDataPool;
@ManagedProperty (value = "resultBean")
private Result result;
// more variables
//public getters and setters
public String create(){
// do some processing
// some magic way to set RESULT bean to be used in the next page
return "result";
}
}
result.xhtml
<h:form style="position: absolute" id="partyRegistrationResponse">
<h:panelGroup>
<h:button outcome="welcome" value="Main Page" id="mainPageButton" />
</h:panelGroup>
<br/>
<h:panelGroup>
<p:panelGrid columns="4">
<h:outputText value="Last Date Changed: " />
<p:inputText id="lastDateChg" value="#{partyResponse.lastChangedDateItem}"
title="Last Date Changed" size="15" >
</p:inputText>
</p:panelGrid>
<h4>Response Identification</h4>
.....
.....
ResultBean:
@ManagedBean (name = "partyResponse")
@ViewScoped //changed to @ConversationScoped
public Class ResultBean implements Serializable{
private Date lastChangedDateItem;
//more variables
//getters and setters
}
faces-config.xml
<navigation-rule>
<navigation-case>
<from-outcome>result</from-outcome>
<to-view-id>/result.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
Try to create the ResultBean in your RegistrationBean’s create() method and put it in a qualified scope the programmatic way. ViewScope may not be the right choice, since you are leaving the registration view.
To survive a redirect, put it into flash scope.
You should have a look at conversation scope, too, which is useful to store beans for a sequence of pages, that belong to one use case.