PDA

View Full Version : Validator is partially working



phamtranquocviet
15 Mar 2009, 10:39 AM
Hi,
The following validator is supposed to check with db if the entered ssn already exits. It correctly shows and not show error when ssn field becomes blur. However, it goes through when I click "Register" button at the bottom of the form even though I call formPanel.isValid(). formPanel.isValid() && ssn.isValid() also let the form submit.



private Button createRegistrationButton()
{
Button registerButton = new Button("Register");
registerButton.addSelectionListener(new SelectionListener<ButtonEvent>()
{
@Override
public void componentSelected(ButtonEvent ce)
{
if(panel.isValid() && ssn.isValid())
{
AsyncCallback<CreatedUser> callback = new AsyncCallback<CreatedUser>()
{
public void onFailure(Throwable caught){}
public void onSuccess(CreatedUser createdUser)
{
//This line is executed even when ssn shows an error message
MessageBox.confirm("Test", "Testing", null);
}
};

Mem mem = new Mem(0, first.getValue());
service.register(mem, callback);
}
else
MessageBox.alert("Form Vaidation", "One or more fields are invalid!", null);
}
});
return registerButton;
}


ssn.setValidator(new Validator<String, TextField<String>>()
{
public String validate(TextField<String> field, String value)
{
AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>()
{
public void onFailure(Throwable caught){}
public void onSuccess(Boolean isDuplicate)
{
if((Boolean)isDuplicate)
ssn.markInvalid("SSN already existss!");
else
ssn.clearInvalid();
}
};
service.isDuplicateSsn(ssn.getValue(), callback);
return null; <<==I have no choice but return null. Any advise on this too?
}
});

I have tried multiple things and gone nowhere. Please help. Thanks.