0

In my scenario i need to change attribute display type from managed bean using ajax

<h:inputText id="text1" value="#{managedBean.value}" />
<h:selectOneRadio value="#{managedBean.option}">
    <f:selectItem itemValue="Yes" itemLabel="Yes" />
    <f:selectItem itemValue="No" itemLabel="No" />
    <f:ajax listener="#{managedBean.changeAttrDisplayType}" event="click" render="text1"/>
</h:selectOneRadio>

If i click yes in the radio button,then attribute(id=text1) will render as textbox and if i click No then attribute (id=text1) will be render as label. Is it possible ?Please Guide me ...

1 Answers1

2

Yes! this is possible! put your h:inputText and h:outputLabel in a h:panelGroup and in the ajax event rerender the h:panelGroup. Put the condition of which one you want to render in the respective rendered attribute like bellow:

            <h:panelGroup id="changingPanel">
                <h:outputLabel id="id1"
                              rendered="#{managedBean.option == 'Yes'}"
                              value="This is label"/>
                <h:inputText id="id2" value="#{managedBean.input}"
                              rendered="#{managedBean.option == 'No'}" />
            </h:panelGroup>

            <h:selectOneRadio value="#{managedBean.option}">
                <f:selectItem itemValue="Yes" itemLabel="Yes" />
                <f:selectItem itemValue="No" itemLabel="No" />
                <f:ajax event="click" render="changingPanel"/>
            </h:selectOneRadio>

Assumed that, you want to display outputLabel when "Yes" is selected and inputText when "No" is selected.

Sazzadur Rahaman
  • 6,938
  • 1
  • 30
  • 52
  • @Luiggi: Actually, the listener is unnecessary for the job as demonstrated here (the `event` attribute also, but that aside). – BalusC Jun 11 '13 at 18:18