SCJP 1.5
Dolphins are grey, but they dream in colour.
Cor Takken wrote:I am a firm believer in separating the presentation layer from the calculation layer. (As an aside: I acknowledge that there are more official terms for these principles, however for the sake of argument I will use these terms). In that believe I have a bit of a problem having for-loops, if-constructions etc. in the presentation layer. This makes the presentation layer no longer pure presentation but now also contains some form calculation and that has a risk of creap (pun intended) of business logic in the presentation layer. However, this I have noticed in the field that this creep is commonplace in JSF and I (will have to) accept the fact that the presentation layer in JSF does contain some programming logic.
You are right to be cautious about using logic in Facelet pages. In fact, I have been touting the complete absence of scriptlets in Facelets as one of its selling points. There are still a few corner cases that remain unresolved in using JSTL conditionals or iterators in Facelet pages, mostly revolving around state that changes between requests. As far as patterns or practices to refactor an existing occurrence of the use of conditionals and iterators I do have some suggestions.
Let's take conditionals and iterators separately. First, conditionals. The most common use of conditionals is to show/hide portions of the page. This usage is generally safe, especially when you value bind to the view scope.
Next on to iterators. If at all possible, use ui:repeat instead of c:forEach. ui:repeat is backed by an actual JSF component, while c:forEach is a tag handler. Because ui:repeat is a JSF component, it does a better job of managing its state.
If anyone else has something to share on this, please do!
Thanks for your interest.
Ed
SCJP 1.5
Dolphins are grey, but they dream in colour.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.