File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes JSF tree component getting rendered before action method call (richfaces) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF tree component getting rendered before action method call (richfaces)" Watch "JSF tree component getting rendered before action method call (richfaces)" New topic
Author

JSF tree component getting rendered before action method call (richfaces)

Pritamjeet Sarangi
Greenhorn

Joined: Jul 05, 2011
Posts: 5
Hi,

I have an issue with JSF rendering. I am using richfaces 3.3 and spring.
I have a parent screen where we can select rows and then clieck on a a4j:command button.
This in turn opens a modal panel and shows some detail. The modal panel has a data table which is rendered by using the binding attribute as the details in this table are dynamic.

My issue here is the required data never comes up in the modal panel data table in the first button click. When I click the button second time then I can view the data.
I tried to debug, and found that the data table setter method is called first (meaning the model tree is getting renedered) before the action method is called (which actually updated the binding attribute).

How can I force the flow to call the action method first before rendering the jsf tree component?

Please suggest any solution for this.

TIA
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

Your problem is that the modal panel "show" function does exactly what its name says and no more. It does not build and show a panel, it only shows it. The panel was built when the page was loaded, and the show/hide functions only affect whether it is visible or not.

So what you need to do is a partial page update that brings the desired values into the panel. I don't have the details, but they should go something like this:

1. Define a commandButton or commandLink on the row you want to pop up for.

2. Define a backing bean property that is itself a bean that contains the row item values. This can be the actual tableModel row item. However, you CANNOT directly reference the table row in your modal panel, since the rendering of the rows is done at a different time and place and the modal panel has no access to the "current row" directly.

3. Here's where the magic occurs.

a. Define an action method on the control in #1. This action will take the dataTable model's current row and assign its values to the property in #2 where the modal panel can then reference it.

b. Tell the control #1 to reRender the contents of the modal panel.

c. Place the JavaScript that makes the panel visible (show) in the "oncomplete=" property of control #1.

If I haven't missed anything, that should do it. The action should fire, the modal panel's contents should update, and then the panel should pop up.


Customer surveys are for companies who didn't pay proper attention to begin with.
Pritamjeet Sarangi
Greenhorn

Joined: Jul 05, 2011
Posts: 5
Thanks Tim for the reply.
We have the similar changes as suggested by you, but still the issue persists.
Following is the case.
I have a screen where data is displyayed, each row having a check box.
I can select one or more rows and click on a button (this button is part of the tool bar).
So, this button has the action method, where I am retreiving the selected records, updating the backing bean property for the Modal Panel and then in the oncomplete of the button I have called the javascript to show the Modal panel. We also have added the rerender attribute for rendering the contents of the Modal Panel.

The thing here is the content of Modal panel is a dynamic tables being populated by using the binding attribute.

Please suggest if there are any other options. Let me know if you need more details.

Thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

The fact that the table in the modal panel is dynamic and bound doesn't change things. However, you do have to invoke reRender properly (make sure you capitalize reRender correctly!). Also, it can be a little tricky in some cases to re-render hidden components. Sometimes it works better to re-render a parent.

A very likely suspect, however, is that you may not be providing the proper ID to reRender. The modal panel should be an independent form outside of the form containing the non-panel table, since forms cannot be nested. So to be able to locate the table inside the form, you may need to either provide a more complete ID (reRender="form1:popupPanel:table1") or use the RichFaces findComponent() EL method to resolve the true ID of the table that needs to be re-rendered.
Pritamjeet Sarangi
Greenhorn

Joined: Jul 05, 2011
Posts: 5
Thanks Tim for the reply,

The data was getting re-rendered with the change suggested but the column header was not getting refreshed. So, we changed the dynamic table to fixed table.

That solved our issue.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF tree component getting rendered before action method call (richfaces)