File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

JSF and Facelets question

Kumar Saravanan
Ranch Hand

Joined: Aug 25, 2004
Posts: 40
Hi,

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}">
</h:dataTable>

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.

Thanks
Kumar
Alim Atar
Ranch Hand

Joined: Oct 06, 2006
Posts: 102

Hi,

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;
getValue()
{
if(flag)
{
//Activity for 1st call
flag=false;
}
else
{
flag=true;
}
}

hope this will solve your problem

Regards,
-Alim


Regards,
Alim

SCEA/OCMJEA Part1,SCBCD1.5,SCWCD1.4,SCJP1.4,SQL(Z007)
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...

Thanks,
- Kumar
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16103
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
GeeCON Prague 2014
 
subject: JSF and Facelets question