Results 1 to 2 of 2

Thread: (ww2 issue)What is the function of validator type "visi

  1. #1
    Join Date
    Sep 2004
    Location
    China
    Posts
    17

    Default (ww2 issue)What is the function of validator type "visi

    The documents of Webwork2 are too lacking. So i come here to turn to you spring's gurus.

    The reference saying,
    Visitor
    Allows you to forward validation to object properties of your action using the object own validate files
    It has no even a example to illustrate how to use it.(But all others have)

    It's better to provide a snippet of example code to illustracte how to use it.

    Thanx in advance.

    Regards.
    Yoshiyan

  2. #2
    Join Date
    Aug 2004
    Posts
    16

    Default

    Your question would be better sent to the webwork mailing list but here goes. Visitor allows you to centralize the validation for a single class in a single file. Why would this be useful? Suppose you have two actions, CreateGame and UpdateGame. They are responsible for creating and updating instances of com.eg.Game. The default webwork validation files would be org/eg/CreateGame-validation.xml and org/eg/UpdateGame-validation.xml. Without visitor validation you would be forced to repeat your validation logic in both files. However, suppose in both actions your Game is accesible via getModel() (ie your action implements ModelDriven). In this case you can simply use

    Code:
    <field name="model">
            <field-validator type="visitor">
                <param name="appendPrefix">false</param>
                <message/>
            </field-validator>
    </field>
    in both files. This validator checks the type of model and then looks for validation files matching its class hierarchy. So in this case assuming Game implements no interfaces and extends no classes it would execute the validation in org/eg/Model-validation.xml. If the instance returned by getModel() is of type Monopoly (extending Game) it would execute the validation in both org/eg/Game-validation.xml and org/eg/Monopoly-validation.xml.

Similar Threads

  1. Oracle Function returning a REF CURSOR
    By jacarlso in forum Data
    Replies: 3
    Last Post: Oct 24th, 2007, 09:44 PM
  2. Replies: 2
    Last Post: Oct 13th, 2005, 09:58 AM
  3. Replies: 4
    Last Post: Sep 21st, 2005, 09:06 AM
  4. Replies: 2
    Last Post: Apr 21st, 2005, 01:14 PM
  5. Replies: 0
    Last Post: Apr 6th, 2005, 07:55 AM

Posting Permissions

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