2

I am trying to display a menu if a radiobutton is selected. I'm using the rendered attribute for this purpose.

Model:

private int type; // +getter+setter

View:

<h:selectOneRadio value="#{bean.type}">
    <f:selectItem itemLabel="A" itemValue="1"/>
    <f:selectItem itemLabel="B" itemValue="2"/>
</h:selectOneRadio>
<h:form id="formMention" rendered="#{bean.type == 1}">
    <h:selectOneMenu ...>
        <f:selectItems ... />
    </h:selectOneMenu>
</h:form>

Nothing shows when I check A. How can I achieve this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

1

Normally, you'd grab ajax for this, but as you're apparently on dead JSF 1.x, which lacks ajax fanciness, you're resorted to "plain" HTML/JS as long as you don't want to introduce an ajax capable component library. One of the ways is just submitting the form outright on click of the radio button.

<h:form>
    <h:selectOneRadio value="#{bean.type}" onclick="this.form.submit()">
        <f:selectItem itemLabel="A" itemValue="1"/>
        <f:selectItem itemLabel="B" itemValue="2"/>
    </h:selectOneRadio>
</h:form>
<h:form id="formMention">
    <h:selectOneMenu ... rendered="#{bean.type == 1}">
        <f:selectItems ... />
    </h:selectOneMenu>
</h:form>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you for your answer. I tried this code and the page doesn't show at all. I noticed that the problem is with the f:ajax. could this be related the the version of JSF I'm using. ( I am using 1.2 ) ? – user4567214 Feb 16 '15 at 10:58
  • Indeed. Nobody would expect that one would be using JSF 1.x these days as it has more than 5 years ago been upgraded to JSF 2.0 and is EOL'ed for three years. So, you'd better always explicitly specify the JSF version being used in the question. I'll update the answer. – BalusC Feb 16 '15 at 11:04