forms - How to use EL with <ui:repeat var> in id attribute of a JSF component -
i have following code:
<ui:repeat var="class2" value="#{bean.list}" varstatus="status"> <h:form id="#{class2.name}"> <h:outputtext value="#{class2.name}" /> </h:form> </ui:repeat>
however, when open page, errors follows:
component identifier must not zero-length string
but printed in <h:outputtext>
. how caused , how can solve it?
you can use el in id
attribute of jsf component, el variable has available during view build time, while jsf component tree built. however, <ui:repeat>
runs during view render time, while html output generated based on jsf component tree. <ui:repeat var>
not available during view build time , #{class2.name}
evaluates null
totally explains error got. works in <h:outputtext>
because runs during view render time.
if replace <ui:repeat>
<c:foreach>
, runs during view build time, it'll work intented. <c:foreach>
namely generate physically multiple <h:form>
components in jsf component tree each generate individually own html output (in contrary <ui:repeat>
, wherein same <h:form>
component been reused multiple times generate html output).
<c:foreach var="class2" items="#{bean.list}" varstatus="status"> <h:form id="#{class2.name}"> <h:outputtext value="#{class2.name}" /> </h:form> </c:foreach>
however, wonder why need that. there's no need dynamically assign component ids. jsf ensure uniqueness of id. below example,
<ui:repeat var="class2" value="#{bean.list}" varstatus="status"> <h:form id="form"> <h:outputtext value="#{class2.name}" /> </h:form> </ui:repeat>
will end in multiple forms each unique id, suffixed iteration index of <ui:repeat>
. if need use #{class2.name}
javascript/jquery purposes (you did state concrete functional requirement in question thought right solution, it's merely guessing), wrap in plain vanilla html element:
<ui:repeat var="class2" value="#{bean.list}" varstatus="status"> <div id="#{class2.name}"> <h:form id="form"> <h:outputtext value="#{class2.name}" /> </h:form> </div> </ui:repeat>
or set style class of jsf component, selectable via css selector:
<ui:repeat var="class2" value="#{bean.list}" varstatus="status"> <h:form id="form" styleclass="#{class2.name}"> <h:outputtext value="#{class2.name}" /> </h:form> </ui:repeat>
Comments
Post a Comment