在這個頁面中,h:commandButton
不會觸發託管bean中的操作方法,但是當我點擊按鈕時它會重新加載當前頁面。我不知道爲什麼請幫助。jsf2 commandButton,commandLink不會觸發動作
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
>
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
<h:outputStylesheet library ="css" name="bootstrap.css"/>
<h:outputStylesheet library ="css" name="bootstrap-responsive.css"/>
<h:outputScript library="js" name="bootstrap.js"/>
<h:outputScript library="js" name="bootstrap-responsive.js"/>
</h:head>
<h:body>
<h:form>
<label><h3>Search</h3></label>
<h:selectOneMenu id="searchtype" value="#{searchView.searchType}" style="width: 230px">
<f:selectItems value="#{searchView.searchType}"/>
</h:selectOneMenu>
<br/>
<h:inputText id="searchvalue" value="#{searchView.searchvalue}" required="true" style="height: 30px; width: 230px">
<p:watermark value="Search type" for="searchvalue"/>
</h:inputText>
<br/>
<h:commandButton id="searchbtn" value="Search" action="#{searchView.prepareSearchResultView()}" styleClass="btn"/>
</h:form>
</h:body>
</html>
而我的searchView託管bean是會話作用域,這裏是managed託管bean中的prepareSearchResultView()方法;
public String prepareSearchResultView(){
this.searchResultList = searchCustomer();
if(!this.searchResultList.isEmpty()){
this.citizenSearchResultList = getCitizenSearchList();
this.orgSearchResultList = getOrganizationSearchList();
if(getCitizenSearchList().getRowCount() >0){
return "citizensearchlist";
}else if(getOrganizationSearchList().getRowCount()>0){
return "orgsearchlist";
}
}else
return "nosearchresult";
//FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "no such result", "no such result"));
return null;
}
和getSearchType()方法
public Map<String, Object> getSearchType(){
Map<String, Object> returnMap = new LinkedHashMap<String, Object>();
if(loginview.isAbleToGetCitizenInfo() || loginview.isUserAdmin()){
returnMap.put("searchtype1", "searchcitizenbyregno");
returnMap.put("searchtype2", "searchcitizenbyname");
}
if(loginview.isAbleToGetOrgInfo() || loginview.isUserAdmin()){
returnMap.put("searchtype3", "searchorgbyregno");
returnMap.put("searchtype4", "searchgorgbyname");
returnMap.put("searchtype5", "searchorgbystateregno");
}
return returnMap;
}
你能更詳細地解釋問題嗎?你管理的bean的範圍是什麼,你可以添加prepareSearchResultView的代碼嗎?點擊命令按鈕後,您想要實現什麼功能?您想要更改某些內容還是要導航到其他頁面? – cubbuk
發佈您的'searchView'代碼顯示使用的註釋 – Daniel
我更新了我的問題 – Odgiiv