1

What happens with EL statements in a view build time in c:forEach loop.

<c:forEach var="v" values="#{bean.values}">
    <p:inputText value="#{v.name}" />
</c:forEach>

class Bean {
   public List<Pojo> getValues();
}

class Pojo {
   public void setName (String);
   public String getName();
}

How will be this code evaluated for render? To:

 <p:inputText value="John Smith">

or

 <p:inputText value="#{pojo.name}" >
John N
  • 844
  • 4
  • 12
  • 20

1 Answers1

5

For UI components, only id and binding attributes are immediately evaluated during view build time. All other attribtues are deferred. I.e. they will get an instance of ValueExpression (or MethodExpression) instead of the immediately evaluated value. The ValueExpression is re-evaluated on every individual getValue()/setValue() call.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you! If I understand your answer correctly, the reference for each object in a collection will be saved in `ValueExpression` (or somewhere) and then EL will be reevaluated in render phase. – John N Sep 14 '13 at 19:58
  • Nope, it's the EL expression itself (in flavor of `String` with exact value `#{pojo.name}`) which is saved. It's re-executed on every `getValue()`/`setValue()` call. – BalusC Sep 14 '13 at 20:05
  • Ok, I understand that EL expression will be saved. But how the EL expression know for which object (in my example Pojo-class) to call the getter/setter. The reference to object should be saved somewhere. Is it saved in `ELContext` parameter of `getValue() / setValue()` ? Or from your comment the evaluated String-value will be saved ? – John N Sep 14 '13 at 20:13
  • Each iteration has its own EL context, indeed. In case of Mojarra, it's `com.sun.facelets.tag.jstl.core.ForEachFaceletContext` – BalusC Sep 14 '13 at 20:17