Hi,
To keep all your validation in onValidateForm, I something like this.
String onValidateForm()
{
if(userName == null )
{
form.recordError(usernameField, "Needs a Username")
}
if(password == null )
{
form.recordError(passwordField, "Please Enter a password")
}
if(!form.getHasErrors()) {
if (!authenticator.isValid(userName, password))
{
form.recordError(passwordField, "Invalid user name or
password.");
}
else
{
//set applicationstate user object
}
}
}
Object onSuccess()
{
//here you can return whatever page you forward after login.
return IndexPage;
}
Benny Law wrote:
>
> Hi Onno,
>
> I am all for clean and maintainable code, and that's why I think
> ValidateForm can be cleaner if I didn't need to check for field errors
> first.
>
> On the main Tapestry 5.1 page, the Login example calls the authenticator
> in
> onValidateForm, but the same example in the User Guide under Input
> Validation does that in onSuccess. I think the latter is correct; the
> former
> won't work properly because it acts on the properties bound to the fields
> which may not reflect the current field contents if there are field
> validation errors. To fix the first example, some code needs to be added
> to
> onValidateForm to check if the fields have passed field-level validations
> before invoking the authenticator.
>
> I hope this clarifies what I am thinking. Thanks.
>
> Benny
>
> On Mon, Aug 31, 2009 at 4:57 AM, Onno Scheffers <[email protected]> wrote:
>
>> > Thanks for your response. Could you explain what you mean by keeping my
>> > validation "in the correct callback"?
>>
>>
>>
>> I think it's about writing clean and maintainable code.
>> For other developers reading back your code it makes more sense if you
>> add
>> your validation errors in the ValidateForm event and to perform some
>> (database?) action in the success handler.
>>
>> The ValidateForm event is where validation errors are added and some of
>> them
>> are automatically taken care of for you by the Tapestry validator
>> mechanism.
>> If you don't want to add more than one error-message, you can easily
>> check
>> if the field is in error already.
>> Sometimes it also makes sense to add mutiple errors per field since
>> you're
>> telling the user immediately what (s)he's doing wrong instead of having
>> them
>> re-submit again only to find yet another validation error on the same
>> field.
>>
>>
>> regards,
>>
>> Onno
>>
>
>
--
View this message in context:
http://www.nabble.com/ValidateForm-Event-tp25205192p25226000.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]