Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Validation error messages display problem
hai friends,
I have a problem with form validations. The following is my code
final TextField instCode = new TextField("Institution Code");
instCode.setWidth("200px");
instCode.addValidator(new RegexpValidator("^[a-zA-Z0-9]*", "Institution Code Must start String and end with digits"));
instCode.addValidator(new StringLengthValidator("Institution Code Must be 5 to 15 characters long", 5, 20, false));
instCode.setRequired(true);
instCode.setRequiredError("Institution Code is required");
instCode.setNullRepresentation("");
instCode.setImmediate(true);
instCode.addListener(new BlurListener() {
public void blur(BlurEvent event) {
if(instCode.isValid()){
String temp=(String) instCode.getValue();
if (institutionHome.isInstCodeExists(temp)) {
instCode.setComponentError(new UserError("Institution is already registered with this code"));
instCode.setValidationVisible(true);
}
}
}
});
return instCode;
My problem is that when the institution is already registered with this institutionCode I want to display an error message and error message is showing correctly, but the problem is even after changing the value also the same error message is showing.........please help me...............
thanks in advance...................
First , I do not thing you really need a validation error for a radio field set because you could just have one of the fields checked by default. Most people would rather correct something then provide something. for instance.
_______________________________________________________________________
Liferay Portal Development
hai chirag,
sorry my friend................i didn't understand anything that what you say............please give the clarity.............
Well, your red marked code-lines set a fixed error-message, that will be displayed always. Just remove them and call isValid() on your form to trigger the Validators.
hai Tobias Demuth ,
Thanks for your reply, but when I come to inside the following if codition I want to display an error message
if (instGenHome.isInstCodeExists(temp)) {
// here I want to display an error message
}
Afterthat When I change the textfield value..........this error message will be removed............this is what I want.........
Please give me a solution................thanks in advance.............
You should write a Validator for this and use it as you would use for example the StringLengthValidator above.