3 Replies Latest reply on May 25, 2008 12:12 AM by Delali Dzirasa

    Command Lnks inside DataTable

    Deibys Quintero Newbie

      Hello Guys!!
      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:region>
       <a4j:commandLink immediate="true" value="Editar" action="#{SearchProspecto.editar}" >
       <a4j:actionparam name="prospectoIdSelected" assignTo="#{SearchProspecto.prospectoIdSelected}" value="#{prospecto.id}" />
       </a4j:commandLink>
       </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>
      


      One of the columns (violet colour) has a command link.....that calls a method in the backing bean


      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) {
       return "editar_empresarial";
       } else {
       return "editar_individual";
       }
       }
      


      I have two weird issues:
      1. Only the last row of the table seems to call the method specified in the action attribute


      2. When I click on the link on the last row , method gets called, but it does not navigate according to my rules 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>
      


      Why this stranged behaviour ?

        • 1. Re: Command Lnks inside DataTable
          Sergey Smirnov Master

          Having form inside the table column is a bad idea in general.

          Why you use Ajax command link if you expect non-Ajax response (using the navigation rule) ?

          • 2. Re: Command Lnks inside DataTable
            Deibys Quintero Newbie

            If it is bad idea , what is the way to go ? in my application i need to have a submit element inside a table , one per each element...
            For instance, I have a table of clientes, and when i click on the "edit" button present in every row....It should go to the "edit client" view

            I use a4j:commandButton or link, because I want my application to have a non-reload page feeling, so...almost every request is done by ajax


            I have put the form outside of the dataTable and it does not work at all. In no case the action method is called

            <h:form>
            <rich:messages />
            <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>
             <a4j:commandButton immediate="true" value="Editar" action="#{SearchProspecto.editar}" >
             <a4j:actionparam name="prospectoIdSelected" assignTo="#{SearchProspecto.prospectoIdSelected}" value="#{prospecto.id}" />
             </a4j:commandButton>
             </h:column>
             <%--
             <rich:componentControl event="onRowDblClick" for="propectoDetails" operation="show">
             <f:param value="#{prospecto.id}" name="prospectoId" />
             </rich:componentControl>
             --%>
            </rich:dataTable>
            </h:form>


            Thanks in advance for any help

            • 3. Re: Command Lnks inside DataTable
              Delali Dzirasa Newbie

              having the same problem...did you ever figure this out?