0

The following snippet works:

<h:form id="form1">

    <h:inputHidden value="#{bean.field1}" id="field1"/>
    <h:inputHidden value="#{bean.field2}" id="field2"/>
    <h:inputHidden value="#{bean.field3}" id="field3"/>
    <h:inputHidden value="#{bean.field4}" id="field4"/>
    <h:inputHidden value="#{bean.field5}" id="field5"/>
    <h:inputHidden value="#{bean.field6}" id="field6"/>
    <h:inputHidden value="#{bean.field7}" id="field7"/>
    <h:inputHidden value="#{bean.field8}" id="field8"/>
    <h:inputHidden value="#{bean.field9}" id="field9"/>

    <p:remoteCommand name="loadRecord" actionListener="#{bean.loadRecord}" 
        process="@this" 
        update="field1 field2 field3 field4 field5 field6 field7 field8 field9" />

</h:form>

The problem is that when the number of fields to update is large (I have another page with 40 fields) it becomes unmaintainable.

I tried to use instead

<p:remoteCommand name="loadRecord" actionListener="#{bean.loadRecord}" 
  process="@this" update="@form" />

but the fields are not updated. Any ideas?

UPDATE:

This problem is not restricted to hidden fields, it seems to apply to any input field for example to

<h:inputText id="name" value="#{bean.name}" />
ps0604
  • 1,227
  • 23
  • 133
  • 330
  • Works fine for me. Which PF version? Sure that you're running the code you think you're running? How does ajax response look like? Perhaps you're nesting forms? – BalusC Sep 05 '14 at 11:40
  • I'm using PF 3.5. The code runs correctly when the fields are enumerated, but when I replace them with `@form` or `form1` or `:form1` the code does not work. Forms are not nested. Not sure how to look at the ajax response. – ps0604 Sep 05 '14 at 12:03
  • I just tried with PF 5.0 and have the same problem – ps0604 Sep 05 '14 at 12:09
  • Press F12 in a decent browser to get web developer toolset with therein HTTP traffic monitor (usually in "Network" tab/section). Select the ajax request to see the request parameters and response body. – BalusC Sep 05 '14 at 12:21
  • I just saw the XHR response of the two scenarios. In both cases the input fields are coming populated (inputHidden and inputText fields) but in the @form scenario the response also contains a large chunk of the HTML page, that doesn't seem correct. – ps0604 Sep 05 '14 at 13:00
  • This strongly suggests that you're nesting forms or perhaps has a custom view handler and/or ajax response writer somewhere. Can you please create and post a real [MCVE](http://stackoverflow.com/help/mcve) so that we can try reproducing the problem in a blank project with everything set to default unless otherwise specified? – BalusC Sep 05 '14 at 13:01

2 Answers2

1

You can wrap your fields (if they are grouped together) in a Naming Container. Then you only have to update the naming container and all it's content will be updated as well. Your h:form is already a NamingContainer, but if you do not want to update your whole form you can try this:

<p:outputPanel id="myContainer">
  <h:inputHidden value="#{bean.field1}" id="field1"/>
  <h:inputHidden value="#{bean.field2}" id="field2"/>
  <h:inputHidden value="#{bean.field3}" id="field3"/>
  <h:inputHidden value="#{bean.field4}" id="field4"/>
  ...
</p:outputPanel>

<p:remoteCommand name="loadRecord" actionListener="#{bean.loadRecord}" 
    process="@this" 
    update="myContainer" />
Community
  • 1
  • 1
Manuel
  • 3,828
  • 6
  • 33
  • 48
-1

You should use the id of the form you want to update. In your case update="form1"

Ishkafel
  • 333
  • 1
  • 10