I have problem. I validate all user input using valuechage event it’s working perfectly. Submit button call another methods, Now my problem if user enter wrong data and press submit button (neglecting errors) those methods should not call and give some error message. Below show my code. Please help me how to solve this problem.
import com.vaadin.Application;
import com.vaadin.data.validator.EmailValidator;
import com.vaadin.data.validator.RegexpValidator;
import com.vaadin.ui.*;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
/**
*
* @author dinesh
* @version
*/
public class MyApplication extends Application implements ClickListener {
TextField txtName;
TextField txtEmailAdd;
Button btnRegister;
@Override
public void init() {
Window mainWindow = new Window("MyApplication");
txtName = new TextField();
txtName.setImmediate(true);
txtName.setHeight("-1px");
txtName.setWidth("-1px");
txtName.setCaption("Name");
txtName.setRequired(true);
txtName.setRequiredError("Please Enter a Name");
txtName.addValidator(new RegexpValidator("^\\w*$", "Must be letters and numbers"));
txtName.setTabIndex(1);
mainWindow.addComponent(txtName);
txtEmailAdd = new TextField("Email");
txtEmailAdd.setImmediate(true);
txtEmailAdd.setHeight("-1px");
txtEmailAdd.setWidth("250px");
txtEmailAdd.setTabIndex(2);
txtEmailAdd.addValidator(new EmailValidator("Enter correct Email"));
mainWindow.addComponent(txtEmailAdd);
btnRegister = new Button();
btnRegister.setImmediate(true);
btnRegister.setHeight("-1px");
btnRegister.setWidth("-1px");
btnRegister.setCaption("Register");
btnRegister.setTabIndex(25);
btnRegister.addListener((ClickListener) this);
mainWindow.addComponent(btnRegister);
setMainWindow(mainWindow);
}
public void buttonClick(ClickEvent event) {
final Button source = event.getButton();
if (source == btnRegister) {
System.out.println("Can't Print");
}
}
}