Reputation: 9796
I am trying to change the value of input with JSF ajax request.
I have that JSF code:
<h:inputSecret id="pwd" value="#{info.password}" redisplay="true">
<f:ajax event="focus" listener="#{info.changePassword}" />
</h:inputSecret>
and theinfo
bean contains:
public String getPassword() {
return "";
}
public void changePassword(AjaxBehaviorEvent e) {
UIInput input = (UIInput)e.getComponent();
input.setValue(createRandomPassword());
}
createRandomPassword()
creates short random string.
But when the inputs get focus, I can see that the changePassword
function is called and it sets some random string, but the input's value stays empty.
So why setValue
not set the value to the component? How can I make it works?
Upvotes: 2
Views: 2385
Reputation: 1846
You need to re-render password input component after setting its value, using render attribute of
<h:inputSecret id="pwd" value="#{info.password}" redisplay="true">
<f:ajax event="focus" listener="#{info.changePassword}" render="pwd"/>
</h:inputSecret>
Upvotes: 1