Bean绑定在Ajax调用中不起作用 [英] Bean binding not working in ajax call

查看:50
本文介绍了Bean绑定在Ajax调用中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个流程来定义一个可以正确提交数据的助手

I have a flow defining a helper that submits correctly the data

<var name="contactForm" class="my.package.bean.ContactFormHelper"/>

要基于用户输入获取一些数据,我在视图中使用绑定属性String id的ajax调用,方法是:

To get some data based on user input I use in the view an ajax call on the binded attribute String id in this way:

<h:panelGroup >
    <p:outputLabel for="id" value="ID" />
    <p:inputText id="id" required="true" value="#{contactForm.id}" label="ID">
        <f:ajax 
            event="change" 
            listener="#{contactController.identifyCustomer(contactForm)}" 
            render="anotherPanel" 
        />
        <p:clientValidator/>
    </p:inputText>
    <p:message for="id" />
</h:panelGroup>

但是,当执行identifyCustomer时,仅更新放置ajax的字段(String id).其余字段均填充有默认值.

But when identifyCustomer is executed only the field where ajax is placed (String id) is updated. The rest of fields are filled with default values.

日志跟踪

[21/11/16 17:10:12:508 CET] 0000007a SystemOut O调试[WebContainer:0:8610ff45-f4c5-4faf-a370-efa36701bc01]- ContactForm [name =,surnames =,nif = 46713535Y]

为什么会这样?

推荐答案

我找到了process的解决方案,该解决方案使用@this和以逗号分隔的字段:

I've found a solution with process using @this and fields separated by commas:

<p:ajax 
    event="change" 
    listener="#contactController.identifyCustomer(contactForm)}"
    <!-- add process with the fields to bind -->
    process="@this name,surname1,surname2"
    update="newCustomerPanel" 
/>

希望对其他人有帮助.

这篇关于Bean绑定在Ajax调用中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆