jsf - h:commandButton remains disabled even after changing disabled to true and re-rendering it using a4j:commandButton -


i have page inputtextwhere type name of author search for, when click a4j:commandbutton searchbutton, i'd enable h:commandbutton gotobutton, if search returns no authors , disabled button, if search returns author. @ first, gotobutton should disabled, that's default behaviour.

the problem is, gotobutton disabled, never changes. what's wrong?

<h:form>  <div align="left"> <rich:panel id="panel" style="width:310px">            <h:panelgrid columns="3">               nome 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> 

search method @ insertauthcontrollerpt1.java

public class insertauthorcontrollerpt1 {     private boolean disabled;     private string nametosearch;     private list<string> variablenames;     private list<map<string, string>> authorlistofmap;     private string flag;     private map<string, object> sessionmap;     private list<author> authors;       public insertauthorcontrollerpt1() {         this.authorlistofmap = new arraylist<map<string, string>>();         this.variablenames = new arraylist<string>();         this.sessionmap = new hashmap<string, object>();         this.authors = new arraylist<author>();         this.disabled = true;     }      public void searchauthor() {              this.variablenames.clear();             this.authorlistofmap.clear();             if( this.nametosearch.equals("") ) {                 this.disabled = true;            } else {               try {                 this.findauthorbynameoperation(this.sessionmap, this.flag, this.nametosearch);             }catch(nullpointerexception n) {                  this.disabled = false;                  }catch (exception e) {                 e.printstacktrace();             }                   if( (authors != null) && (!authors.isempty()) ) {                      this.disabled = true;                      for( author author : authors ) {                         map<string, string> map = new hashmap<string, string>();                          map.put("uri", author.geturi().tostring());                         map.put("nome", author.getname());                         map.put("email", author.getemail());                         this.authorlistofmap.add(map);                       }               this.addvariablenames();             } } 

first highly discouraged mix jstl tags , facelets tags (see: jstl in jsf2 facelets… makes sense?)

then use f:ajax tag. use ajax call render gotobutton after action has been executed

<h:commandbutton id="searchbutton" value="search" action="#{insertauthcontrollerpt1.searchauthor()}">     <f:ajax render="gotobutton"> </h:commandbutton> 

not miss using ajax jsf:


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -