I'm pretty new to JSF / Facelets and trying to understand where best placed to put logic when deciding whether to render content within a ui:repeat component.
In my backing bean I have a list of messages each one containing a date. I want to print all messages but only render the date when it changes.
Currently I have something like below where the backing bean getter method determines whether or not to render the message date based on logic and setting state within the backing bean.
<ui:repeat value="#{bean.orderedMessages}" var="message" varStatus="messageLoop">
<h:panelGroup rendered="#{bean.isDateRendered(messageLoop.index)}">
#{message.formattedDate}
</h:panelGroup>
// some other stuff for each message
</ui:repeat>
This is buggy and horrible since JSF calls the getter method many times before actually rendering which adds further complexity to the getter method, the code has nothing to do with the anything other than whether something should be rendered or not which should really be in the UI and the getter method has a whole bunch of nasty logic in it whereas I would prefer a simple property to be returned.
I believe the UI has to somehow store the state of the last rendered date and compare that against the one it is about to render but I'm not sure whether that's correct.
I don't believe this is an uncommon problem. Does anyone know if there is a more elegant solution to solving this?