0

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>
4

2 に答える 2

1

RegistrationBeanのcreate()メソッドでResultBeanを作成し、プログラムによって修飾されたスコープに配置してみてください。登録ビューを離れているため、ViewScopeは正しい選択ではない可能性があります。

リダイレクトを生き残るために、それをフラッシュスコープに入れてください。

FacesContext.getCurrentInstance().getExternalContext().getFlash().putNow("partyResponse", resultBean);

会話スコープも確認する必要があります。これは、1つのユースケースに属する一連のページのBeanを格納するのに役立ちます。

于 2012-05-10T10:53:32.407 に答える
0

If you only need the simple String, why not using FacesMessage?

public String create(){
    FacesContext.getCurrentInstance()
       .addMessage(null, new FacesMessage("Add your message here"));
    return "result";
}

and in your result.xhtml use the <h:messages> tag:

<h4>Response Identification</h4>
<h:messages/>

Otherwise if you would need more than the result message you should really think over your design and put the ResultBean in a broader scope (conversation or session).

For example with a session scoped bean that holds the current result:

@ManagedBean
@SessionScoped
public Class SessionBean
  private Result currentResult;
  // getter and setter
}

and in your registration bean:

// inject the session scoped bean
@ManagedProperty(value="#{sessionBean}")
private SessionBean sessionBean;

public String create(){
  sessionBean.setCurrentResult(myResult);
  return "result";
}
于 2012-05-10T11:00:09.140 に答える