从侦听器方法更改inputText值 [英] Change inputText value from listener method

查看:123
本文介绍了从侦听器方法更改inputText值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个inputText:

I have an inputText:

<h:inputText id="result" value="#{guessNumber.result}"/>

和另一个inputText:

and another inputText:

<h:inputText id="name" value="#{guessNumber.named}" onchange="submit()" valueChangeListener="#{guessNumber.processValueChange}"/>

在processValueChange方法中,我添加了以下行:

and inside the processValueChange method, I added the following line:

result = "hello";

但是结果" inputText的显示值仍然没有链接,这是什么问题?

but the displayed value of "result" inputText remains unchainged, what is the problem?

推荐答案

我找到了解决方案: 我没有将inputText的 value 属性绑定到bean内的String属性(结果),而是将inputText绑定到bean内的UIInput属性:

I found the solution: Instead of binding the value attribute of the inputText to a String property (result) inside the bean, I bound the inputText to UIInput property inside the bean:

<h:inputText id="result" binding="#{guessNumber.result}"/>

并在bean中:

private UIInput result = null;

这允许侦听器方法直接修改inputText的 value 值,而不是修改绑定到inputText的 value 属性的属性:

this lets the listener method modify the inputText value directly, instead of modifying the property that is bound to the value attribute of the inputText:

result.setValue("Hello");

感谢每一个试图解决我的问题的人.

Thanks for every one tried to solve my problem.

这篇关于从侦听器方法更改inputText值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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