You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Sandor Feher <sf...@bluesystem.hu> on 2017/10/19 13:03:56 UTC
Validate before convert
Hi,
I have a form used for changing users' data e.g, mail address, password and
so one. I have a custom converter to convert clear text password to md5 hash
on the fly.
I set up some validators for password (length, complexity..) but the problem
is that the validator fires only after the input value get converted.
If I check the input within isModelChanged() then it works fine but I try to
avoid such solutions if possible.
<code>
PasswordTextField pwd1 = new PasswordTextField("password") {
@Override
public <C> IConverter<C> getConverter(Class<C> type) {
return (IConverter<C>) new Md5Converter() {
@Override
public Boolean isModelChanged() {
return u.getPassword() == null ||
!u.getPassword().equals(getInput());
}
};
}
};
</code>
TIA, Sandor
--
Sent from: http://apache-wicket.1842946.n4.nabble.com/Users-forum-f1842947.html
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Validate before convert
Posted by Sven Meier <sv...@meiers.net>.
Oops, forgot one thing :/
All wrapping models have to forward detach calls to nested models, i.e.:
public void detach() {
model.detach();
}
Have fun
Sven
Am 20.10.2017 um 09:34 schrieb Sandor Feher:
> Cool solution. Works like charm :), thanks!
>
> s
>
> --
> Sent from: http://apache-wicket.1842946.n4.nabble.com/Users-forum-f1842947.html
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Validate before convert
Posted by Sandor Feher <sf...@bluesystem.hu>.
Cool solution. Works like charm :), thanks!
s
--
Sent from: http://apache-wicket.1842946.n4.nabble.com/Users-forum-f1842947.html
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Validate before convert
Posted by Sven Meier <sv...@meiers.net>.
Hi,
you can do your md5-hashing in a model wrapper instead:
public class Md5Model implements IModel<String> {
private IModel<String> model;
public Md5Model(IModel<String> model) {
this.model = model;
}
public String getObject() {
return null;
}
public void setObject(String string) {
model.setObject(md5(string));
}
}
Have fun
Sven
Am 19.10.2017 um 15:03 schrieb Sandor Feher:
> Hi,
>
> I have a form used for changing users' data e.g, mail address, password and
> so one. I have a custom converter to convert clear text password to md5 hash
> on the fly.
> I set up some validators for password (length, complexity..) but the problem
> is that the validator fires only after the input value get converted.
>
> If I check the input within isModelChanged() then it works fine but I try to
> avoid such solutions if possible.
>
>
> <code>
> PasswordTextField pwd1 = new PasswordTextField("password") {
>
> @Override
> public <C> IConverter<C> getConverter(Class<C> type) {
> return (IConverter<C>) new Md5Converter() {
>
> @Override
> public Boolean isModelChanged() {
> return u.getPassword() == null ||
> !u.getPassword().equals(getInput());
> }
>
> };
> }
>
> };
> </code>
>
>
> TIA, Sandor
>
> --
> Sent from: http://apache-wicket.1842946.n4.nabble.com/Users-forum-f1842947.html
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org