0

I have a Primeface xhtml page, in which one dropdown menu should be visible or not depending on wether on the value of Two radiobuttons on the page.

I have googled around on many similar questions, for example this Ajax render not working on SelectBooleanCheckbox but can't seem to get it to work. My code is

<p:fieldset id="Settings" legend="Settings" styleClass="pFieldSet_Template" style="margin-bottom: 5px;">
    <p:selectOneRadio id="showCars" value="#{settingsHandler.beanSelected.showCars}">
    <p:ajax event="change" render="carSelection"/>
        <f:selectItem itemLabel="Yes" itemValue="true" />
        <f:selectItem itemLabel="No" itemValue="false" />
    </p:selectOneRadio>
        <p:selectOneMenu id="carSelection" value="Mercedes" rendered="#{settingsHandler.beanSelected.showCars}">
            <f:selectItem itemLabel="Mercedes" itemValue="Mercedes" />
            <f:selectItem itemLabel="Volvo" itemValue="Volvo" />
            <f:selectItem itemLabel="Fiat" itemValue="Fiat" />
        </p:selectOneMenu>
</p:fieldset>

and I have corresponding getters and setters in the backing bean as follows:

private Boolean showCars = new Boolean(false);

@Column(name = "SHOWCARS", nullable=false, columnDefinition = "bit default 'true'")
public Boolean getShowCars() { return showCars; }
public void setShowCars(Boolean value) { showCars = value; }

Nothing really happens with the menu though when I click the radio buttons. Similar to what the link I wrote above suggested I tried wrapping it in another component that is always rendered, but that didn't help either. Code is:

<p:fieldset id="Settings" legend="Settings" styleClass="pFieldSet_Template" style="margin-bottom: 5px;">
    <p:selectOneRadio id="showCars" value="#{settingsHandler.beanSelected.showCars}">
    <p:ajax event="change" render="group"/>
        <f:selectItem itemLabel="Yes" itemValue="true" />
        <f:selectItem itemLabel="No" itemValue="false" />
    </p:selectOneRadio>
    <h:panelGroup id="group">
        <p:selectOneMenu id="carSelection" value="Mercedes" rendered="#{settingsHandler.beanSelected.showCars}">
            <f:selectItem itemLabel="Mercedes" itemValue="Mercedes" />
            <f:selectItem itemLabel="Volvo" itemValue="Volvo" />
            <f:selectItem itemLabel="Fiat" itemValue="Fiat" />
        </p:selectOneMenu>
    </h:panelGroup>
</p:fieldset>

I've also tried some other approaches laid out in questions/answers here on Stackoverflow, but I am a bit unsure about when to use execute, update and render and whether or not to use listeners. Thanks a lot

Mattias
  • 161
  • 1
  • 13

1 Answers1

2

You are using the wrong attribute. In p:ajax you should use the update attribute on your second approach (the first will not work). So:

<p:ajax update="group"/>

Note that the change event is default, so I've left that one out. For more information on the p:ajax tag, check the documentation.

For your first approach, please see Ajax update/render does not work on a component which has rendered attribute.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102