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

左心房为你撑大大i 提交于 2019-12-13 13:07:17

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/6298189/how-to-force-the-build-phase-in-a-jsf-1-2-page-using-jstl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!