views:

243

answers:

1

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>
+2  A: 

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 = "";
       }
      
Bozho
Our problem was not with issue 1. We got it working with onLoad and modifying the id(s) didn't help here.
Joshua
@Joshua : I added another even more preferred option - try it as well.
Bozho
thanks for updating, we are using the autocomplete option and is quite easy to use.
Joshua