facebook

Struts validating data

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #260017 Reply

    Bobby
    Member

    My question is pertaining to the Struts Form validation

    Here is the scenario in Struts:

    (1) Once you submit a form, ActionServlet checks for the required Action class and the ActionForm class that is associated with the form submission action.

    (2) The input that user provided prior to submitting the form, is checked in the validate method of ActionForm class.

    Now my question is, if a validation is to be performed against the database.

    Say for example, user inputs an employee id in the form field and I need to check whether the employeeId exists in the database table, I will have to call the database object layer in the ActionForm class.

    Doesn’t it violate the MVC pattern in that, you should not call a DAO(database access object) from within the front-end(html, jsp). I am assuming that ActionForm is a part of the presentation rather than a Model and I think you should not call DAO from ActionForm. Am I correct with this assumption?

    Thanks in advance!!!
    -Bhavin

    #260163 Reply

    Riyad Kalla
    Member

    Bhavin,
    This is a great question. A general rule of thumb is to keep your Form validation implementations as light weight as possible. So any DB validation that you need, place it at the top of your Action implementation. So the form, for example, can validate all the basic values then the action can validate the actual values of those fields against the DB if need be.

    Some people feel that *all* validation should be in the Form, it’s up to you, I know that in writing Struts app, as much as I wanted to have all validation in the Form, some more complex validation ended up in the Actions anyway, so now I try and keep all complex validation in the actions and simple validation in the form.s

    #260256 Reply

    Bobby
    Member

    Thanks for the reply, Riyad. I helped a lot.

    #260257 Reply

    Riyad Kalla
    Member

    No problem, glad it helped.

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Struts validating data

You must be logged in to post in the forum log in