This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF2 Custom Component with conditional rendering

 
Aj Jaro
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • 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: 31
  • Mark post as helpful
  • send pies
  • 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!

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!