0

In Primefaces (JSF), in a web form I have 2 fields one & two. And on field two I have a change event which triggers myListener and inside that I am trying to read the field values of both one and two. But I get only the value of field two which triggers the event but not field one.

Is this the expected behaviour in JSF ? I need to do a cross field calculation with more than one fields.

HTML

<p:row>
    <p:column>
        <p:inputNumber id="one" value="#{bean.model.one}"  />
    </p:column>
    <p:column>
        <p:inputNumber id="two" value="#{bean.model.two}" >
            <p:ajax event="change"  listener="#{bean.myListener}" />
        </p:inputNumber>
    </p:column>

</p:row>    

Java

public void myListener() {
    System.out.println(model.one);  // prints null. Why ??
    System.out.println(model.two);  // prints value
}       
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Jay
  • 9,189
  • 12
  • 56
  • 96
  • 1
    Maybe you just need to (1) make sure everything is in a form, and (2) use the `process` attribute on `p:ajax` to specify to submit the form, e.g. `process="@form"`. – DavidS Dec 14 '16 at 17:42
  • @DavidS Many thanks a ton, I added 'process' and it now works... – Jay Dec 14 '16 at 17:47
  • Good. Consider reading the linked duplicate question because JSF is a powerful tool with a significant learning curve. Two tips: (1) never forget that client-side JSF is ultimately just HTML and Javascript, so all the same rules apply (e.g. AJAX and forms), and (2) try to learn the "JSF lifecycle" as that's where the majority of the complexity lies. – DavidS Dec 14 '16 at 18:23

0 Answers0