0

there are already a lot of questions concerning the usage of:

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 type String (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!

Christoph W.
  • 958
  • 2
  • 10
  • 24
  • _" 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?"_ Try... If it works, you have answers to most of the other questions as well. – Kukeltje Jan 13 '17 at 13:48
  • @Kukeltje Indeed it works, but my questions are intended for a discussion about the recommendability. – Christoph W. Jan 13 '17 at 13:56
  • Question 1: If it was not ok, they would most likely have prevented it Question 2/3: That it does not work in iterating jsf components since that is view render time (jstl should work irrc), Question 4: No iddea, 'try'? More basic question from me would be: why do you want this? I never had the need to do things like this – Kukeltje Jan 13 '17 at 14:48

1 Answers1

-1

No, never do it, id should not be dynamic . QA team will reject it.

Armen Arzumanyan
  • 1,939
  • 3
  • 30
  • 56