如何使用< f:ajax>当值< h:inputText>设置为0时,在托管Bean中设置更新的值.改变了 [英] How to use <f:ajax> to set updated value in managed bean when value of <h:inputText> is changed

查看:45
本文介绍了如何使用< f:ajax>当值< h:inputText>设置为0时,在托管Bean中设置更新的值.改变了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个<h:inputText>的JSF页面.我想在更改值时设置绑定到<h:inputText>的值.

I have a JSF page with <h:inputText>. I want to set the value bound to the <h:inputText> when the value is changed.

Bean:

@ManagedBean
@SessionScope
public class MyBean {

    private String in;
    //getter and setter

}

查看:

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

如何为此使用<f:ajax>?

推荐答案

只需将<f:ajax>标记嵌套在<h:inputText>标记内.

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

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

它将在HTML DOM change事件发生时(即,在编辑字段然后将其模糊时)提交值.

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

event属性已经默认为valueChange,因此将其省略.它的execute属性已经默认为@this,因此将其省略.如果您想完全更新其他组件,请设置render属性.例如

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" />

如果要在成功设置侦听器后调用它,请设置listener属性:

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);
}

另请参见:

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