0

I have a requirement, program should convert every character entered into wicket textfield should be transformed to upper case. and when we get the value from model, it should be an uppercase String.

UpperCaseBehavior.java

import org.apache.wicket.Component;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.model.Model;

public class UpperCaseBehavior extends AttributeAppender {'
    private static final long serialVersionUID = 1L;

    public UpperCaseBehavior() {
        super("style", new Model<String>("text-transform: uppercase"), ";");
    }

    @Override
    public void bind(Component component) {
        super.bind(component);
        component.add(new AttributeAppender("onkeyup", new Model<String>(
                "this.value = this.value.toUpperCase()"), ";"));
    }
}

**adding upper case behaviour to textfield**<br/>
TextField<String> comp= new TextField<String>("chitMasterId",
                new PropertyModel<String>(this, "id"));
comp.add(new UpperCaseBehavior());


Above code is working fine when I enter characters sequentially. Assume ‘|’ as cursor.
Ex: ABCDEF|
When I bring the curser to middle (somewhere but not to the end) of the String
Ex: ABC|DEF
And as soon as I enter character the character is getting converted into upper case And curser is going to the end of the string.
Ex: ABCGDEF|
I am unable to change characters at the middle of the string sequentially.

0 Answers0