Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically assigning IDs to tags using an EL variable

Tags:

jsf

el

primefaces

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?

like image 432
devsnd Avatar asked Mar 19 '12 12:03

devsnd


1 Answers

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>
like image 160
Matt Handy Avatar answered Sep 28 '22 13:09

Matt Handy