[英]How to use <f:ajax> to set updated value in managed bean when value of <h:inputText> is changed
I have a JSF page with <h:inputText>
.我有一个带有
<h:inputText>
的 JSF 页面。 I want to set the value bound to the <h:inputText>
when the value is changed.我想在更改值时设置绑定到
<h:inputText>
的值。
Bean:豆:
@ManagedBean
@SessionScope
public class MyBean {
private String in;
//getter and setter
}
View:看法:
<h:inputText value="#{myBean.in}" />
How can I use <f:ajax>
for this?我该如何使用
<f:ajax>
?
Just nest the <f:ajax>
tag within the <h:inputText>
tag.只需将
<f:ajax>
标记嵌套在<f:ajax>
<h:inputText>
标记中。
<h:inputText value="#{myBean.in}">
<f:ajax />
</h:inputText>
It'll submit the value when the HTML DOM change
event has occurred (ie when the field was edited and then blurred).它会在 HTML DOM
change
事件发生时提交值(即当字段被编辑然后模糊时)。
The event
attribute already defaults to valueChange
, so it's omitted. event
属性已默认为valueChange
,因此将其省略。 Its execute
attribute already defaults to @this
, so it's omitted.它的
execute
属性已经默认为@this
,所以它被省略了。 In case you'd like to update other component on complete, set render
attribute.如果您想在完成时更新其他组件,请设置
render
属性。 Eg例如
<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:如果要在成功设置后调用侦听器,请设置
listener
属性:
<h:inputText value="#{myBean.in}">
<f:ajax listener="#{myBean.changeIn}" />
</h:inputText>
public void changeIn() {
System.out.println("in has been changed to " + in);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.