there are already a lot of questions concerning the usage of:
- EL in attributes (How to use EL with <ui:repeat var> in id attribute of a JSF component)
- JSTL in Facelets (JSTL in JSF2 Facelets... makes sense?)
- view build time (What's the view build time?)
My question should address the general usage of an EL expression in the id attribute of a JSF component.
Assume we have the following example code (the usefulness of this code should not be questioned):
<h:form id="#{bean.property}">
<h:outputText value="#{bean.property}" />
</h:form>
Now I have the following questions:
- Is it okay to use an EL expression in the id attribute of
h:form
or other JSF components? - What are the things to keep in mind if one uses EL expressions in the id attribute?
- The id attribute of a JSF component has to be available at view build time. A deferred EL expressions, like above, is evaluated when the attribute is accessed. Consequently, if you have an EL expression in id attribute the result of the EL expression is available at view build time?
- I read that an EL expression can be used in attributes of type
javax.el.ValueExpression
, but the id is often of typeString
(https://coderanch.com/t/550270/java/null-variable-id-attribute). Consequently you can only use EL expressions in id attribute, if the expression evaluates to a String?
If you google for "EL expression in id attribute", there are people stating you cannot use EL expressions in id attribute, but the above example code works totally fine. This question is mainly intended for a discussion about the recommendability of the usage of EL expressions in id attribute.
Thanks for your answers!