且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在JSF中从托管Bean更改属性显示类型

更新时间:2021-10-13 02:23:11

是的!这个有可能!将您的h:inputTexth:outputLabel放在h:panelGroup中,并在ajax事件中重新呈现h:panelGroup.将要渲染的条件放在相应的rendered属性中,例如波纹管:

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>

假定,您要在选择是" 时显示outputLabel,并在选择否" 时显示inputText.

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