How to clear the password / login id fields on load
When i try to create a new user, the following fields (loginId which is an inputText) and (password which is an inputSecret) come with pre-loaded values开发者_运维问答. How do we clear these fields when the page is loaded
<s:decorate id="loginIdField" template="/layout/edit.xhtml">
<ui:define name="label">Desired Login Name</ui:define>
<a:region>
<h:inputText id="loginId" required="true" value="#{userHome.instance.loginId}"/>
<div class="actionButtons">
<a:commandButton id="submit" value="Check Availability"
action="#{userHome.isUniqueUsername(userHome.instance.loginId)}" reRender="loginIdField"/>
</div>
</a:region>
</s:decorate>
<table style="clear:both">
<tr>
<td>
<s:decorate id="passwordField" template="/layout/edit.xhtml">
<ui:define name="label">Password</ui:define>
<h:inputSecret id="password" required="true" redisplay="true" value="#{userHome.instance.passwordHash}"/>
</s:decorate>
</td>
<td>
<s:decorate id="passwordControlField" template="/layout/edit.xhtml">
<ui:define name="label">Retype Password</ui:define>
<h:inputSecret id="passwordControl" required="true" redisplay="true">
<s:validateEquality for="password" message="The passwords don't match, please enter again"/>
</h:inputSecret>
</s:decorate>
</td>
</tr>
</table>
This may have two reasons:
- your
instance
is an already initialized object with setloginId
andpassword
- your browser recognizes the login fields and automatically fills-in the remembered values
They can be solved fairly easily:
during the initialization of the
userHome
bean create a new instance ofUser
rather than load anythingThree options:
(preferred) set the following attribute:
<h:inputText autocomplete="off" ..
change the
id
attribute of the fields to be different from those in the login form. for exampleid="registerLoginId"
.alternatively you can use javascript -
window.onload() = function() { document.getElementById("formId:fieldId").value = ""; }
精彩评论