0

我是 usnig jsf 2.1 和 PrimeFaces 4.0。我有一个简单的 html 页面 index.html,它的链接如下:

<a href="pages/findus.jsf">

此链接打开的页面 findus.jsf,在此页面上我有命令按钮:

<p:commandButton value="Find" action="#{findUsBean.onClickBtnFindUs}">

在 onClickBtnFindUs 我需要为 FindUsBean 的字段设置一些值并重定向到同一页面意味着 findus.jsf 并希望在 findus.jsf 页面上检索该值。以下是我完整的 FindUsBean。

@ManagedBean(name = "findUsBean")
@RequestScoped
public class FindUsBean implements Serializable{

private static final long serialVersionUID = 1L;

@ManagedProperty(value = "#{findUsService}")
private FindUsService findUsService;
private String state;
private String city;
private String zip;
private String result;

public String onClickBtnFindUs(){
    RestaurantLocationMaster restoLoc = new RestaurantLocationMaster();

    System.out.println(getState());

    restoLoc.setResState(getState());
    restoLoc.setResCity(getCity());
    restoLoc.setResZip(getZip());

    restoLoc = findRestaurantLocation(restoLoc);
    if(null != restoLoc){
        setState(restoLoc.getResState());
        setCity(restoLoc.getResCity());
        setZip(restoLoc.getResZip());
        setResult(restoLoc.getResAddress1()+","+restoLoc.getResAddress2());
    }else{
        setResult("Comming soon...");
    }

    System.out.println(getState() +""+getCity());
    return "/pages/findus.jsf";
}

public RestaurantLocationMaster findRestaurantLocation(RestaurantLocationMaster    restoLoc){
    RestaurantLocationMaster restoLoc1 = null;
    restoLoc1 = findUsService.findRestaurantLocation(restoLoc);
    return restoLoc1;
}

public String getState() {
    return state;
}
public void setState(String state) {
    this.state = state;
}
public String getCity() {
    return city;
}
public void setCity(String city) {
    this.city = city;
}
public String getZip() {
    return zip;
}
public void setZip(String zip) {
    this.zip = zip;
}
public void setFindUsService(FindUsService findUsService) {
    this.findUsService = findUsService;
}
public FindUsService getFindUsService() {
    return findUsService;
}

public void setResult(String result) {
    this.result = result;
}

public String getResult() {
    return result;
}

}

我的 findus.jsf 是:

<h:form prependId="false" method='POST'>
<table>
    <tr>
        <td><p:outputLabel value="State"></p:outputLabel>
        </td>
        <td><p:inputText maxlength="20" value="#{findUsBean.state}"></p:inputText>
        </td>
    </tr>
    <tr>
        <td><p:outputLabel value="city"></p:outputLabel>
        </td>
        <td><p:inputText maxlength="20" value="#{findUsBean.city}"></p:inputText>
        </td>
    </tr>
    <tr>
        <td><p:outputLabel value="zip"></p:outputLabel>
        </td>
        <td><p:inputText maxlength="8" value="#{findUsBean.zip}"></p:inputText>
        </td>
    </tr>
    <tr>
        <td colspan="2" align="right"><p:commandButton value="Find"
                action="#{findUsBean.onClickBtnFindUs}">
            </p:commandButton>
        </td>
    </tr>
    <tr>
        <td colspan="2"></td>
    </tr>
    <tr>
        <td></td>
        <td><p:inputTextarea value="#{findUsBean.result}"
                readonly="true"></p:inputTextarea>
        </td>
    </tr>
</table>

我无法获得价值。如果这是错误的方式,那么请建议我正确的方式。

4

1 回答 1

0

The problem ist the scope of your bean. You should use @ViewScope or a larger scope.

Have a look here

于 2013-11-15T07:41:28.400 回答