我有一個Web應用程序,它在命中按鈕時基本處理用戶的條目,然後接收事務的響應/結果消息,並且應該將顯示在另一個JSF頁面中。如何在響應期間將支持bean傳遞/重定向/派發到JSF頁面
這裏就是我想要做的一個例子:我使用JSF2和primefaces
registration.xhtml - 起點爲交易
RegistrationBean - 後臺bean使用registration.xhtml - 擁有通過registration.xhtml上的commanButton調用的「create」(也處理輸入的數據並假定設置了ResultBean)方法,然後返回導航字符串(至result.xhtml)
result.xhtml - 交易
ResultBean的結果UI - 持有由result.xhtml
我一直在尋找在互聯網上的樣品需要的值,似乎找不到一個。有沒有辦法做到這一點?如果沒有,也許是一種解決方法?我是一個初學者使用這個。任何幫助將不勝感激。提前致謝! 請參閱下面的示例代碼。
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>
對不起,對我來說,目前還不清楚是什麼你要實現的目標。哪裏有問題? (導航規則在JSF 2.0中不是必需的) –
謝謝Matt。我想在這裏實現的是result.xhtml應該包含ResultBean(在createButton中設置)。我需要在result.xhtml頁面 –