使用EL变量为标签动态分配ID [英] Dynamically assigning IDs to tags using an EL variable
问题描述
我想遍历多个来宾并动态插入ID
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>
问题是,< p:message />
无法解析 firstname _#{guest.uniqueID}
javax.faces.FacesException-在视图中找不到组件 firstname_1。 org.primefaces.component.message.MessageRenderer.encodeEnd(MessageRenderer.java:41)上的
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.
我该如何指示jsf或primefaces来解决此变量?
How can I instruct jsf or primefaces to resolve this variable?
推荐答案
您不能在 id $中使用EL表达式c $ c>属性。
但是您不需要关心ui:repeat中ID的唯一性。 JSF为您做到了。只需给您的输入字段一个固定 ID,并在您的 p:message
:
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>
这篇关于使用EL变量为标签动态分配ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!