0

I'm implementing simple registration form. Table with inputs and labels is placed in p:dialog which is placed in h:form. One of the feature is automatically generated alphanumeric password. I want to update value of password p:inputText after clicking button which is placed in the same form. Generating method is called every time I push the button (and I can see generated strings in console log). The problem is related with the inputText tag which is not updated properly. After opening the dialog box I can refresh password inputText only once, next time method is fired but inputText is not updated. The code is as below:

Alphanumeric password generator method:

public static String randomPassword(){
    return RandomStringUtils.randomAlphanumeric(PASSWORD_LENGTH);
}

New account model:

@Named
@ViewScoped
public class AccountModel implements Serializable {
    private Account Account = new Account();
    public Account getAccount() {
        return account;
    }
    public void setAccount(Account account) {
        this.account = account;
    }
}

Password fixing method in ViewScoped AddUserBean:

public void generateRandomPassword() {
   accountModel.getAccount().setPassword(PasswordGenerator.randomPassword());
   LOGGER.info(MessageFormat.format("Random password generated: {0}", accountModel.getAccount().getPassword()));
}

JSF form snippet:

<p:column>
    <p:inputText id="userPassword" value="#{accountModel.account.password}" styleClass="fullWidth"  />
</p:column>
<p:column>
    <p:commandButton id="randomPasswordButton" update="userPassword">
        <p:ajax event="click" listener="#{addUserBean.generateRandomPassword}" update="userPassword" />
    </p:commandButton>
</p:column>

The question is: What kind of updating should I use for proper password inputText refreshing (every time I push the button, not only once)?

Kukeltje
  • 11,924
  • 4
  • 19
  • 44
micGar
  • 1

0 Answers0