• 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

JSF2 Custom Component with conditional rendering

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've created a custom component called conditionalDisplay. It has an action (hide/display), comparison (equals or isNull), and value1/value2. Value1 and Value2 are compared if the comparison is 'equals' and if they are equal, the specific action should be performed. This is helpful when there is a little more complicated logic than normal and it provides a different interface than just adding the boolean result in the bean class.

My trouble is getting the children tags not to render. It has no problem rendering, but when the action is 'display', the comparison is 'equals', and the values don't match it still renders. It seems like using the setRendered method in the encodeBegin method should work, but it continues to render the children.

In the simple example below, when the Bean.client equals 'YYY' the div tag should display and that part works fine. However, when the client is anything else, say 'AAA', the div tag should not be rendered. I've followed the code through the debugger and found that it's setting the setRendered method to false, but it's still rendered. Do you know why it is still rendering or what I need to do in the logic so that it doesn't render?


ConditionalDisplayTag.java

UIComponentBaseTag.java


index.xhtml
 
Aj Jaro
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found out that I have to override getRendersChildren with a return of true and then I can choose to render everything from the encodeChildren method which I also need to override. Here are the two new methods I had to override and what they look like. I created a localRendered boolean field which I populate based on the logic previously given instead of calling the setRendered method.

Thanks!

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic