Submitted form values not updated in model when adding to

前端 未结 1 994
清酒与你
清酒与你 2020-12-11 22:23

I\'m learning how to use ajax within jsf, I made a page that does actually nothing, an input text that is filled with a number, submitted to the server, call the setter for

相关标签:
1条回答
  • 2020-12-11 22:50

    The <f:ajax> processes by default only the current component (read description of execute attribute). Basically, your code is exactly the same as this:

    <h:form>
        <h:commandButton action="nothing">
            <f:ajax execute="@this" render="num"/>
        </h:commandButton>
        <h:inputText value="#{helper.randomize}" id="num"/>
    </h:form>
    

    In effects, only the <h:commandButton action> is been processed and the <h:inputText value> (and any other input field, if any) is completely ignored.

    You need to change the execute attribute to explicitly specify components or sections you'd like to process during the ajax request. Usually, in order to process the entire form, @form is been used:

    <h:form>
        <h:commandButton action="nothing">
            <f:ajax execute="@form" render="num"/>
        </h:commandButton>
        <h:inputText value="#{helper.randomize}" id="num"/>
    </h:form>
    

    See also:

    • Communication in JSF 2.0 - Ajax (asynchronous) POST form
    • commandButton/commandLink/ajax action/listener method not invoked or input value not updated (point 8)
    • Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes
    0 讨论(0)
提交回复
热议问题