如何使用< 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
问题描述
我有一个<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);
}
另请参见:
- 何时使用valueChangeListener或f:ajax监听器?
- 哪些值可以我传递给f:ajax标记的事件属性?
- When to use valueChangeListener or f:ajax listener?
- What values can I pass to the event attribute of the f:ajax tag?
See also:
这篇关于如何使用< f:ajax>当值< h:inputText>设置为0时,在托管Bean中设置更新的值.改变了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!