Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force the build phase in a JSF 1.2 page using JSTL?

I am making use of JSTL tags in my JSF application. With certain actions, I need the component tree to be rebuilt as if it was an initial build. My current symptoms are incorrect object to component associations, duplicate ids, and other issues with stale components. This is using a c:foreach (cannot use a repeat tag, see example link) tag which is used in the build phase.

My understanding is that it is possible to force a rebuild, but I haven't been able to find where or how that occurs. I am open to solutions that start on the client or in the server.

For an example of the code I am using refer to this page on dynamic tabs in Richfaces. http://in.relation.to/Bloggers/UsingDynamicallyCreatedRichFacesTabPanelForSearchResults

Note: Using ui:repeat or a4j:repeat is not feasible. See the example page for details.

Other Note: The app beans are session scoped and the data in them needs to be, just not the component tree state.

Update This question is directly to the issue raised in this article and the first comment. I didn't know how to actually do the workaround in the first comment and the accepted answer led me to it.

like image 360
Adam Avatar asked Oct 11 '22 19:10

Adam


1 Answers

I don't think stale components are the issue. The duplicate IDs especially are a side effect of using the <c:forEach> tag. This is because <c:forEach> will add any child componenets to the component tree multiple times and each time it will attempt to use the same ID (unlike <ui:repeat>). This obviously results in duplicate IDs (you will notice in the example you linked to they did not specify any IDs within the <c:forEach> tags).

I'm not sure what they mean by the 'view build phase'. If you look at the JSF documentation, you will see that there is no such phase. In any case, when you use <ui:repeat>, as long as the AJAX call you use to perform the search re-renders the rich:tabPanel then it should work.

The reason they cited for <ui:repeat> not working was:

You could not use repeat components(neither ui:repeat nor a4j:repeat) for that because they work during page render time and do not create components in JSF tree but just iterate the same instance.

And in their example they used:

...
<a4j:commandButton action="#{capitalsBean.search}" value="Search" reRender="output" id="search"/>
...
<a4j:outputPanel id="output">
    <rich:tabPanel id="tapPanel" width="700" rendered="#{not empty capitalsBean.foundCapitals}">
        <c:forEach items="#{capitalsBean.foundCapitals}" var="cap">
        ...

If you are specifying reRender="output" on the search's a4j:commandButton how does 'page render time' not occur for tapPanel??

In summary, use <ui:repeat>, JSTL and JSF are typically not very good bedfellows.

EDIT: I should have done this first since I don't have experience with rich:tabPanel but <ui:repeat>, it appears, cannot be used with rich:tabPanel (but not for the reasons stated in the example you link to, hence my confusion). Don't use <c:forEach> though, use a component binding to the rich:tabPanel.

like image 165
Gyan aka Gary Buyn Avatar answered Nov 16 '22 19:11

Gyan aka Gary Buyn