peterremec
peterremec

Reputation: 516

Updating h:inputHidden on tab change

I have a Primefaces tab view with two tabs and a inputHidden element with some string in it. On the first tab there is a commandButton that changes the value of an inputHidden element. I'd like to use that changed value in a useText JS function, but I get an old value of a hidden field.

After updating my hidden field, it IS updated but an output text on a second tab is not updated and I don't understand, why.

<h:form id="formMain">
      ...
    <p:tabView onTabChange="useText(#{bean.text});">
        <p:tab title="tab1">
            <p:commandButton value="Change" action="#{bean.doBtnChangeText}" update=":formMain:hidArray @(.textTest)" />
        </p:tab>
        <p:tab title="tab2" >
<h:outputText styleClass="textTest" value="#{bean.text}" />
        </p:tab>
    </p:tabView>
      ...
<h:inputHidden id="hidText" value="#{bean.text}" immediate="true" />

</h:form>

EDIT: I added some output text on a second tab to check for updated value. I updated both, hidden field and output text, on a command button. Hidden field is updated but output text is not.

Upvotes: 0

Views: 1228

Answers (2)

peterremec
peterremec

Reputation: 516

Solved it by adding id attribute to h:outputText element.

<h:outputText id="outText" styleClass="textTest" value="#{bean.text}" />

Upvotes: 0

Marcus Martins
Marcus Martins

Reputation: 121

As Jasper said, you can try update on your command button, or try to update directly from bean, on your doBtnChangeText(), just call RequestContext.getCurrentInstance().update("form:hidText").

Upvotes: 1

Related Questions