1 2 Previous Next 16 Replies Latest reply on Feb 14, 2012 2:30 AM by Logan M

    Problem with events in a rich:dataTable

    Matthias Hinderkott Newbie

      Hello Community,

       

      for the next 3 months i will be involved with RichFaces 4.1 and JSF 2 my knlowledge about this subject is not good ..

      The last 3 Days i tried to make a jsf page using RF4.1 and now i having a problem. I would like to enter a method in a CDI Bean after doubleclicking in a row of my dataTable. After 2 hours i found a solution:

       

       

      <rich:dataTable value="#{dummy.textbausteine}" var="iterator" >
                              <f:facet name="header">
                                      <rich:column>Parameter:</rich:column>
                              </f:facet>
                              <rich:column>
                                  <h:outputText value="#{iterator}" style="font-family:Courier New;" />
                              </rich:column>
                              <a4j:ajax event="rowdblclick"  listener="#{dummy.doSth()}" />
                          </rich:dataTable>
      

       

      but... the Code i posted is surrounded by a CollapsablePanel and if i try to collapse, nothing happens in the view and on my Server i got a NullPointerExeption..

       

      14:18:32,529 Schwerwiegend [org.richfaces.log.Context] (http--127.0.0.1-8080-1) null: java.lang.NullPointerException

          at org.richfaces.renderkit.DataTableRenderer.doDecode(DataTableRenderer.java:111) [richfaces-components-ui-4.1.0.Final.jar:]

       

      Is there something wrong with my <ajax... > stuff or what could be the reason of that exeption ?

       

      I hope you can unterstand me cause my English is not well

       

      Regards from Germany

       

      Matthias

        • 1. Re: Problem with events in a rich:dataTable
          Matthias Hinderkott Newbie

          There is a second question, how can i get access on an Event on the CDI Bean

            <a4j:ajax event="rowdblclick"  listener="#{dummy.doSth()}" />

          and

          public void doSth(ActionEvent e)

           

          does not work...

           

          Best Regards

          Matthias

          • 2. Re: Problem with events in a rich:dataTable
            Christian Peter Expert

            It seems like a bug. A workaround for now could be setting the switchType to "client" in the collapsable panel. (then there won't be any posts on (de-)collapsing the panel.

             

            <rich:collapsiblePanel switchType="client">

                       

                            <rich:dataTable value="#{myMBean.allCustomers}" var="iterator" >

                                    <f:facet name="header">

                                            <rich:column>Parameter:</rich:column>

                                    </f:facet>

                                    <rich:column>

                                        <h:outputText value="#{iterator}" style="font-family:Courier New;" />

                                    </rich:column>

                            <a4j:ajax event="rowdblclick"  listener="#{myMBean.doSomething()}" />

                                </rich:dataTable>

                           

                           

                        </rich:collapsiblePanel>

            • 3. Re: Problem with events in a rich:dataTable
              Matthias Hinderkott Newbie

              Thanks Christian,

              your workaround works. Do i have to create a Ticket or something or this Bug is already known ?

               

              Can you tell me how it is possible to get acces to the event in my bean. After dblclicking i want to check wich row is clicked an i think i need the UIComponent isnt it ?

               

              Best Regards

               

              Matthias Hinderkott

              • 4. Re: Problem with events in a rich:dataTable
                Christian Peter Expert

                public void myListener(AjaxBehaviorEvent event){

                        System.out.println("event" + event);

                        System.out.println("XXXXXXXXXXXXX");

                        UIDataTable table = (UIDataTable) event.getSource();

                        AjaxBehavior behavior = (AjaxBehavior) event.getBehavior();

                       

                        System.out.println("table: " + table);

                        System.out.println("behavior: " + behavior);

                        System.out.println("data: " +behavior.getData());

                        System.out.println("row: " + table.getRowIndex());

                       

                    }

                 

                Facelet:

                ...

                <rich:dataTable id="tbl" value="#{myMBean.allCustomers}" var="iterator" rowKeyVar="rowk" >

                                        <f:facet name="header">

                                                <rich:column>Parameter:</rich:column>

                                        </f:facet>

                                        <rich:column>

                                            <h:outputText value="#{iterator}" style="font-family:Courier New;" />

                                        </rich:column>

                                    <a4j:ajax event="rowdblclick" data="#{iterator}" listener="#{myMBean.myListener}" />

                                </rich:dataTable>

                 

                 

                Maybe you'll find some usable values in the AjaxBehaviorEvent. "Row" returns the current index of the row.

                 

                More interesting is the DATA: it gives the actual selected Object! In my case it's the rows customer entity.

                • 5. Re: Problem with events in a rich:dataTable
                  Matthias Hinderkott Newbie

                  Hey Christian thanks for your great help!

                   

                  You say the intresting part is the getData, this method returns "null" on every row i select :/. Ist correct that the behavior class is from package

                  import org.ajax4jsf.component.behavior.AjaxBehavior; ?  You have an idea why getData returns null ?

                   

                  The getRowIndex or getRowData or getRowKey seams to work wrong with data scrollers :/ .

                  For example i have 10 Tupels in my dataTable i configured the table with rows="3" and my table got a data scroller

                   

                                 <f:facet name="footer">

                                      <rich:dataScroller id="scroller" for="txtListe" >

                                      </rich:dataScroller>

                                  </f:facet>

                              </rich:dataTable>

                   

                  so if i click on Page 2 row 2 it would be Index 4  (0,1,2 - 3,4,5 - 6,7,8) but it returns 1 Is that behavior correct ??

                   

                  Best Regards

                  Matthias

                  • 6. Re: Problem with events in a rich:dataTable
                    Matthias Hinderkott Newbie

                    Hm i found something but i dont think that this is the prefered ^^ can u tanke a look at this

                     

                    UIDataTable table = (UIDataTable) event.getSource();

                    SequenceRange range = (SequenceRange) table.getComponentState().getRange();

                    System.out.println(range.getFirstRow()+table.getRowIndex());

                    • 7. Re: Problem with events in a rich:dataTable
                      Christian Peter Expert

                      So, I've tried with your code snippets. But, strangely enough, it seems to work, but only on the first page. If I change the page with the datascroller and select a row on the new page, "data" still returns the objects from the first page! This could be also a bug or we are using it wrong. The rowIndex is still the same for every page.

                       

                      System.out.println(range.getFirstRow()+table.getRowIndex());

                      return the correct index in the table. But if you have clientside filtering / sorting, you'll have to keep that in mind, too.

                      • 8. Re: Problem with events in a rich:dataTable
                        Christian Peter Expert

                        I've got another workaround ;-) :

                         

                        <rich:dataTable id="tbl" value="#{myMBean.allCustomers}" var="iterator" rowKeyVar="rowk"

                                                        rows="5">

                                                <f:facet name="header">

                                                        <rich:column>Parameter:</rich:column>

                                                </f:facet>

                                                <rich:column>

                                                    <h:outputText value="#{iterator}" style="font-family:Courier New;" />

                                                    <a4j:commandLink value="select" action="#{myMBean.editCustomer(iterator)}"

                                                                     execute="@this"

                                                                     style="display:none !important;"/>

                                                </rich:column>

                                           

                                            <f:facet name="footer">

                                                <rich:dataScroller id="scroller" for="tbl" oncomplete="initRowSelect();">

                                            </rich:dataScroller>

                         

                                        </f:facet>

                                        </rich:dataTable>

                         

                        You'll recognize the hidden a4j:commandLink in the column. This one will execute the editCustomer(Customer c) method in the bean. This works and you'll get the currentrows customer.

                         

                        The link is intentionally hidden. But how to call it? Use jQuery and bind an dblclick event on each row!

                         

                        <script> 

                                           

                                           var initRowSelect = function (){

                                                    jQuery(".rf-dt-r").bind("dblclick", function(){

                                                        console.log(this);

                                                        jQuery(this).find("a:first").click();

                                                    });                     

                                                }

                                           jQuery(document).ready(function(){    

                                                initRowSelect();

                                            });

                                        </script>

                         

                        I think, you'll have to fix the selector  - especially if you have more than one table on one page.

                        1 of 1 people found this helpful
                        • 9. Re: Problem with events in a rich:dataTable
                          Matthias Hinderkott Newbie

                          Hey Christian,

                          thanks for this great idea im a complete newbee in jQuery but i got it.

                          I used the jQuery function of RichFaces and it works

                           

                          Here my code snippet:

                           

                           

                          <rich:dataTable value="#{dummy.myModel}" var="iterator"  rows="8" styleClass="stable">

                          .....

                          <rich:column style="width:500px">

                                           <h:outputText value="#{iterator.erlaeuterung}" />

                                           <a4j:commandLink value="select" action="#{dummy.doSthMoreMore(iterator)}"

                                                   execute="@this" style="display:none !important;" styleClass="hlp"/>

                          </rich:column>

                          .....

                          </rich:dataTable>

                          <rich:jQuery selector=".stable tbody tr" event="click" query="jQuery(this).find('.hlp')[0].click()"/>

                           

                          I think that way is much better than my old with calculating an id via (range.getFirstRow()+table.getRowIndex()); ^^

                           

                           

                          What do you think we shold create a BugReport or sth. for this both "Bugs" ?

                           

                          Best Regards

                          Matthias

                          • 10. Re: Problem with events in a rich:dataTable
                            Logan M Newbie

                            Hi,

                             

                            I confirm the first problem. I have resolved it by patching the org.richfaces.renderkit.DataTableRenderer class.

                            It happens when "decoding" Rich data table whereas there's no behavior event. In this case there's no request parameter named "javax.faces.behavior.event". So parameter value must be "null"-checked before testing it's starting by "row".

                             

                            I suspect it reproduce each time a rich data table is submitted whereas there's no behavior event. A possible work around can be to place a region around components in the form for excluding the table and provides a well-filled execute attribute on a4j:ajax (or a4j:command*).

                            CAUTION: I haven't tested this solution as the simple patch works fine.

                            • 11. Re: Problem with events in a rich:dataTable
                              F M Newbie

                              Hi,

                               

                              This error shows up as soon as there are a rich:dataTable with a4j:ajax attached in the page...

                              Example:

                              <rich:dataTable ...>

                                        <a4j:ajax event="rowclick" listener="..." />

                                        ...

                              </rich:dataTable>

                              <h:commandButton action="..." value="..." />

                               

                              A click on the button will show the error. This is quite a huge bug for me !

                              Is there already an issue filled ?

                               

                              Regards,

                              Florian Minjat

                              • 12. Re: Problem with events in a rich:dataTable
                                Logan M Newbie

                                Hi F M,

                                 

                                Have you try to replace your h:commandButton with a a4j:commandButton and filled the "execute" attribute in order to exclude your table from the restore view phase ?

                                 

                                 

                                Is there already an issue filled ?

                                 

                                I don't think so. At top of the topic you can see that there's no issue attach to this thread ...

                                • 13. Re: Problem with events in a rich:dataTable
                                  F M Newbie

                                  Hi,

                                  Yes it works with a4j:commandButton with execute=@this.

                                  But this is rather problematic on big pages with templates as the error isn't easily understandable !

                                  The normal h:commandButton should work, and it should be possible to also submit the table: we had with JSF1.2 the need to submit a table with input in the rows. I don't think it'll be possible with this error...

                                   

                                  Regards,

                                  Florian Minjat

                                  • 14. Re: Problem with events in a rich:dataTable
                                    Logan M Newbie

                                    As I mention in my first message, I have patched the org.richfaces.renderkit.DataTableRenderer class.

                                    On RF 4.1, it consits in adding null check on line 113. Like this :

                                    Map<String, String> parametersMap = context.getExternalContext().getRequestParameterMap();
                                     final String behaviorEvent = parametersMap.get(BEHAVIOR_EVENT_NAME);
                                    
                                    if (behaviorEvent == null || !behaviorEvent.startsWith(ROW)) {
                                      return;
                                    }
                                    

                                     

                                    I join the patched file.

                                     

                                    Just add it to the /WEB-INF/classes of your web application. Your container must take it prior to the JAR bundled one.

                                    1 2 Previous Next