1

I've got a checkbox with an ajax event, upon changing the value, the checkbox will change a boolean in my bean. This ajax event should also render a panelGrid with attribute rendered="#{!*the bean's boolean*}". This means that the panelGrid should be visible when unchecked, and visible when checked. The boolean will be set to false by default (by @PostConstruct).

This is the corresponding code snippet:

<h:selectBooleanCheckbox id="useAddress" value="#{handleOrder.useAddress}">
    <f:ajax event="change" execute="useAddress" render="outputAddress" />
</h:selectBooleanCheckbox>

<h:panelGrid id="outputAddress" rendered="#{!handleOrder.useAddress}" columns="2" width="468px">
(...)

This snippet is surrounded by a <h:form /> tag. My getUseAddress() and setUseAddress() will be executed upon valuechange.

My question is, why is my panelGrid always visible?

Menno
  • 12,175
  • 14
  • 56
  • 88
  • 2
    Related: http://stackoverflow.com/questions/9010734/why-do-i-need-to-nest-a-component-with-rendered-some-in-another-component-w – BalusC Nov 22 '12 at 20:21

1 Answers1

3

Don't point with f:ajax on elements that got rendered attribute , cause when those elements wont be rendered it would be impossible for f:ajax to find them.

f:ajax must point on element that is present in the generated HTML DOM tree and when the rendered attribute of some JSF element equals false that element wont be even present in the HTML DOM tree

Change your code into this

<h:selectBooleanCheckbox id="useAddress" value="#{handleOrder.useAddress}">
    <f:ajax event="change" render="outputAddressWrapper" />
</h:selectBooleanCheckbox>

no need for the execute="useAddress" cause the default of execute is @this anyway

<h:panelGroup id="outputAddressWrapper">
    <h:panelGrid id="outputAddress" rendered="#{!handleOrder.useAddress} columns="2" width="468px">
        ...

You say that your panelGrid always visible , what is the scope of your bean ? Make it at least @ViewScoped

Daniel
  • 36,833
  • 10
  • 119
  • 200
  • This would lead to the problem you're describing, I think you mean the id of `ajax render` should be on the outer panel and the rendered attribute on the inner panel, right? – Menno Nov 22 '12 at 20:08