1 2 Previous Next 20 Replies Latest reply on Oct 23, 2007 5:15 PM by Stephen Scheck

    Capturing the rowdata of a DataTable

    richfacesuser richfacesuser Newbie

      HELLO

      I am having some difficulty in capturing the rowdata of a <rich:dataTable and <rich:subTable using onRowClick. Can anybody please post a sample code of the jsp and backing bean for the same.

        • 2. Re: Capturing the rowdata of a DataTable
          richfacesuser richfacesuser Newbie

          Thanks very much for the reply.
          Could you please tell me what does the binding method
          binding=""#{ajaxhelper.table} do. If you provide me with a snippet of the bean including the imports for getTable and ActionEvent that will be greatly appreciated.
          Thanks again

          • 3. Re: Capturing the rowdata of a DataTable
            richfacesuser richfacesuser Newbie

            Thanks for the info Carsten.
            I have modified my page and bean as specified in the example.
            The code snippet is as follows.

            <%@ page language="java" pageEncoding="ISO-8859-1"%>
            <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
            <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
            <%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="rich" %>
            <%@taglib prefix="a4j" uri="https://ajax4jsf.dev.java.net/ajax" %>




            <f:view>
            <a4j:form>
            <rich:dataTable styleClass="table" style="width: 39pc; padding-left: 0px; left: 0px; margin-left: 0px; text-align: center; clip: rect(auto, auto, auto, 0px); vertical-align: middle"
            onRowClick="onRowClick(this)"
            onRowMouseOver="this.style.backgroundColor='#F8F8F8'"
            onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
            cellpadding="0" cellspacing="0" id="record" rows="10" var="record" value="#{beanA.Lists}" >
            <a4j:support event="onRowClick" actionListener="#{beanA.rowSelected}"/>
            <f:facet name="header">
            <rich:columnGroup>
            <rich:column>
            <h:outputText value="#{msgs['paddress']}" />
            </rich:column>
            <rich:column>
            <h:outputText value="#{msgs['city']}" />
            </rich:column>
            </rich:columnGroup>
            </f:facet>
            <rich:columnGroup>
            <rich:column style="white-space: nowrap;" >
            <h:outputText value="#{record.primaryaddress}"></h:outputText>
            </rich:column>
            <rich:column>
            <h:outputText value="#{record.city}"></h:outputText>
            </rich:column>
            </rich:columnGroup>
            </rich:dataTable>
            </a4j:form>


            </f:view>




            ANd my bean beanA looks like





            ................................
            RowData rowData = new RowData();
            private UIDataTable table;

            public void rowSelected(ActionEvent event) {
            System.out.println("rowSelected");
            Integer currIndex = getTable().getRowIndex();
            List allData = (List) getTable().getValue();

            this.rowData = (RowData) allData.get(currIndex);
            System.out.println("@#@#@#@#@#@#@: ROW: "+ rowData.getPrimaryAddress()+" "+rowData.getCity()+" "+rowData.getZip());
            }


            public UIDataTable getTable() {
            return table;
            }


            public void setTable(UIDataTable table) {
            this.table = table;
            }



            Here the control is never invoking the rowSelected method.
            The statement "System.out.println("rowSelected");" is not getting executed on the row click.

            Whenever I am clicking on any row in the datatable, an error message "Error on Page" is displayed in the status bar of the Internet Explorer.


            Any help is highly appreciated.
            Thank you

            • 4. Re: Capturing the rowdata of a DataTable
              Ilya Shaikovsky Master

              1)you still have no binding to table. It's important to get clicked row.

              simple example of getting clicked row is
              http://livedemo.exadel.com/a4j-repeat/
              source is at
              http://webdownload.exadel.com/downloads/ajax4jsf/examples/a4j-repeat/a4j-repeat.zip

              2) Please explore the client error with some client debugger to get the more info.

              • 5. Re: Capturing the rowdata of a DataTable
                Yurii Kartsev Apprentice

                Good afternoon.

                I read some information here on the forum about how users try to make actions while clicking on a row in the DataTable. I tried to make it by myself using your suggestions and advices. But I've got an exception about illegal argument in binding param of the rich:dataTable. But what type should it be?

                I make it as:

                <rich:dataTable style="width:167px"
                 id="employeesDataTable"
                 rows="20"
                 binding="#{amBean.table}"
                 columnsWidth="98%,1%,1%"
                 onRowClick="this.style.backgroundColor='#F1F1F1'"
                 onRowMouseOver="this.style.backgroundColor='#B5CEFD'"
                 onRowMouseOut="this.style.backgroundColor='#{org.richfaces.SKIN.tableBackgroundColor}'"
                 cellpadding="0" cellspacing="0" value="#{amBean.employeeListMan.employees}"
                 var="item">
                
                 <a4j:support event="onRowClick" actionListener="#{amBean.rowSelected}"/>
                
                </rich:dataTable>
                
                ...


                And in managed bean:
                ...
                
                import org.richfaces.component.UIDataTable;
                
                ...
                
                private UIDataTable table;
                
                ...
                
                public UIDataTable getTable() { return table; }
                public void setTable(UIDataTable table) { this.table = table; }
                
                ...
                
                public void rowSelected(ActionEvent event)
                {
                 System.out.println("======>>>>>> rowSelected invoked");
                 Integer currIndex = getTable().getRowIndex();
                 List allData = (List) getTable().getValue();
                
                 Employee rowData = new Employee();
                 rowData = (Employee)allData.get(currIndex);
                 System.out.println("Data: "+ rowData.getFirstName()+" "+rowData.getLastName()+" "+rowData.getEmployeeId());
                }
                
                ...



                And after all this I have:
                javax.el.ELException: /index.xhtml @26,15 binding="#{amBean.table}": java.lang.IllegalArgumentException: argument type mismatch



                Can you give any advices to me please, what I'm doing wrong?


                Thank you very much in advance.

                • 6. Re: Capturing the rowdata of a DataTable
                  Ilya Shaikovsky Master

                   

                  <a4j:support event="onRowClick" actionListener="#{capitalsBean.actionListener}"/>
                  


                  private HtmlDataTable table = new HtmlDataTable();
                  
                  public void actionListener(ActionEvent event) {
                   System.out.println(getTable().getRowKey().toString() + "clicked");
                   }
                  


                  Works fine for me.

                  • 7. Re: Capturing the rowdata of a DataTable
                    Yurii Kartsev Apprentice

                     

                    "ilya_shaikovsky" wrote:

                    ...

                    Works fine for me.


                    Strange... I've changed UIDataTable to org.richfaces.component.html.HtmlDataTable and got the same exception. Then I made clean+rebuild and started getting this:
                    /index.xhtml @540,59 onRowMouseOver="this.style.backgroundColor='#B5CEFD'" object is not an instance of declaring class


                    I should notice that it's far away from the place in the code where my first dataTable for employees is. And I'm trying to control rowClick only in employees table. But in the line 540 and around there are:
                    533 <h:form id="relativesTab_dataTableForm">
                    534 <rich:dataTable
                    535 id="relativesDataTable"
                    536 onRowClick="this.style.backgroundColor='#F1F1F1'"
                    537 onRowMouseOver="this.style.backgroundColor='#B5CEFD'"
                    538 onRowMouseOut="this.style.backgroundColor='#{org.richfaces.SKIN.tableBackgroundColor}'"
                    539 cellpadding="0" cellspacing="0" style="width:100%"
                    540 value="#{amBean.employee.relativeList}" var="rudele">
                    
                     <rich:column>
                     <h:outputText value="#{rudele.relativeId}" />
                     </rich:column>
                    
                    ...



                    I removed all "onRowClick="this.style.backgroundColor='#F1F1F1'"" from my xhtml-file and made rebuild. The exception keeps appearing.

                    This exception only disappears when I remove "binding="#{amBean.table}"" and "<a4j:support event="onRowClick" actionListener="#{amBean.rowSelected}"/>" from my first dataTable for employees (its code is listed above).


                    What it could be? I use RF 3.1.0 with JBoss 4.2.0.GA.

                    Thank you very much.

                    • 8. Re: Capturing the rowdata of a DataTable
                      Ilya Shaikovsky Master

                      I'm using 3.1.1.. Can you try to update to check?

                      • 9. Re: Capturing the rowdata of a DataTable
                        Yurii Kartsev Apprentice

                         

                        "ilya_shaikovsky" wrote:
                        I'm using 3.1.1.. Can you try to update to check?


                        Sure! Thanks for your reply.

                        Updated to richfaces-ui-3.1.1-SNAPSHOT - the same exception:
                        /index.xhtml @540,59 onRowMouseOver="this.style.backgroundColor='#B5CEFD'" object is not an instance of declaring class


                        and it still only disappears when I remove "binding="#{amBean.table}"" and "<a4j:support event="onRowClick" actionListener="#{amBean.rowSelected}"/>" from my first dataTable for employees (its code is listed above).

                        • 10. Re: Capturing the rowdata of a DataTable
                          Yurii Kartsev Apprentice

                          By the way - the same is with richfaces-ui-3.2.0-SNAPSHOT...

                          Maybe I'm doing something wrong?

                          I have EAR, where are:

                          1. war - my webapp, where RF is used.
                          2. jar - my business logic with EJB. That's where my amBean is from.

                          I've copied three jars from RF to JBoss\server\default\lib\", added it from this location into BOTH of war and jar build classpaths, rebuild all the project, restarted the server and redeployed EAR.

                          Is it right?

                          • 11. Re: Capturing the rowdata of a DataTable
                            Ilya Shaikovsky Master

                            create a war file for me please. I'll write an answer here then.

                            • 12. Re: Capturing the rowdata of a DataTable
                              Yurii Kartsev Apprentice

                              Thanks for helping me, Ilya.

                              My EAR-file with jar and war inside was sent to your e-mail. Hope it helps to solve my problem.

                              Thank you again in advance.

                              • 13. Re: Capturing the rowdata of a DataTable
                                Yurii Kartsev Apprentice

                                Ilya, do you have any suggestions?

                                • 14. Re: Capturing the rowdata of a DataTable
                                  Maksim Kaszynski Apprentice

                                  I have strong feeling that JBoss AS caches some older copies of resources. I'll check. Ilya's already gone, tomorrow he'll give me your app war, I'll check.

                                  1 2 Previous Next