Question

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.

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top