我是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>
我无法获得价值观。如果这是错误的方式,请建议我正确的。