views:

266

answers:

2

Hello,

I am currently trying to dynamically add a new component to the JSF component tree during an ajax request.

In fact I add a child to the UIViewRoot component in my AjaxBehaviorListener which is fired on server side during the ajax request process.

The issue is that the new component is not rendered. It seems that this component is not taken into account in the render response phase.

Could you help me on this issue ?

Regards,

Guillaume

+1  A: 

Instead of trying to add the component dynamically during the ajax request, try defining the component upfront, and setting it's rendered tag to false. The contents of the component can then be populated with the ajax request, and the rendered attribute flipped to display the attribute.

Brian Leathem
Actually, how would you change component's attribute (or some property) in order to render it during the AJAX request? Would you use a backing bean?
Tuukka Mustonen
You just want the evaluation of some EL to change from false to true. This could be a backing bean boolean property, or any arbitrarily complex bit of EL (Expression Language)
Brian Leathem
+1  A: 

This solution works in case of you know before the ajax request the component to add. But if you are not able to know which component to add, it does not work.

I maybe found a solution :

My solution is to implement my custom PartialViewContext and use the method startInsertAfter or startInsertBefore of the PartialResponseWriter.

It is working, but you have to put the component added as transient. (uiComponent.setTransient(Boolean.TRUE);)

Regards,

Guillaume

Guillaume