我有下一个代码:
<h:form id="form" >
<h:panelGrid >
<p:inputText placeholder="Name" value="#{controladorGestionGrados.otherValue}" />
<p:selectOneMenu value="#{controladorGestionGrados.value}" >
<f:selectItem itemValue="A" itemLabel="A" />
<f:selectItem itemValue="B" itemLabel="B" />
<f:selectItem itemValue="C" itemLabel="C" />
<p:ajax update=":form" />
</p:selectOneMenu>
<p:outputLabel id="someText"
value="Some text"
rendered="#{controladorGestionGrados.value eq 'C'}" />
</h:panelGrid>
</h:form>
首先:我在inputText中写了任何东西。 第二:我选择选项C.
之后,输出标签&#34;一些文字&#34;显示,但重置inputText。
如何更改&#34; selectOneMenu&#34;的价值?没有重新启动&#34; inputText&#34;?
我试过了:
<p:ajax update="someText" />
但有效的输入文本不会重置,但outLabel不会显示。
答案 0 :(得分:2)
包裹你的<p:outputLabel>
<p:outputLabel id="someText" value="Some text" rendered="#{controladorGestionGrados.value eq 'C'}" />
持有人<p:outputPanel>
像这样:
<p:outputPanel id="someTextPanel">
<p:outputLabel id="someTextLabel" value="Some text" rendered="#{controladorGestionGrados.value eq 'C'}" />
</p:outputPanel>
使用
更新持有者组件(<p:outputPanel>
)
<p:ajax update="someTextPanel" />
因此整个代码应该是这样的:
<h:form id="form" >
<h:panelGrid >
<p:inputText placeholder="Name" value="#{controladorGestionGrados.otherValue}" />
<p:selectOneMenu value="#{controladorGestionGrados.value}" >
<f:selectItem itemValue="A" itemLabel="A" />
<f:selectItem itemValue="B" itemLabel="B" />
<f:selectItem itemValue="C" itemLabel="C" />
<p:ajax update="someTextPanel" />
</p:selectOneMenu>
<p:outputPanel id="someTextPanel">
<p:outputLabel id="someTextLabel" value="Some text" rendered="#{controladorGestionGrados.value eq 'C'}" />
</p:outputPanel>
</h:panelGrid>
</h:form>