更改值的JSF ajax事件

更改值的JSF ajax事件,jsf,jsf-2.2,Jsf,Jsf 2.2,我试图用JSF ajax请求更改输入的值 我有JSF代码: <h:inputSecret id="pwd" value="#{info.password}" redisplay="true"> <f:ajax event="focus" listener="#{info.changePassword}" /> </h:inputSecret> createRandomPassword()创建短随机字符串 但是当输入获得焦点时,我可以看到调用了cha

我试图用JSF ajax请求更改输入的值

我有JSF代码:

 <h:inputSecret id="pwd" value="#{info.password}" redisplay="true">
   <f:ajax event="focus" listener="#{info.changePassword}" />
 </h:inputSecret>
createRandomPassword()
创建短随机字符串

但是当输入获得焦点时,我可以看到调用了
changePassword
函数,它设置了一些随机字符串,但是输入的值保持为空


那么为什么
setValue
不设置组件的值呢?如何使其工作?

在设置密码输入组件的值后,需要使用的render属性重新渲染密码输入组件

<h:inputSecret id="pwd" value="#{info.password}" redisplay="true">
   <f:ajax event="focus" listener="#{info.changePassword}" render="pwd"/>
 </h:inputSecret>


因为您没有告诉它更新ui端。您只需更新服务器端模型。但是为什么不直接设置一个名为“password”的字段并设置它,而不是从事件中获取输入呢?@Kukeltje我是JSF新手,我认为它可以完成这项工作。你能给我举个例子吗?请从一些好的教程开始。。。看,这是一件非常基本的事情,阅读这些内容会让你了解这件事,还有更多的事情……很有效!非常感谢。
<h:inputSecret id="pwd" value="#{info.password}" redisplay="true">
   <f:ajax event="focus" listener="#{info.changePassword}" render="pwd"/>
 </h:inputSecret>