0

I have no idea why my setters are not invoked while processing form. I see in network browser tool, that POST request is fired with correct (updated) data. But it doesn't affects my binded bean.

<p:commandButton value="Action"
                     immediate="true"
                     action="#{beanView.actionForString('5/13/015')}"
                     oncomplete="PF('some_widget').show()"
                     update="some_widget_update"/>
    <p:dialog id="some_widget_update" widgetVar="some_widget" width="800">
        <ui:include src="/view.xhtml" />
    </p:dialog>

Template form:

<h:form id="contentForm"
                prependId="false"
                enctype="multipart/form-data">
            <p:messages autoUpdate="true"
                        globalOnly="true"
                        showDetail="true"
                        for="formMessages"
                        closable="true" />
            <div id="starterDiv"
                 class="ui-fluid">
                <ui:insert name="formAsd" />
            </div>
        </h:form>

And view.xhtml:

    <ui:define name="formAsd">
        <h:panelGroup rendered="#{beanView.payment!= null}">
            <c:set var="payment" value="#{beanView.payment}" />
  <div class="ui-g with_background">
               <div class="ui-g-2">Payment Id:</div>
               <div class="ui-g-2">
                   <p:inputText value="#{payment.id}"/>
               </div>
          </div>
  <p:commandButton value="Save"
                                 immediate="true"
                                 process="contentForm"
                                 action="#{beanView.save()}" style="width: 150px"/>
   </h:panelGroup>
</ui:define>

The bean view looks like that:

@ManagedBean
@ViewScoped
@Data
@FieldDefaults(level = AccessLevel.PRIVATE)
public class BeanView implements Serializable {

    Payment payment;

    @Setter(onMethod=@__({@Autowired}))
    transient PaymentService paymentService;

    public void save() {
        paymentService.registerPayment(payment); // here It's unchanged!!
   }
    public void actionForString(String asd) {
        payment= paymentService.takeForString(asd)

    }
}

Getter works fine, I can see values which service returns in my view.xhtml. Then as I said above, after changing the input value and clicking save button, my debugger shows old value (from intialization in actionFroString) method. Why it is happening?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
minizibi
  • 363
  • 2
  • 14
  • Tried without the 'lombok' @setter annotation? Since you seem to be using things that you did not use in your tags. Please create a [mcve] – Kukeltje Dec 01 '18 at 18:43

1 Answers1

0

I believe your problem is immediate="true" on your Command Button. That command immediate="true" tells JSF to skip the validation and binding phase which is why your setters are not being called. This detailed explanation explains why: https://dzone.com/articles/jsf-and-immediate-attribute

Melloware
  • 10,435
  • 2
  • 32
  • 62