9 Replies Latest reply on Mar 26, 2008 11:44 AM by Pericles Junior

    How link by clicking in a row in a dataTable?

    Pericles Junior Newbie

      Hi,


      I use Seam Generate Entities for generate xhtml files and components of my application and it generates in xhtml files all a dataTables with one column named Action and this column have links to the edit page of this component.


      I want to eliminate this column and persist the link funcionality but only if user click in the row of the table. I modify the code of the table to this:



      <rich:dataTable id="tipologiesList"
      onRowMouseOver="this.style.backgroundColor='#DfDfF8'"
      onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
      onRowClick="#{empty from ? 'Tipologies' : from}.xhtml"
      var="tipologies"                                value="#{tipologiesList.resultList}" 
      rendered="#{not empty tipologiesList.resultList}">




      The column action is defined like this:



              <h:column>
                  <f:facet name="header">action</f:facet>
                  <s:link view="/#{empty from ? 'Tipologies' : from}.xhtml" 
                         value="Select" 
                            id="tipologies">
                      <f:param name="tipologiesId" 
                              value="#{tipologies.id}"/>
                  </s:link>
              </h:column>




      My level in Seam is basic (and in English too ;) ), and I'd like to know how I can do this. If I click in one row of the dataTable go to the same page that links the Action column to that row but without this column.


      I hope I explind me well.


      Thank you very much

        • 1. Re: How link by clicking in a row in a dataTable?
          mars1412 Apprentice

          I think you will need to use the onRowClick event and then submit the form from java-script...

          • 2. Re: How link by clicking in a row in a dataTable?
            Pericles Junior Newbie

            Can you say an little exemple please?


            Thanks.

            • 3. Re: How link by clicking in a row in a dataTable?
              mars1412 Apprentice

              I haven't done that myself yet, but I would try the following:



              • check the source code produced by your original s:link e.g.



              <input type="button" value="ändern" id="j_id40" onclick="location.href='/xxx.seam?tipologiesId=1'; return false;"/>




              • then do the same in your onRowClick() event



              onRowClick="location.href='/Tipologies.seam?tipologiesId=#{tipologies.id}';"



              if you are in a long-running conversation, you will also have to append the cid as URL parameter

              • 4. Re: How link by clicking in a row in a dataTable?
                Paul Pantages Novice

                Hello Javi, I have had good luck using a4j:jsFunction for this sort of thing. Something like this:


                                  <!-- ondbClick edit -->
                                  <a4j:region>
                                     <a4j:jsFunction 
                                        name="fedit"
                                        eventsQueue="feditQ"
                                        timeout="5000"
                                        action="#{neEditor.edit}" >
                                        <f:param name="neId"/>
                                        <f:param name="ctx"   value="nodetable" />
                                        <f:param name="cid"   value="#{conversation.id}" />
                                    </a4j:jsFunction>
                                  </a4j:region>
                
                                  <rich:dataTable 
                                     rowClasses="alarmRowOdd, alarmRowEven"
                                     onRowDblClick="fedit('#{networkElement.id}')"
                                     value="#{nodeList}" 
                                     var="networkElement" 
                                     rendered="true" >
                


                The parameters to fedit() are just assigned, in order, to the f:params. So the parameter netwrokrElement.id will be assigned to f:param neId. If you passed a second parameter, it would override the ctx. Otherwise, ctx assumes the default value specified in the f:param.


                I found (through trial and error) that the single quotes are needed around the parameter or it doesn't work.


                Note that I am using an action method here; You should be able to set the action to the view from your s:link...


                PdP

                • 5. Re: How link by clicking in a row in a dataTable?
                  Pericles Junior Newbie

                  Hello again,


                  I'll prove both proposals today, thank you very much Martin and Paul for help me ;).


                  I will inform.


                  Bye

                  • 6. Re: How link by clicking in a row in a dataTable?
                    Pericles Junior Newbie
                    ...

                    Note that I am using an action method here; You should be able to set the action to the view from your s:link...

                    PdP



                    Hi again Paul,


                    I prove it but doesn't work. I think I'm following badly your indications. I do this:



                        <a:region>
                           <a:jsFunction 
                                  id="fedit"
                              name="fedit"
                              eventsQueue="feditQ"
                              timeout="5000"
                              action="#{neEditor.edit}" >
                              <f:param name="neId"/>
                              <f:param name="ctx"   value="nodetable" />
                              <f:param name="cid"   value="#{conversation.id}" />
                          </a:jsFunction>
                        </a:region>
                                         
                        <rich:dataTable id="permisosTipologiaList" 
                                            rowClasses="alarmRowOdd, alarmRowEven"
                                            onRowMouseOver="this.style.backgroundColor='#E9F0F8'"
                                            onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
                                            onRowClick="fedit('#{permisosTipologia.id}')"
                                         var="permisosTipologia"
                                            value="#{permisosTipologiaList.resultList}" 
                                              rendered="#{not empty permisosTipologiaList.resultList}">
                               
                            <h:column>
                                <f:facet name="header">
                                    <s:link 
                                         name="header"
                                         id="permisosTipologies"
                                         value="#{messages['documentTypeId']} #{permisosTipologiaList.order=='tipologies.id asc' ? messages.down : (permisosTipologiaList.order=='tipologies.id desc' ? messages.up : '' )}"
                                         action="">
                                        <f:param name="order" value="#{permisosTipologiaList.order=='tipologies.id asc' ? 'tipologies.id desc' : 'tipologies.id asc'}"/>
                                    </s:link>
                                </f:facet>
                                #{permisosTipologia.tipologies.descripcio}
                            </h:column>




                    Now, without the function, the s:link do this.


                                   <s:link view="/#{empty from ? 'Tipologies' : from}.xhtml" 
                                          id="tipologia">
                                         <f:param name="tipologiesId" 
                                              value="#{tipologies.id}"/>
                                #{tipologies.descripcio}
                                </s:link>



                    How can I do to set the action link correctly?


                    Thank you very much.

                    • 7. Re: How link by clicking in a row in a dataTable?
                      Pericles Junior Newbie

                      I do it with Martin's solution, it works:



                          <rich:dataTable id="permisosTipologiaList" 
                                                      onRowMouseOver="this.style.backgroundColor='#E9F0F8'"
                                                      onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
                                                      onRowClick="location.href='/gucudo/PermisosTipologia.seam?permisosTipologiaIdUsuari=#{permisosTipologia.id.idUsuari}&amp;permisosTipologiaIdTipologia=#{permisosTipologia.id.idTipologia}&amp;permisosTipologiaIdTipus=#{permisosTipologia.id.idTipus}&amp;cid=#{conversation.id}'"
                                              var="permisosTipologia"
                                              value="#{permisosTipologiaList.resultList}" 
                                                      rendered="#{not empty permisosTipologiaList.resultList}">




                      But put the url like this... it's a badly ingeniering aplication with Seam, I think Paul solution is better (thinking in Seam) but I don't know how use it, can anybody help me to do it?


                      Thanks a lot.

                      • 8. Re: How link by clicking in a row in a dataTable?
                        Paul Pantages Novice

                        Hello Javi, looking at your s:link,


                        Try setting the action to the view
                        Then add your parameters (id in this case)
                        Then add the cid (s:link normally adds this)


                        It might be easier to harcode the action initially,
                        to get it working.



                            <a:region>
                               <a:jsFunction 
                                      id="fedit"
                                  name="fedit"
                                  eventsQueue="feditQ"
                                  timeout="5000"
                                  action="/Tipologies.xhtml" 
                                  <f:param name="tipologiesId"/>
                                  <f:param name="cid"   value="#{conversation.id}" />
                              </a:jsFunction>
                            </a:region>
                        
                            ...
                            ...
                        
                            onRowClick="fedit('#{permisosTipologia.id}')"
                        
                        



                        • 9. Re: How link by clicking in a row in a dataTable?
                          Pericles Junior Newbie

                          Hi Pau Pantages,


                          Thank you for the help, I can't prove it now but in a few days I will test it and say here the results.


                          Thank you very much.