James Jefferies and ShedCode Ltd

The world of James and ShedCode

Why Has My JSF Button Stopped Working..

| Comments

I’ve asked this a number of times in the past, but I think I’ve finally found the answer!

Often with JSF you may have a command button wrapped in a div or subview rendered only in certain circumstances.

1
2
3
<f:subview id="show-the-button" rendered="#{managedBean.shouldButtonBeRendered}">
    <h:commandButton action="#{managedBean.doSomething}" value="Do Something" />
</f:subview>

Ok, you might have some extra mark up in there, id etc, but this is just to keep things simple for this example.

Now, for the button to be rendered, the value of managedBean.shouldButtonBeRendered should be true when the page is being rendered, then the button appears.

However, if between the page loading and the button being clicked, the value of managedBean.shouldButtonBeRendered changes, then the button action is ignored. Many hours of headaches would have been saved if I’d realised this sooner!

So, if you have a button which stops working under certain circumstances, check any rendering on the component or parent components!

More info can be found on the sun forums and on BalusC’s useful site

Comments