Question

I am using a Wicket formpanel to allow admins of the webapp to edit user account data. There is a password field, where an admin can set a new password for a user and other account data fields. When I open the formpanel the browser autofills the password field with MY password I saved in the browser. This field should be left blank by default. In addition the browser inserts my username ("admin") in the field for the mobile number!

The formpanel

Is there a way to avoid this behavior by changing the code of the formfield? For example prohibit autofill or something like this? Here are the relevant code parts:

        mobile = new TextField<String>("mobile");
    mobile.add(PhonenumberValidator.getInstance());
    mobile.setOutputMarkupId(true);
    addToForm(new FencedFeedbackPanel("mobileCfp", mobile));
    addToForm(mobile);
    generatedPassword = new GeneratedPasswordLabelPanel("generatedPassword");
    generatedPassword.setOutputMarkupId(true);
    generatePassword = new IndicatingAjaxLink<Void>("generatePassword"){
        private static final long serialVersionUID = 6759645521399346111L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            generatedPasswordString = PasswordGenerator.generatePassword(8);
            generatedPassword.setPasswordString(generatedPasswordString);
            target.add(generatedPassword);
        }
    };
    newPassword = new PasswordTextField("newPassword");
    newPassword.add(PasswordValidator.getInstance());
    newPassword.setOutputMarkupId(true);
    newPassword.setModel(new Model<String>());
    newPassword.setRequired(false);
    newPassword.setResetPassword(true);
    newPassword.add(new RequiredLabelBehavior());
    confirmPassword = new PasswordTextField("confirmPassword");
    confirmPassword.setOutputMarkupId(true);
    confirmPassword.setModel(new Model<String>());
    confirmPassword.setRequired(false);
    confirmPassword.setResetPassword(true);
    confirmPassword.add(new RequiredLabelBehavior());
    pwContainer = new WebMarkupContainer("pwContainer");
    pwContainer.add(confirmPassword);
    pwContainer.add(newPassword);
    pwContainer.add(generatePassword);
    pwContainer.add(generatedPassword);
    pwContainer.add(new FencedFeedbackPanel("newPasswordCfp", newPassword));
    pwContainer.add(new FencedFeedbackPanel("confirmPasswordCfp", confirmPassword));
    pwContainer.setVisible(ajax);
    addToForm(pwContainer);

And this is the Wicket-Html Code:

<?xml version="1.0" encoding="UTF-8"?>

        <div wicket:id="emailCfp" />
        <input wicket:id="email" type="text" />
        <div class="brclear"></div>

        <select wicket:id="account.salutation" />
        <div class="brclear"></div>

        <input wicket:id="title" type="text" style="width:100px" />
        <div class="brclear" />

        <div wicket:id="firstnameCfp" />
        <input wicket:id="firstname" type="text" />
        <div class="brclear"></div>

        <div wicket:id="lastnameCfp" />
        <input wicket:id="lastname" type="text" />
        <div class="brclear"></div>

        <div wicket:id="phoneCfp" />
        <label><wicket:message key="phone" /></label><input wicket:id="phone" type="text" />
        <div class="brclear"></div>

        <div wicket:id="birthday" />
        <div class="brclear" />

        <div wicket:id="mobileCfp" />
        <label><wicket:message key="mobile" /></label><input wicket:id="mobile" type="text" />
        <div class="brclear"></div>
    </fieldset>

    <fieldset wicket:id="imageContainer">
        <legend><wicket:message key="legend.picture" /></legend>
        <div>
            <img style="float: left; margin: 0px 5px 5px 0px;" wicket:id="userImage" />
            <br />
            <span wicket:id="blob"></span>
        </div>
    </fieldset>

    <fieldset wicket:id="pwContainer">
        <legend><wicket:message key="legend.pw" /></legend>
        <input type="button" wicket:id="generatePassword" wicket:message="value:generatePassword" />
        <div style="float:left;">
            <div wicket:id="generatedPassword" />
        </div>
        <div class="brclear"></div>

        <div wicket:id="newPasswordCfp" />
        <input wicket:id="newPassword" type="password" />
        <div class="brclear"></div>

        <div wicket:id="confirmPasswordCfp" />
        <input wicket:id="confirmPassword" type="password" />
        <div class="brclear"></div>
    </fieldset>

    <wicket:child />

</wicket:extend>

Thank you!

Était-ce utile?

La solution

The following code will show you how to deactivate auto fill for a HTML form. I think that is what you need. But I do not know how to set this value in Java. autocomplete="off" is the magic parameter.

<form action="demo_form.asp" method="get" autocomplete="off">
   First name:<input type="text" name="fname"><br>
   E-mail: <input type="email" name="email"><br>
   <input type="submit">
</form>

Edit: I found something at https://issues.apache.org/jira/browse/WICKET-1504, but I'm not sure if it works. newPassword.put("autocomplete", "off"); and the same for the username input field object.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top