Hello,
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:
@Configurable
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() {
super();
}
public JobEditWindow(String caption, ComponentContainer content) {
super(caption, content);
}
public JobEditWindow(String caption) {
super(caption);
}
@PostConstruct
public void init()
{
setWidth("550px");
vl1 = new VerticalLayout();
vl1.setMargin(true);
form = new ViewBoundForm(new JobFormComp());
form.setImmediate(false);
form.setWriteThrough(false);
form.setInvalidCommitted(false);
vl1.addComponent(form);
saveBtn = new Button("SAVE");
hl1 = new HorizontalLayout();
hl1.addComponent(saveBtn);
vl1.addComponent(hl1);
setContent(vl1);
saveBtn.addListener(new ClickListener()
{
private static final long serialVersionUID = 6225427029801552571L;
@Override
public void buttonClick(ClickEvent event)
{
try
{
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;
}
}