Hello Mailinglist again,

I tried to implement a simple input field where you can e.g. enter your
username. Now I want to let the background of the textfield be red while it
is not valid. And if it's finally valid it should change to green (during
the input). My problem is, that I always loose the focus on the input field
on correct input. I guess it has something to do with the addComponent
method. Here is my code so far....

final FormComponent usernameField;
       usernameField = new TextField("username", new PropertyModel(this,
"username"));
       usernameField.add(new AttributeModifier("class", true, new
PropertyModel(this, "usernamevalid")));
       usernameField.setOutputMarkupId(true);

       //this works aswell with AjaxFormSubmitBehavior. I do not see the
difference yet.
       usernameField.add(new AjaxFormComponentUpdatingBehavior("onkeyup"){

           @Override
           protected void onUpdate(AjaxRequestTarget target) {
               System.out.println(username);
               if (username.equals("Cliff")) {
                   usernameField.add(new AttributeModifier("class", true,
new Model("valid")));
                   target.addComponent(usernameField);
               }else {
                   if (usernamevalid.equals("valid")) {
                       usernameField.add(new AttributeModifier("class",
true, new Model("invalid")));
                       target.addComponent(usernameField);
                   }
               }
           }

       });
       add(usernameField);

Is there a way not to loose the focus?
Thank in advance!
Cliff

P.S.: usernamevalid could also be a boolean variable. But somehow I feel it
is not so nice code I produced here...
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to