<ui:param and caching
Asked Answered
B

1

6

I have the following thing:

<ui:param name="randomVideo" value="#{bean.randomVideo}" />
<a href="#{randomVideo.link}">#{randomVideo.text}</a&></pre>

Because <ui:param> does not cache the variable, Bean.getRandomVideo() is called twice, and the worst part is that the .text and .link are from different videos. I have already tried <c:set and <f:param. They both do not set the variable, maybe because I'm with facelets (JSF2).

Any ideas?

Barsac answered 21/7, 2011 at 7:42 Comment(0)
P
2

Getters are supposed to be real getters, not containing any logic. So:

  • make your bean @RequestScoped
  • initialize the randomVideo field in @PostConstruct
  • let the getter only retrieve the randomVideo field of the bean.
Pasha answered 21/7, 2011 at 8:0 Comment(1)
Actually, I had to move my logic to a new bean, but if we disregard the extra code this solution was better than mine - put the random video in the request and check whether there was anything in the request in the getter)Barsac

© 2022 - 2024 — McMap. All rights reserved.