Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 jsf2 commandButton,commandLink不会触发操作_Jsf 2_Commandbutton - Fatal编程技术网

Jsf 2 jsf2 commandButton,commandLink不会触发操作

Jsf 2 jsf2 commandButton,commandLink不会触发操作,jsf-2,commandbutton,Jsf 2,Commandbutton,在这个页面中,h:commandButton不会触发托管bean中的操作方法,但当我单击按钮时,它会重新加载当前页面。我不知道为什么请帮忙 <?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"

在这个页面中,h:commandButton不会触发托管bean中的操作方法,但当我单击按钮时,它会重新加载当前页面。我不知道为什么请帮忙

    <?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>
和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;
}
你用错了方法。选择菜单中的值是一个映射,如果不使用转换器,则无法从选择菜单中设置映射类型的值。在selectitems中,您应该将value属性绑定到托管bean中的某个字符串。然后,在actionMethod中,您可以使用此选定类型从映射中检索选定值

<h:selectOneMenu id="searchtype" value="#{searchView.selectedType}" style="width: 230px">
    <f:selectItems value="{searchView.searchType}"/>
</h:selectOneMenu>

最后,prepareSearchList函数的最后一个语句返回null是不必要的,应该删除它,因为根据您发布的内容,它是一个无法访问的代码。

您能更详细地解释这个问题吗。托管bean的范围是什么,您是否也可以添加prepareSearchResultView的代码?单击命令按钮后,您想要实现什么?您想要更改某些内容还是要导航到另一个页面?发布您的searchView代码在getters中显示使用过的注释SBTW:never do business logic。另见
<h:selectOneMenu id="searchtype" value="#{searchView.selectedType}" style="width: 230px">
    <f:selectItems value="{searchView.searchType}"/>
</h:selectOneMenu>
<h:selectOneMenu id="searchtype" value="#{searchView.selectedType}" style="width: 230px">
    <f:selectItems value="{searchView.searchType}" 
                   var="searchType" 
                   itemLabel=#{searchType.key} 
                   itemValue=#{searchType.value}/>
</h:selectOneMenu>

List<RowItems> searchType = Lists.newArrayList(); // guave constructor

@PostConstruct
public void initBean(){
    if(loginview.isAbleToGetCitizenInfo() || loginview.isUserAdmin()){
        searchType.add(new RowItems("searchType1", "searchcitizenbyregno"));
        searchType.add(new RowItems("searchtype2", "searchcitizenbyname"));
    }
    if(loginview.isAbleToGetOrgInfo() || loginview.isUserAdmin()){
        searchType.add(new RowItems("searchtype3", "searchorgbyregno"));
        searchType.add(new RowItems("searchtype4", "searchgorgbyname"));
        searchType.add(new RowItems("searchtype5", "searchorgbystateregno"));
    }
}

public List<RowItems> getSearchType(){
    return searchType
}