8 Replies Latest reply on Jun 1, 2010 1:32 PM by Hugo Barona

    Problem with action of <a4j:commandButton> inside an <rich:datatable>

    Hugo Barona Newbie


      I'm having a problem with an <a4j:commandbutton> inside of an  <rich:datatable>.

      I'm declaring the button like this:

      <a4j:commandButton value="Remove"  image="../../images/icons/delete.png" style="border : 0"  actionListener="#{userGroup.removeUserFromUsers}" />

      Then, i'm calling the fuction removeUserFromUsers of the bean userGroup.

      public void removeUserFromUsers(ActionEvent event) throws  SQLException {
      System.out.println("Entrouuuu neste método!!!");


      The problem is if the button is inside the datatable, nothing happens (  no printout on console). It's like it doesn't call the method.

      If the button is outside the datatable, it calls the method without  problem, and prints the string.

      if anyone can help me, it would be very useful for me


        • 3. Re: Problem with action of <a4j:commandButton> inside an <rich:datatable>
          Hugo Barona Newbie

          I'm sorry for the spamm of code, but it's necessary to understand the structure, and maybe my problem is on structure of JSP file.



          JSP file:


          <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
          <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
          <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
          <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
              <a4j:form ajaxSubmit="true">


                  <f:facet name="Find User">
                      <h:outputText value="Find User"></h:outputText>
                  <h:panelGrid columns="4">
                      <h:outputText value="Email: " />
                      <rich:inplaceInput id="emailInput" value="#{userGroup.search}"
                          defaultLabel="click to enter email for search" />
                      <a4j:outputPanel id="errorMsg" ajaxRendered="true">
                          <rich:spacer width="100"></rich:spacer>
                          <h:outputText value="#{userGroup.errorMessage}" />
                  <a4j:commandButton style="float:left;" value="Search"
                      actionListener="#{userGroup.findUser}" reRender="users" />
                  <rich:spacer height="50">


                  <rich:dataTable id="users" value="#{userGroup.queryUser}"
                      binding="#{userGroup.dataTable}" rows="8" var="user" >
                      <f:facet name="header">
                              <rich:column colspan="8">
                                  <h:outputText value="Users" />


                              <rich:column width="50" breakBefore="true">
                                  <h:outputText value="Edit" />
                              <rich:column width="60">
                                  <h:outputText value="Person ID" />
                              <rich:column width="60">
                                  <h:outputText value="User ID" />
                              <rich:column width="150">
                                  <h:outputText value="Username" />
                              <rich:column width="150">
                                  <h:outputText value="Email" />
                              <rich:column width="80">
                                  <h:outputText value="Date of registration" />
                              <rich:column width="50">
                                  <h:outputText value="Remove" />
                      <rich:column width="50">
                          <div align="center"><h:commandButton value="edit"
                              style="height: 24px; width: 24px; border : 0;"
                              action="#{userGroup.captureFieldsUser}" /></div>


                      <rich:column width="60">
                          <div align="center"><h:outputText value="#{user.id}" /></div>
                      <rich:column width="60">
                          <div align="center"><h:outputText value="#{user.sessionId}" /></div>
                      <rich:column width="150">
                          <div align="center"><h:outputText value="#{user.email}" /></div>
                      <rich:column width="150">
                          <div align="center"><h:outputText value="#{user.password}" /></div>
                      <rich:column width="80">
                          <div align="center"><h:outputText value="#{user.dataRegisto}" /></div>
                      <rich:column width="50">
                          <div align="center">
                              <a4j:commandButton value="Remove"
                              image="../../images/icons/delete.png" style="border : 0" reRender="users">
                                  <f:setPropertyActionListener target="#{userGroup.removeUserFromUsers}" value="#{user}"/>
                      <f:facet name="footer">
                          <rich:datascroller id="ds" renderIfSinglePage="true"
                              fastControls="auto" stepControls="auto"></rich:datascroller>




          UserGroup Bean:


          package logic.admin;
          import java.sql.SQLException;
          import java.util.ArrayList;
          import java.util.List


          import data.admin.*;
          import org.richfaces.component.html.HtmlDataTable;
          import logic.admin.JavaMail;
          import javax.faces.event.ActionEvent;
          import javax.faces.model.SelectItem;


          public class UserGroup {
               * Bulk Mail
               * */
              List<SelectItem> comunities;
              List<SelectItem> groups;
              String selectedComunitie;
              String selectedGroup;
              String title;
              String message;
              String selectedMail;
              String email;
              List<RegUser> queryUser;
              List<Group> queryGroups;
              HtmlDataTable dataTable;
              String search;
              String errorMessage;
              admin root;
              char opcao;
              public UserGroup(){
                  queryUser = new ArrayList<RegUser>();
                  comunities = new ArrayList<SelectItem>();
                  groups = new ArrayList<SelectItem>();
                  root= new admin();


              public String getEmail() {
                  return email;


              public void setEmail(String email) {
                  this.email = email;
              public String getSearch() {
                  return search;


              public void setSearch(String search) {
                  this.search = search;


              public List<RegUser> getQueryUser() {
                  return queryUser;


              public void setQueryUser(List<RegUser> queryUser) {
                  this.queryUser = queryUser;


              public HtmlDataTable getDataTable() {
                  return dataTable;


              public void setDataTable(HtmlDataTable dataTable) {
                  this.dataTable = dataTable;


              public String getErrorMessage() {
                  return errorMessage;


              public void setErrorMessage(String errorMessage) {
                  this.errorMessage = errorMessage;


              public List<Group> getQueryGroups() {
                  return queryGroups;


              public void setQueryGroups(List<Group> queryGroups) {
                  this.queryGroups = queryGroups;
              public char getOpcao() {
                  return opcao;


              public void setOpcao(char opcao) {
                  this.opcao = opcao;


              public List<SelectItem> getComunities() throws SQLException {
                  ArrayList<String> result = root.getComunities();
                  for( String s : result)
                      comunities.add(new SelectItem(s));
                  return comunities;


              public void setComunities(List<SelectItem> comunities) {
                  this.comunities = comunities;


              public String getSelectedComunitie() {
                  return selectedComunitie;


              public void setSelectedComunitie(String selectedComunitie) {
                  this.selectedComunitie = selectedComunitie;


              public List<SelectItem> getGroups() throws SQLException {
                  ArrayList<String> result = root.getGroups();
                  for( String s : result)
                      groups.add(new SelectItem(s));
                  return groups;


              public void setGroups(List<SelectItem> groups) {
                  this.groups = groups;


              public String getSelectedGroup() {
                  return selectedGroup;


              public void setSelectedGroup(String selectedGroup) {
                  this.selectedGroup = selectedGroup;


              public void findUser(ActionEvent event) throws SQLException{
                  queryUser = root.findUser(search);
                  errorMessage="Search is done.";
              public String getTitle() {
                  return title;


              public void setTitle(String title) {
                  this.title = title;


              public String getMessage() {
                  return message;


              public void setMessage(String message) {
                  this.message = message;


              public String getSelectedMail() {
                  return selectedMail;


              public void setSelectedMail(String selectedMail) {
                  this.selectedMail = selectedMail;


              public void removeUserFromUsers() throws SQLException {
                  String email = getUserEmail();
                  System.out.println("O email do utilizador é: " + email);
                  if (root.removeUser(email)) {
                      errorMessage = "Utilizador removido com sucesso.";
          //            findUser(null);
                      errorMessage = "Não foi possível remover o utilizador.";


              private String getUserEmail() {
                  return ((RegUser) dataTable.getRowData()).getEmail();


              public String captureFieldsUser() {
          //        FacesContext fc = FacesContext.getCurrentInstance();
          //        Utilizador selectedUser = ((Utilizador) usersTable.getRowData());
                  return null;






          And the registration of the Bean on facesConfig






          Thanks for your help and attention

          • 4. Re: Problem with action of <a4j:commandButton> inside an <rich:datatable>
            Hugo Barona Newbie

            I want to append that i already tried 3 ways of work with <a4j:commandButton>, and no one worked on this example.



            The first is have an ActionListener on the commandButton calling the method of the bean. And on the head of the method on the bean i had as parameter an ActionEvent e.


            The second way was use an Action on the commandButton calling the method of the bean. And on the head of the method on the bean i had no parameter.


            The third way was as it is on the code, using an Property


            <f:setPropertyActionListener target="#{userGroup.removeUserFromUsers}" value="#{user}"/>


            And on the head of the method on the bean i had as parameter an  ActionEvent e.




            • 5. Re: Problem with action of <a4j:commandButton> inside an <rich:datatable>
              Hugo Barona Newbie

              Any idea of the problem? It's really important for me to solve this problem.


              Really thanks for your attention.

              • 7. Re: Problem with action of <a4j:commandButton> inside an <rich:datatable>
                Rob Acraman Newbie

                Just a couple of quick thoughts:

                - When you had the button out of the table, was it still in the same form?

                - Try adding ajaxSingle="true" to the button

                - Try adding a rich:messages component to see if there's any validation,etc problems

                • 8. Re: Problem with action of <a4j:commandButton> inside an <rich:datatable>
                  Hugo Barona Newbie

                  ajaxSingle=true resolved it


                  Really thank you for all help!