jsf - Dynamic <ui:include src> depending on <ui:repeat var> doesn't include anything -
i new jsf , struggling dynamicaly rendering included pages. code looks this:
menubean
@viewscoped public class menubean implements serializable { private menuitem[] menuitems = new menuitem[] { new menuitem("page_1", "/page_1.xhtml"), new menuitem("page_2", "/page_2.xhtml"), }; private string selecteditemlabel; //... }
menuitem
public class menuitem implements serializable { private string label; private string page; //... }
index.xhtml
<ui:repeat var="menuitem" value="#{menubean.menuitems}"> <h:panelgroup rendered="#{menubean.selecteditemlabel eq menuitem.label}" layout="block"> <h:outputtext value="#{menubean.selecteditemlabel}" /> <ui:include src="#{menuitem.page}" /> </h:panelgroup> </ui:repeat>
the result 2 buttons rendered. whenever click button label inside conditionaly rendered panelgroup appears included page doesn't. if change 'menuitem1' var first ui:repeat works unpredictable. example if hardcode setselecteditemlabel parameter 'page_1' when click button_1 page_1 displayed if click button_2 page_2 (!?) displayed...
you're facing view build time vs view render time problem. same problem answered in detail in jstl in jsf2 facelets... makes sense? in answer, replace "jstl" "ui:include". point, <ui:repeat>
runs during view render time, while <ui:include>
has run during view build time before.
you'll understand solution replace <ui:repeat>
tag runs during view build time, such jstl <c:foreach>
.
note don't guarantee solve concrete functional requirement you've in mind. using jstl may have undesirable "side effects" (which explainable, understandable , workaroundable).
Comments
Post a Comment