• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSF and Facelets question

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 102
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Kumar Saravanan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic