10 Replies Latest reply on Jan 25, 2008 2:21 PM by Sergey Smirnov

    Command Buttons in <rich:dataTable>

    Deibys Quintero Newbie

      Hello guys ,

      I am posting again, to provide more information.... I have the following code:

      <rich:dataTable id="prospectoTable" value="#{SearchProspecto.prospectoItems}"
       var="prospecto" rowKeyVar="index"
       onRowMouseOver="this.style.backgroundColor='#FFE4E1'"
       onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'" >
       <h:column>
       <f:facet name="header">
       <h:outputText value="#" />
       </f:facet>
       <h:outputText value="#{index+1}" />
       </h:column>
       <h:column>
       <f:facet name="header">
       <h:outputText value="Identificacion" />
       </f:facet>
       <h:outputText value="#{prospecto.identificacion}" />
       </h:column>
       <h:column>
       <f:facet name="header">
       <h:outputText value="Nombre" />
       </f:facet>
       <h:outputText value="#{prospecto.fullName}" />
       </h:column>
       <h:column>
       <h:form>
       <a4j:commandButton immediate="true" value="Editar" action="#{SearchProspecto.editar}" >
       <a4j:actionparam name="prospectoIdSelected" assignTo="#{SearchProspecto.prospectoIdSelected}" value="#{prospecto.id}" />
       </a4j:commandButton>
       </h:form>
       </h:column>
       <%--
       <rich:componentControl event="onRowDblClick" for="propectoDetails" operation="show">
       <f:param value="#{prospecto.id}" name="prospectoId" />
       </rich:componentControl>
       --%>
      </rich:dataTable>


      I have a command button for every row in the table.... When clicked it should navigate to another page through an ajax request.
      The code in the backing bean is:
      public String editar() throws NamingException, SQLException {
       System.out.println("prospecto_id="+prospectoIdSelected);
       Prospecto prospecto = Prospecto.getProspectoById(prospectoIdSelected);
       FacesUtil.setRequestMapValue("prospecto", prospecto);
       if (prospecto.getTipoCliente() == 1) {
       System.out.println("editar_empresarial");
       return "editar_empresarial";
       } else {
       System.out.println("editar_individual");
       return "editar_individual";
       }
       }
      


      The issue I have ...it is that action bean method gets executed by navigation rules are not applied.......... I have in faces-config.xml
      <navigation-rule>
       <from-view-id>/Prospectacion/searchProspecto.jsp</from-view-id>
       <navigation-case>
       <from-outcome>editar_empresarial</from-outcome>
       <to-view-id>/Prospectacion/editProspecto_e.jsp</to-view-id>
       </navigation-case>
       <navigation-case>
       <from-outcome>editar_individual</from-outcome>
       <to-view-id>/Prospectacion/editProspecto_i.jsp</to-view-id>
       </navigation-case>
       </navigation-rule>
      
      


      Please provide me with some information:

      I have already done some ajax navigations just exactly like the example in the demo:http://livedemo.exadel.com/richfaces-demo/richfaces/include.jsf?c=include

      But is there any issue if commandButton is placed inside dataTables ?



      I have tried to put the form outside the <rich:datatable> and it does not work either .....


      deibys





        • 1. Re: Command Buttons in <rich:dataTable>
          Ilya Shaikovsky Master

          please add

          <redirect/>
          to your navigation cases definitions if you use a4j controls for navigation.

          • 2. Re: Command Buttons in <rich:dataTable>
            Deibys Quintero Newbie

            Thanks for the answer....
            I dont think might work for me , because the content I want to update is inside a "" , in the code bellow(orange coloured), navigation should only occur in the "main "

            I have done this and works...exactly in the same way as in the demo http://livedemo.exadel.com/richfaces-demo/richfaces/include.jsf?c=include
            , ...the only difference with this case...it is that command buttons is not inside a <rich:dataTable >

            Is it a bug ? What is the issue ?



            deibys


            The post I have is this :

            <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
            <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
            <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j" %>
            <%@ taglib uri="http://richfaces.org/rich" prefix="rich" %>
            
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
             "http://www.w3.org/TR/html4/loose.dtd">
            
            <html>
            <head>
             <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
             <title>Aplicacion Gambatte</title>
             <style type="text/css">
             #header {
             height: 20px;
             }
             #container{
             margin:0 auto 0 auto;
             width: 96%;
             border: 1px solid gray;
             }
             #main{
             margin-left: 250px; /*Set left margin to LeftColumnWidth*/
             padding: 2em;
             font: small Georgia, serif;
             /* border-left: 1px solid gray; */
             }
             #sidebar{
             float: left;
             width: 220px;
             margin: 0;
             padding: 1em;
             }
             #footer{
             clear: both;
             margin: 0;
             padding: .5em;
             background: #ddd;
             color: #333;
             text-align: center;
             border-top: 1px solid gray;
             }
             .error {
             background: #ffc;
             padding: 0 10px;
             }
             .info {
             background: #33ccff;
             padding: 0 10px;
             }
             </style>
            </head>
            <body>
             <f:view>
             <div id="container" >
             <div id="header">
             <rich:toolBar>
             <rich:toolBarGroup>
             <h:outputText value="Bienvenido #{UserBean.userName} !" />
             </rich:toolBarGroup>
             <rich:toolBarGroup location="right">
             <h:form id="logoutForm" >
             <h:commandLink id="logout" action="#{LoginManager.logout}" >
             <h:outputText value="Salir" />
             </h:commandLink>
             </h:form>
             </rich:toolBarGroup>
             </rich:toolBar>
             </div>
             <div id="sidebar">
             <rich:panel>
             <h:form>
             <rich:tree switchType="client" value="#{MenuBean.treeNode}" var="item" id="navigationMenu"
             iconLeaf="/images/gear.gif" iconCollapsed="/images/tree_folder_close.gif"
             iconExpanded="/images/tree_folder_open.gif" icon="false"
             ajaxSingle="true" ajaxSubmitSelection="true" reRender="main2"
             componentState="#{MenuBean.treeState}"
             nodeSelectListener="#{MenuBean.processSelection}" >
            
             <rich:treeNode >
             <h:outputText value="#{item.title}" />
             </rich:treeNode>
             </rich:tree>
             </h:form>
             </rich:panel>
             </div>
             <div id="main">
             <a4j:include viewId="#{MenuBean.optionSelectedUrl}" id="main2" layout="block" />
             </div>
             <rich:spacer width="1" height="10" />
             <div id="footer">
             <h:outputLink value="http://www.coorserpark.com" >
             <f:verbatim>@CopyRight Coorserpark 2008</f:verbatim>
             </h:outputLink>
             </div>
             </div>
             </f:view>
            </body>
            </html>


            • 3. Re: Command Buttons in <rich:dataTable>
              Deibys Quintero Newbie

              Hello,

              I have changed my code to use non-a4j components , and it does not work yet.

              <h:form>
              <rich:dataTable id="prospectoTable" value="#{SearchProspecto.prospectoItems}"
               var="prospecto" rowKeyVar="index"
               onRowMouseOver="this.style.backgroundColor='#FFE4E1'"
               onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'" >
               <h:column>
               <f:facet name="header">
               <h:outputText value="#" />
               </f:facet>
               <h:outputText value="#{index+1}" />
               </h:column>
               <h:column>
               <f:facet name="header">
               <h:outputText value="Identificacion" />
               </f:facet>
               <h:outputText value="#{prospecto.identificacion}" />
               </h:column>
               <h:column>
               <f:facet name="header">
               <h:outputText value="Id Alterna" />
               </f:facet>
               <h:outputText value="#{prospecto.idAlterna}" />
               </h:column>
               <h:column>
               <f:facet name="header">
               <h:outputText value="Nombre" />
               </f:facet>
               <h:outputText value="#{prospecto.fullName}" />
               </h:column>
               <h:column>
               <f:facet name="header">
               <h:outputText value="Estado" />
               </f:facet>
               <h:outputText value="#{prospecto.status}" />
               </h:column>
               <h:column>
               <h:commandButton immediate="true" value="Editar" action="#{SearchProspecto.editar}" >
               <f:setPropertyActionListener value="#{prospecto.id}" target="#{SearchProspecto.prospectoIdSelected}" />
               </h:commandButton>
               </h:column>
               <%--
               <rich:componentControl event="onRowDblClick" for="propectoDetails" operation="show">
               <f:param value="#{prospecto.id}" name="prospectoId" />
               </rich:componentControl>
               --%>
              </rich:dataTable>
              </h:form>



              Again there are my navigation rules:
              <navigation-rule>
               <from-view-id>/Prospectacion/searchProspecto.jsp</from-view-id>
               <navigation-case>
               <from-outcome>editarEmpresarial</from-outcome>
               <to-view-id>/faces/Prospectacion/editProspecto_e.jsp</to-view-id>
               </navigation-case>
               <navigation-case>
               <from-outcome>editarIndividual</from-outcome>
               <to-view-id>/faces/Prospectacion/editProspecto_i.jsp</to-view-id>
               </navigation-case>
               </navigation-rule>
              


              And my backing bean method (gets invoked , but navigation does not occur)
              public String editar() throws NamingException, SQLException {
               System.out.println("prospecto_id="+prospectoIdSelected);
               Prospecto prospecto = Prospecto.getProspectoById(prospectoIdSelected);
               FacesUtil.setRequestMapValue("prospecto", prospecto);
               if (prospecto.getTipoCliente() == 1) {
               System.out.println("editar_empresarial");
               return "editarEmpresarial";
               } else {
               System.out.println("editar_individual");
               return "editarIndividual";
               }
               }
              


              in web.xml:
              <servlet>
               <servlet-name>Faces Servlet</servlet-name>
               <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
               <load-on-startup>1</load-on-startup>
               </servlet>
               <servlet-mapping>
               <servlet-name>Faces Servlet</servlet-name>
               <url-pattern>/faces/*</url-pattern>
               </servlet-mapping>
              


              • 4. Re: Command Buttons in <rich:dataTable>
                Sergey Smirnov Master

                put <rich:messages /> somewhere on the page.

                • 5. Re: Command Buttons in <rich:dataTable>
                  Deibys Quintero Newbie

                  Hello Sergey,

                  I put <rich:messages /> and no message is thrown....

                  <h:form>
                  <rich:messages id="errorMessages" />
                  <rich:dataTable id="prospectoTable" value="#{SearchProspecto.prospectoItems}"
                   var="prospecto" rowKeyVar="index"
                   onRowMouseOver="this.style.backgroundColor='#FFE4E1'"
                   onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'" >
                   <h:column>
                   <f:facet name="header">
                   <h:outputText value="#" />
                   </f:facet>
                   <h:outputText value="#{index+1}" />
                   </h:column>
                   <h:column>
                   <f:facet name="header">
                   <h:outputText value="Identificacion" />
                   </f:facet>
                   <h:outputText value="#{prospecto.identificacion}" />
                   </h:column>
                   <h:column>
                   <f:facet name="header">
                   <h:outputText value="Id Alterna" />
                   </f:facet>
                   <h:outputText value="#{prospecto.idAlterna}" />
                   </h:column>
                   <h:column>
                   <f:facet name="header">
                   <h:outputText value="Nombre" />
                   </f:facet>
                   <h:outputText value="#{prospecto.fullName}" />
                   </h:column>
                   <h:column>
                   <f:facet name="header">
                   <h:outputText value="Estado" />
                   </f:facet>
                   <h:outputText value="#{prospecto.status}" />
                   </h:column>
                   <h:column>
                   <%-- <h:form> --%>
                   <a4j:region >
                   <a4j:commandButton immediate="true" value="Editar" action="#{SearchProspecto.editar}" >
                   <a4j:actionparam name="prospectoId" value="#{prospecto.id}" assignTo="#{SearchProspecto.prospectoIdSelected}" />
                   </a4j:commandButton>
                   </a4j:region>
                   <%-- </h:form> --%>
                   </h:column>
                   <%--
                   <rich:componentControl event="onRowDblClick" for="propectoDetails" operation="show">
                   <f:param value="#{prospecto.id}" name="prospectoId" />
                   </rich:componentControl>
                   --%>
                  </rich:dataTable>
                  </h:form>


                  I was wondering if it has to do something with specs (software):

                  JBOSS 4.2.2GA (builtin JSF I guess 1.2)
                  is it a bug ? I am really clueless

                  cheers, deibys




                  • 6. Re: Command Buttons in <rich:dataTable>
                    Sergey Smirnov Master

                     

                    "d_fdo@yahoo.com" wrote:

                    is it a bug ? I am really clueless


                    No proofs for bug yet.

                    remove a4j:region from h:column. It is just does not make any sense there.
                    define the id for h:form and commandButton explicitly

                    If no luck, add phase tracker and see what phases JSF comes thought. You can take the read-to-use phase tracker at:
                    http://www.jsftutorials.net/faces-config/phaseTracker.html

                    • 7. Re: Command Buttons in <rich:dataTable>
                      Deibys Quintero Newbie

                      Hello,
                      I have added id's for <h:form> and <a4j:commandButton>

                      and this is what I have got from the phaseTracker, though I really dont know how to interpret it....that is the output when i click o any button of the dataTable

                      12:53:15,758 ERROR [STDERR] 25/01/2008 12:53:15 PM org.exadel.jsf.PhaseTracker beforePhase
                      INFO: BEFORE RESTORE_VIEW 1
                      12:53:15,820 ERROR [STDERR] 25/01/2008 12:53:15 PM org.exadel.jsf.PhaseTracker afterPhase
                      INFO: AFTER RESTORE_VIEW 1
                      12:53:15,820 ERROR [STDERR] 25/01/2008 12:53:15 PM org.exadel.jsf.PhaseTracker beforePhase
                      INFO: BEFORE APPLY_REQUEST_VALUES 2
                      12:53:15,851 ERROR [STDERR] 25/01/2008 12:53:15 PM org.exadel.jsf.PhaseTracker afterPhase
                      INFO: AFTER APPLY_REQUEST_VALUES 2
                      12:53:15,851 ERROR [STDERR] 25/01/2008 12:53:15 PM org.exadel.jsf.PhaseTracker beforePhase
                      INFO: BEFORE RENDER_RESPONSE 6
                      12:53:16,008 ERROR [STDERR] 25/01/2008 12:53:16 PM org.exadel.jsf.PhaseTracker afterPhase
                      INFO: AFTER RENDER_RESPONSE 6


                      I see [STDERR] , but i dont know....this appears in almost every page of my application , and they seem to work fine.....


                      deibys


                      • 8. Re: Command Buttons in <rich:dataTable>
                        Sergey Smirnov Master

                        This is a result of immediate="true". If you set it to "false', it should be all 6 phases passed. Right?

                        • 9. Re: Command Buttons in <rich:dataTable>
                          Deibys Quintero Newbie

                          Hello,

                          I have set immediate to false , and it seems to me the same. Any clue ? Would anybody like me to send some sample code about what is occuring ?

                          deibys

                          14:06:53,461 ERROR [STDERR] 25/01/2008 02:06:53 PM org.exadel.jsf.PhaseTracker beforePhase
                          INFO: BEFORE RESTORE_VIEW 1
                          14:06:53,492 ERROR [STDERR] 25/01/2008 02:06:53 PM org.exadel.jsf.PhaseTracker afterPhase
                          INFO: AFTER RESTORE_VIEW 1
                          14:06:53,492 ERROR [STDERR] 25/01/2008 02:06:53 PM org.exadel.jsf.PhaseTracker beforePhase
                          INFO: BEFORE APPLY_REQUEST_VALUES 2
                          14:06:53,492 ERROR [STDERR] 25/01/2008 02:06:53 PM org.exadel.jsf.PhaseTracker afterPhase
                          INFO: AFTER APPLY_REQUEST_VALUES 2
                          14:06:53,492 ERROR [STDERR] 25/01/2008 02:06:53 PM org.exadel.jsf.PhaseTracker beforePhase
                          INFO: BEFORE PROCESS_VALIDATIONS 3
                          14:06:53,726 ERROR [STDERR] 25/01/2008 02:06:53 PM org.exadel.jsf.PhaseTracker afterPhase
                          INFO: AFTER PROCESS_VALIDATIONS 3
                          14:06:53,726 ERROR [STDERR] 25/01/2008 02:06:53 PM org.exadel.jsf.PhaseTracker beforePhase
                          INFO: BEFORE UPDATE_MODEL_VALUES 4
                          14:06:53,726 ERROR [STDERR] 25/01/2008 02:06:53 PM org.exadel.jsf.PhaseTracker afterPhase
                          INFO: AFTER UPDATE_MODEL_VALUES 4
                          14:06:53,726 ERROR [STDERR] 25/01/2008 02:06:53 PM org.exadel.jsf.PhaseTracker beforePhase
                          INFO: BEFORE INVOKE_APPLICATION 5
                          14:06:53,742 ERROR [STDERR] 25/01/2008 02:06:53 PM org.exadel.jsf.PhaseTracker afterPhase
                          INFO: AFTER INVOKE_APPLICATION 5
                          14:06:53,742 ERROR [STDERR] 25/01/2008 02:06:53 PM org.exadel.jsf.PhaseTracker beforePhase
                          INFO: BEFORE RENDER_RESPONSE 6
                          14:06:53,836 ERROR [STDERR] 25/01/2008 02:06:53 PM org.exadel.jsf.PhaseTracker afterPhase
                          INFO: AFTER RENDER_RESPONSE 6



                          • 10. Re: Command Buttons in <rich:dataTable>
                            Sergey Smirnov Master

                            BTW, you do not have to ignore Ilya's advice about < redirect /> in the navigation rules.

                            Ie. it should be:

                            <navigation-rule>
                             <from-view-id>/Prospectacion/searchProspecto.jsp</from-view-id>
                             <navigation-case>
                             <from-outcome>editarEmpresarial</from-outcome>
                             <to-view-id>/faces/Prospectacion/editProspecto_e.jsp</to-view-id>
                             <redirect />
                             </navigation-case>
                             <navigation-case>
                             <from-outcome>editarIndividual</from-outcome>
                             <to-view-id>/faces/Prospectacion/editProspecto_i.jsp</to-view-id>
                             <redirect />
                             </navigation-case>
                             </navigation-rule>


                            What if you, for the testing purpose, put just after <h:form>:
                            <h:commandButton action="editarIndividual" />

                            Does navigation work?