Exforsys
+ Reply to Thread
Results 1 to 3 of 3

possible pattern for validation of page

This is a discussion on possible pattern for validation of page within the Software Patterns forums, part of the Testing category; Hello, I have to validate a form with a lot of fields and was wondering if there was a better ...

  1. #1
    ryanferretti@gmail.com Guest

    possible pattern for validation of page

    Hello, I have to validate a form with a lot of fields and was wondering
    if there was a better way to do this rather than just a long list of
    "if" statements. Would it be better to use a strategy for this to
    separate the code. Any suggestions for other ways?
    Thanks




  2. #2
    pven Guest

    Re: possible pattern for validation of page

    Hi,

    I am not able to suggest a pattern, however I found the
    apache struts framework very modular for validation and error handling.


    To just give a breif overview of struts, (just in case you
    are not aware of struts)...

    In struts, for every page we define a class that will hold
    all the fields in the page.

    Lets say the page has an input field called "name".
    In sruts, we will have a class for that page

    class Page extends ...{

    string name ;

    void setName (String name ) {

    }

    string getName() {
    return name ;
    }

    }

    When the form is posted, the struts engine creates
    an object of this class Page and pushes the value provided
    in the field name to the member variable name by calling the setName().

    This Page object also has a method called validate()
    where we can write the code to check if the fields in
    the form are of the right type. Again, there would be if else...
    This validate() method is automatically called by the struts engine...

    If there are errors in validation, struts has a neat way to throw
    the error back in an elagant manner.. ( error message is read from
    an message file)

    Back,

    I don't think this is the appropriate answer to your query
    but I found the struts framework very neat when building jsp pages.

    Previously, I had the validation and business logic in the jsp,
    and when there was a requirement change I needed to go through
    a lot of pain to understand the flow in a jsp that was packed with
    everything but with struts things became simpler....

    Prasanth




  3. #3
    ryanferretti@gmail.com Guest

    Re: possible pattern for validation of page

    Thanks for the reply, I have had experience with using struts and had
    considered it with for this project. We decided on using Sping MVC
    instead of struts because of what it offers.

    Ryan




    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...