Results 1 to 4 of 4

Thread: Validatiting User data

  1. #1

    Exclamation Validatiting User data

    Hi,
    I had a login form and want to forward to a success view once the user is valid. I wrote one class for data access. But where i can compare those values from the database with the values entered in login page.
    Please help me....
    Regards,
    Sasikanth

  2. #2

    Default

    Hi there,

    I would do all the comparison work in a LoginValidator class which can make calls to your data-access objects. The call need not return something as plain as a boolean, how about something like a LoginAudit object which contains the user object, if username was found, and various other values (boolean - password matched, int - login failures, date - last login?, etc).

    You can then pass meaningful error messages back to your login form if the login fails.

    The onSubmit(...) may then become a very small method, but can initialise any objects required for the success-view, in all likelihood the user's homepage.

    Mike

  3. #3
    Join Date
    Dec 2005
    Posts
    21

    Question

    I've been doing database access in the onBindAndValidate() method in the controller object rather than the validator class. I'm not sure which method is preferrable?

  4. #4
    Join Date
    Aug 2004
    Location
    Hawaii, US
    Posts
    225

    Default

    Quote Originally Posted by Seabamirum
    I've been doing database access in the onBindAndValidate() method in the controller object rather than the validator class. I'm not sure which method is preferrable?
    Generally, I like to put as much validation logic as I can into the Validator class. This encapsulates it better and makes it more reusable.

    However, obviously the Validator interface isn't aware of the HttpServletRequest, which sometimes you need. In that case, you can call a method on the validator passing in the request from onBindAndValidate().

    Good rule is to delegate all validation logic to a Validator, even from onBindAndValidate(). It's just not reusable inside that method.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •