h:即使将disabled更改为true并使用a4j:commandButton重新呈现它,commandButton仍保持禁用状态

时间:2014-03-10 20:16:18

标签: jsf commandbutton disabled-control

我有一个inputtext页面,我在其中输入要搜索的作者的姓名,当我点击a4j:commandButton searchButton时,我想启用{{ 1}} h:commandButton,如果搜索没有返回作者,则禁用该按钮,如果搜索返回作者。首先,应禁用GoToBUtton,这是默认行为。

问题是,GoToButton始终被禁用,它永远不会改变。怎么了?

goToButton

InsertAuthControllerPt1.java的搜索方法

<h:form>
 <div align="left">
<rich:panel id="panel" style="width:310px">
           <h:panelGrid columns="3">
              Nome do autor: <h:inputText id="nameInput" 
              value="#{insertAuthControllerPt1.nameToSearch}"/>

                <a4j:commandButton id="searchButton" value="Procurar" 
           action="#{insertAuthControllerPt1.searchAuthor()}"
            render="authorTable, goToButton">              
           </a4j:commandButton>

           </h:panelGrid>  
       </rich:panel> 


   <h:panelGrid id="authorTable">
       <rich:dataTable value="#{insertAuthControllerPt1.authorListOfMap}"  var="result">
            <c:forEach items="#{insertAuthControllerPt1.variableNames}" var="vname">
                 <rich:column>
                     <f:facet name="header">#{vname}</f:facet>
                      #{result[vname]}
                 </rich:column> 
            </c:forEach>    
       </rich:dataTable>
       <br /> 
   </h:panelGrid>


<h:commandButton id="goToButton" value="Go" action="InsertAuthorPt2" 
           disabled="#{insertAuthControllerPt1.disabled}">
             <f:setPropertyActionListener target="#{insertAuthorController.flag}"
                         value="true" />      
           </h:commandButton>
 </div>
</h:form>

2 个答案:

答案 0 :(得分:1)

首先,强烈建议不要混用JSTL标签和Facelets标签(参见:JSTL in JSF2 Facelets… makes sense?

然后您将使用f:ajax标记。在执行操作后,您基本上将使用ajax调用来呈现goToButton

<h:commandButton id="searchButton" value="Search" action="#{insertAuthControllerPt1.searchAuthor()}">
    <f:ajax render="goToButton">
</h:commandButton>

不要错过将AJAX用于JSF:

答案 1 :(得分:0)

h:commandButton更改为a4j:commandButton并添加render属性:

<a4j:commandButton id="searchButton" value="Search" 
    action="#{insertAuthControllerPt1.searchAuthor()}"
    render="goToButton" />