I want to loop over a number of "guests" and insert an id dynanimally
<ui:repeat value="#{guestList}" var="guest">
<p:inputText id="firstname_#{guest.uniqueID}" value="" label="Firstname" />
<p:message for="firstname_#{guest.uniqueID}" />
</ui:repeat>
The problem is, that the <p:message />
cannot resolve firstname_#{guest.uniqueID}
javax.faces.FacesException - Cannot find component "firstname_1" in view. at org.primefaces.component.message.MessageRenderer.encodeEnd(MessageRenderer.java:41)
It works without any problems if I write a constant inside the loop, and also I am sure that the variable can be resolved, as I can output it in that loop.
How can I instruct jsf or primefaces to resolve this variable?
You cannot use EL expressions in the id
attribute.
But you don't need to care for the uniqueness of your ids in ui:repeat. JSF does it for you. Just give your input field a "fixed" id and reference it in your p:message
:
<ui:repeat value="#{guestList}" var="guest">
<p:inputText id="firstname" value="" label="Firstname" />
<p:message for="firstname" />
</ui:repeat>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With