How I can change the value of “selectOneMenu” without restart the “inputText”?

≡放荡痞女 提交于 2020-01-06 08:30:51

问题


I have the next code:

<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>

First: I write anything in the inputText. Second: I select option C.

After, the outputLabel "Some text" is displayed, but the inputText is reseted.

How I can change the value of "selectOneMenu" without restart the "inputText"?

I've tried:

<p:ajax update="someText"  />

But effectively the inputText don't reset, but outLabel don't show.


回答1:


Wrap your <p:outputLabel>

<p:outputLabel id="someText" value="Some text" rendered="#{controladorGestionGrados.value eq 'C'}" />

with a holder <p:outputPanel>

Like this :

<p:outputPanel id="someTextPanel">
<p:outputLabel id="someTextLabel" value="Some text" rendered="#{controladorGestionGrados.value eq 'C'}" />
</p:outputPanel>

And update the holder component (<p:outputPanel>) with

<p:ajax update="someTextPanel" />

So entire code should be something like this :

<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>


来源:https://stackoverflow.com/questions/23276928/how-i-can-change-the-value-of-selectonemenu-without-restart-the-inputtext

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