Help on Form Validation!


I have searched the forum for hours without success, please help me.
I got a form in which one of the TextFiled registered a StringLengthValidator.
If I call commit(), isValid() or validate() on the form, it will throw InvalidValueException follow by a notification to the client side. The textfiled also has proper error message indicating the textfield has failed the validation, this is correct.
The problem is that this InvalidValueException will not be caught on the button listener. How can I catch this exception and disable the notification?

Here is my partial code:

public class JobEditWindow extends Window 
	private static final long serialVersionUID = -6596707217856351847L;
	private VerticalLayout vl1;
	private HorizontalLayout hl1;
	private Button saveBtn;
	private ViewBoundForm form;
	@Resource private ResumeDAO dao;

	public JobEditWindow() {

	public JobEditWindow(String caption, ComponentContainer content) {
		super(caption, content);

	public JobEditWindow(String caption) {
	public void init()
		vl1 = new VerticalLayout();
		form = new ViewBoundForm(new JobFormComp());
		saveBtn = new Button("SAVE");
		hl1 = new HorizontalLayout();
		saveBtn.addListener(new ClickListener()
			private static final long serialVersionUID = 6225427029801552571L;
			public void buttonClick(ClickEvent event) 
					form.commit();  //same as form.isValid()  or form.validate()
				catch(Exception e)
					System.out.print("ERROR");  //this line can not be reached.

	 * @return the form
	public ViewBoundForm getForm() {
		return form;

I do something similar all the time and it works fine for me:

                    try {
                    } catch (InvalidValueException ive) {
                        // get root cause of ive and show notification

How do you know it’s not getting into your catch block? If through a debugger, then you ought to be able to step into the commit() method to see what’s going on. Since Vaadin is open-source, grabbing the sources to step through is a huge help to understanding it. If you’re not trying this is a debugger, then make sure your output actually goes somewhere. For instance, add a println statement before and after the “form.commit()” call.

If you can’t figure it out, try creating a simpler test case (e.g. one Application class with inner classes for listeners) and post that so that someone can try the whole thing. Often, the act of creating the simple test case helps you see the problem if there is one.

Note that InvalidValueExceptions should be handled differently than other exceptions since it has an array of causes instead of a single Throwable cause like other exceptions. Maybe that’s already obvious to everyone else though. :slight_smile:


I have exactly the same problem