How to use to set updated value in managed bean when value of is changed

前端 未结 1 479
灰色年华
灰色年华 2020-12-07 03:21

I have a JSF page with . I want to set the value bound to the when the value is changed.

Bean:

相关标签:
1条回答
  • 2020-12-07 03:51

    Just nest the <f:ajax> tag within the <h:inputText> tag.

    <h:inputText value="#{myBean.in}">
        <f:ajax />
    </h:inputText>
    

    It'll submit the value when the HTML DOM change event has occurred (i.e. when the field was edited and then blurred).

    The event attribute already defaults to valueChange, so it's omitted. Its execute attribute already defaults to @this, so it's omitted. In case you'd like to update other component on complete, set render attribute. E.g.

    <h:inputText value="#{myBean.in}">
        <f:ajax render="msg" />
    </h:inputText>
    <h:message id="msg" />
    

    If you want to invoke a listener when it has been successfully set, set the listener attribute:

    <h:inputText value="#{myBean.in}">
        <f:ajax listener="#{myBean.changeIn}" />
    </h:inputText>
    
    public void changeIn() {
        System.out.println("in has been changed to " + in);
    }
    

    See also:

    • When to use valueChangeListener or f:ajax listener?
    • What values can I pass to the event attribute of the f:ajax tag?
    0 讨论(0)
提交回复
热议问题