我有一个 Web 应用程序,它基本上在按下 commandButton 时处理用户的条目,然后接收事务的响应/结果消息,并且应该显示在另一个 JSF 页面中。
这是我想做的一个示例:我正在使用 JSF2 和 primefaces
registration.xhtml - 交易的起点
RegistrationBean - registration.xhtml 使用的支持 bean - 具有通过 registration.xhtml 上的 commanButton 调用的“创建”(也处理输入的数据并假设设置 ResultBean)方法,然后返回用于导航的字符串(到 result.xhtml)
result.xhtml - 交易的结果 UI
ResultBean - 保存 result.xhtml 所需的值
我一直在互联网上搜索样本,但似乎找不到。有没有办法做到这一点?如果没有,也许是一种解决方法?我是使用这个的初学者。任何帮助将不胜感激。提前致谢!请参阅下面的示例代码。
注册.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>
.....
.....
注册豆:
@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";
}
}
结果.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>
.....
.....
结果豆:
@ManagedBean (name = "partyResponse")
@ViewScoped //changed to @ConversationScoped
public Class ResultBean implements Serializable{
private Date lastChangedDateItem;
//more variables
//getters and setters
}
面孔-config.xml
<navigation-rule>
<navigation-case>
<from-outcome>result</from-outcome>
<to-view-id>/result.xhtml</to-view-id>
</navigation-case>
</navigation-rule>