I'll throw in my endorsement for (1). Often, we programmers get too
wrapped up in try to use some clever framework feature for every
minute detail ... when sometimes, it's simpler just to write a few
lines of code.
A listener which first performs validation before processing is easy
to write, easy to read, and extremely flexible. I'm not saying it's
the best way to do everything; it's just an option people often
overlook.
Here's a more complete example:
@Bean( value=ValidationDelegate.class )
public abstract IValidationDelegate getValidation();
@Component(
type="TextField", id="email",
bindings = { "value=email" } )
public abstract TextField getEmailComponent();
public abstract String getEmail();
public abstract void setEmail(String value);
@Component(
type="TextField", id="password",
bindings = { "value=password", "hidden=true" } )
public abstract TextField getPasswordComponent();
public abstract String getPassword();
public abstract void setPassword(String value);
public IPage logIn()
{
if(isBlank(getEmail()))
getValidation().record(
getEmailComponent(),
"Please enter the email address for your account.");
if(!matchPassword(getEmail(), getPassword()))
getValidation().record(
getPasswordComponent(),
"Sorry, this is the wrong password.");
if(getValidation().getHasErrors())
{
// take action to prevent commit if necessary
return this;
}
// --- Success ---
// ... do work ...
// ... commit work ...
return successPage;
}
Cheers, P
On Jul 3, 2006, at 1:46 PM, Richard Clark wrote:
You can either:
1) Do all the validation in your listener (on the Java side), or
2) Write your own client-side valdation code in JavaScript.
The server-side validation would look like this:
ValidationDelegate delegate = (ValidationDelegate)getComponent
("delegate");
if (!getCheckbox()) {
String firstName = getFirstName(); // @Text component bound to
firstName
if (firstName == null || firstName.length() == 0) {
delegate.setFormComponent((IFormComponent)getComponent
("inputFirstName"));
delegate.record("Please supply a first name",
ValidationConstraint.REQUIRED);
}
}
if (delegate.getHasErrors()) return;
...Richard
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
_________________________________________________________________
Piano music podcast: http://inthehands.com
Other interesting stuff: http://innig.net
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]