AjaxEditableLabel and Validator behavior confuses me

I searched a lot for this problem, but the explanation does not explain what I am looking for

I have a class as I posted at the end. Very briefly: PatternValidation behavior is different from manual validation.

For example: AjaxEditableLabel has a shortcut and editor that switches to edit (focus) and cancel or submit

If I make an input that is unvalid for the Patternvalidator, the input is checked as you can fix it. If you then press Esc, the editor will be set invisible and the label will be empty again. But if I edit the label again, the value is still in the editor, it's wrong.

If I make an input that passes a templated ID, but it is not valid inside the onSubmit method, the input is flagged as well and you can fix it. But if you do and then press Esc, the value you entered will be written on the label, and it shouldn't. And I really need further validation inside onSubmit.

It seems like something between the validation part and the onSubmit () method is pulling the value from the editor into the label. Is there something completely wrong in my mind?

Sample code:

public class MyEditableLabel extends AjaxEditableLabel<String>{
    public MyEditableLabel(String id, IModel<String> model) {
        super(id, model);
        PatternValidator patternValidator = new PatternValidator(Pattern.compile(
            "(^([0-9]|[0-1][0-9]|2[0-3]):([0-5][0-9])$)|((\\d{1,2})(,|\\.)(\\d\\d))"));
        this.add(patternValidator);
    }

    @Override
    protected void onSubmit(AjaxRequestTarget target) {
        // further validation
        if( editorValue.equals("00:00") ) { //just for example
            onError(target);
        } else {
            super.onSubmit(target);
        }
    }
}

      

+3


source to share


1 answer


This appears to be a bug in the AjaxEditableLabel and will be fixed in the next Wicket release.

Now you can override onCancel ():



protected void onCancel(final AjaxRequestTarget target)
{
    super.onCancel();
    getEditor().clearInput();
}

      

+4


source







All Articles