0
我是usnig jsf 2.1和PrimeFaces 4.0。 我有是有一個鏈接等簡單的html頁面的index.html:轉發到具有相同受管bean的相同頁面
<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>
我不能夠得到的值。如果這是錯誤的方式,那麼請給我一個適當的建議。
感謝重播莫Yapro ...這是曾與AJAX事件
\t \t \t \t \t \t \t \t \t \t
\t \t \t \t \t \t \t \t \t P:的commandButton> –