4 Replies Latest reply: Oct 26, 2011 7:46 AM by Hauke Gulich RSS

Richfaces 4 datatable rowclick is not hitting the listener method

Hauke Gulich Newbie

Hello,

 

I wrote and read several threads regarding this issue but I can't get that to work.

 

Can somebody give me a complete example, on how to make this work-a-round with a4j:jsfunction?

 

What I have so far is

 

 

<rich:dataTable value="#{control.lightList}" rowKeyVar="rowKey" var="light" width="100%" id="lightList" columns="5" columnClasses="lightTableWidthNarrow,lightTableWidthLarge,lightTableWidthLarge,lightTableWidthNarrow,lightTableWidthLarge">
             
    <a4j:jsFunction name="selectRow" actionListener="#{control.actionListener}" render="lightList">
            // do I have to pass some parameter with the row key value in order the read the clicked row key on my backing bean? If yes, how?                      
     </a4j:jsFunction>

      <rich:column>
           <h:graphicImage value="graphics/#{light['icon'].stringValue}" width="20"></h:graphicImage>
      </rich:column>

 

 

This is what I understood from this thread

 

http://community.jboss.org/message/598232#598232

 

regarding the same problem, but where do I have to put the event = "rowclick" ? Do I have to add an extra a4j:ajax tag around the a4j:jsFunction tag?

 

 

I am getting kind of frustrated because I don't get any answers and this kind of easy behavoir seems to be so complicated to realize that I am not sure if this framework is the right one. On richfaces 3 everything worked so good and even this is working with primefaces, but I don't want to turn my back on richfaces.

 

So please give me and other users with this kind of problem an easy example.

 

Thanks for your help and many greeting,

Hauke

  • 1. Re: Richfaces 4 datatable rowclick is not hitting the listener method
    Brendan Healey Master

    Hello Hauke, I think you need to add rich:dataTable var="light" onrowclick="selectRow('#{light.id}')", then

    your jsFunction needs to be like this:

     

    <a4j:jsFunction name="selectRow" actionListener="#{userBean.myListener" ...>

      <a4j:param name="currentRow" assignTo="#{userBean.selectedRowId}"/>

    </a4j:jsFunction>

     

    I don't know if it's ok to have the jsFunction nested inside the datatable, or if it needs to be outside, but

    it's easily tested.

     

    One thing to consider is whether you can use the M2 release, I am using that and row selection works in

    the normal way without the need for a4j:jsFunction.

     

    Regards,

    Brendan.

  • 2. Re: Richfaces 4 datatable rowclick is not hitting the listener method
    Hauke Gulich Newbie

    Hello Brendan,

     

    thanks for your answer. This helped me a lot and I figured it out.

     

    So what I did is to create a a4j:jsFunction tag outside (before) the rich:datatable. I think it can be anywhere, but I am not sure (I didn't try that).

    And on my rich:dataTable I added the attribute onrowclick and called the js function and pass them the rowkey or in my example the database ID of the corresponding row.

     

     

            <a4j:jsFunction name="selectLight" render="lightList" actionListener="#{control.actionListener}>
                <a4j:param name="param1" assignTo="#{control.xxx}"  />                  
            </a4j:jsFunction>
        
            <rich:dataTable value="#{control.lightList}" onrowclick="selectLight(#{rowKey})" rowKeyVar="rowKey" var="light" width="100%" id="lightList" columns="5" columnClasses="lightTableWidthNarrow,lightTableWidthLarge,lightTableWidthLarge,lightTableWidthNarrow,lightTableWidthLarge">
    

     

     

    The only problem seems to be right now, that the listener will be executed before the setter of xxx is called.

     

    For the sake of completeness I will print out the listener method as well

     

    public void actionListener(ActionEvent event){       System.out.println("VALUE OF XXX : " + xxx);}

     

     

    So one way to do a work-a-round here is the execute the business logic on server side to start them from the setter-method. This isn't very nice, but I will play around with that and come back if I figure out a better way. Maybe somebody has an idea?

     

    Maybe one way is with the ActionEvent object. Can I read the param value?

     

    Many greetings,

    Hauke

  • 3. Re: Richfaces 4 datatable rowclick is not hitting the listener method
    Brendan Healey Master

    Hauke, I already came across this problem. You need to use a4j:jsFunction action=, instead of

    actionListener=. I logged this here: https://issues.jboss.org/browse/RF-11446, perhaps add a vote

    if you'd like it corrected. As there is a workaround I don't know how much priority it will receive,

    it's just that finding out that there's a workaround can take a days work.

     

    Regards,

    Brendan.

  • 4. Re: Richfaces 4 datatable rowclick is not hitting the listener method
    Hauke Gulich Newbie

    Brendan,

     

    thanks for your help. Now it works but this is really strange and now really consequent.

    But anyway, this way it is working.

     

    Thanks,

    Hauke