I have a page with an inputtext
where I type the name of an author to search for, when I click the a4j:commandButton
searchButton
, I'd like to enable the h:commandButton
GoToBUtton
, if the search returns no authors and to disabled that button, if the search returns an author. At first, the GoToButton
should be disabled, that's the default behaviour.
The problem is, goToButton
is always disabled, it never changes. What's wrong?
<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>
Search Method at 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();
}
}