Search code examples
javawebtapestry

How to set init data for passwordfield in Tapestry Framework?


On my login page, I make a checkbox to save data to cookie. When the checkbox is check, data will be loaded to Username field, password field on next open login page. Right now, cookie data is loaded on username field but base on Tapestry page

PasswordField is a version of TextField, but rendered out as an element. Further, the output value for a PasswordField is always blank.

So I cannot set the init data for passwordfield. And I don't allow to use jquery or javascript just set the value to passwordfield on serverside. Can someone suggest a solution ?

Login.tml

<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
    xmlns:p="tapestry:parameter">
<body>
    <t:passwordfield t:id="password" size="30" />           
</body>
</html>

Login.java

@Property
private String password;
@InjectComponent("password")
private PasswordField passwordField;    

void setupRender() {
password = cookieTapestry.readCookieValue("userPassword") != null ?cookieTapestry.readCookieValue("userPassword") : null;
}

Solution

  • PasswordField is like a more limited TextField. Try <t:textfield type="password" ...> and you'll find you have more control over the behavior.