Expression Language (EL) not working for id tag

Wondering why assigning a variable to an id tag does not work, although you can assign the variable to the for or value attribute without any problems?

The reason is that expression evaluation on the id attribute is explicitly disallowed (maybe for some security reasons). So you cannot generate dynamic ids using EL as in the code below.

<ui:repeat value="#{bean.elements}" var="e">							  	
<h:outputLabel for="#{}" value="#{e.label}"/>
<h:inputText id="#{}" value="#{bean&#91;e.variable&#93;}"/>		            			

You will likely get an Illegal Argument Exception.

But you can simply write the code as follows, JSF will automatically assign an iteration number to the id myid and the final id will be the same for outputLabel and inputText.

<ui:repeat value="#{bean.elements}" var="e">							  	
<h:outputLabel for="myid" value="#{e.label}"/>
<h:inputText id="myid" value="#{bean&#91;e.variable&#93;}"/>		            			

You can verify this by checking the ids in FireBug.

Firebug results:

<label for="bean:j_id53:0:myid" ... />
<input id="bean:j_id53:0:myid" ... />
<label for="bean:j_id53:1:myid" ... />
<input id="bean:j_id53:1:myid" ... />
<label for="bean:j_id53:2:myid" ... />
<input id="bean:j_id53:2:myid" ... />
Dieser Beitrag wurde unter IT abgelegt und mit , , , , , verschlagwortet. Setze ein Lesezeichen auf den Permalink.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.