0

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
victorpacheco3107
  • 822
  • 3
  • 10
  • 32

1 Answers1

2

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>
  • 1
    Fantastic! But did you understand why it is working ? It's in fact all about the presence in the DOM of the element to be dynamically rendered upon ajax update events. An element can't be updated if it is not there.. –  Apr 25 '14 at 00:14
  • Yes Sir, I understand, in summary: if not present at the beginning, after can not manipulated. – victorpacheco3107 Apr 25 '14 at 00:29