Change Attribute Display Type from Managed Bean in JSF

牧云@^-^@ 提交于 2019-12-25 16:42:02

问题


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:


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.



来源:https://stackoverflow.com/questions/17041064/change-attribute-display-type-from-managed-bean-in-jsf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!