Validate before convert

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Validate before convert

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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Validate before convert

Sven Meier
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: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Validate before convert

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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Validate before convert

Sven Meier
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: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]