File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes JSF and Facelets question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF and Facelets question" Watch "JSF and Facelets question" New topic

JSF and Facelets question

Kumar Saravanan
Ranch Hand

Joined: Aug 25, 2004
Posts: 40

I am using facelets and JSF. I would like to know how to catch the value in UI (I mean in UI Facelets tag) and reference that variable from JSF code.

Here is my problem, I am having a getter method which executes a database query and return the collection of results.

I referred this getter method (getValue) in my datatable like this:

<h:dataTable var="items" value="#{myBean.value}" rendered="#{not empty myBean.value}">

In the above case, since I referred the "value" property 2 times, my getter method in Backing Bean is getting invoked 2 times (getValue).

I would like to avoid this repeated execution by execute the call and cache the result in faceletes tag and I can refer the variable from h:dataTable tag.

Can anyone suggest or advice me how to get catch the value in Facelets?

I tried in ui:param tag and it doesnt work. I tried c:set and the bean is not at all getting invoked.

Alim Atar
Ranch Hand

Joined: Oct 06, 2006
Posts: 102


If you want to avoid the second time execution of getValue then use some boolean variable and don't do any thing in that getValue.

boolean flag=true;
//Activity for 1st call

hope this will solve your problem



Kumar Saravanan
Ranch Hand

Joined: Aug 25, 2004
Posts: 40
Hey Alim,

thanks for your reply...code looks ugly if I start coding like that for each and every individual getter method...

like in jsp's you can catch them in local variable and iterate over them but in facelets how do you handle the same situation...

- Kumar
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

The problem with trying to cache is that the JSF and Facelets tags are implemented as JavaBeans and they're not allowed to preserve state for things like this since there'd be no way to easily track on a tag-by-tag basis - the same tag bean is being used for all usages of that tag. You'd have to write your own custom tag that tracked things somehow and did the call only once per field. Not impossible, but probably not worth it.

In my own experience, it's better to use booleans and other simple expressions on JSF EL anyway, so I recommend doing what Alim said.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: JSF and Facelets question
It's not a secret anymore!