开发者

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:

  1. your instance is an already initialized object with set loginId and password
  2. your browser recognizes the login fields and automatically fills-in the remembered values

They can be solved fairly easily:

  1. during the initialization of the userHome bean create a new instance of User rather than load anything

  2. Three 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 example id="registerLoginId".

    • alternatively you can use javascript -

      window.onload() = function() {
           document.getElementById("formId:fieldId").value = "";
       }
      
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜