问题描述
在我的场景中,我需要使用ajax从托管bean更改属性显示类型
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>
如果我在单选按钮中单击是",则属性(id = text1)将呈现为文本框,如果我单击否",则属性(id = text1)将呈现为标签.有可能吗?请引导我...
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 ...
推荐答案
是的!这个有可能!将您的h:inputText
和h: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.
这篇关于在JSF中从托管Bean更改属性显示类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!