Announcement Announcement Module
Collapse
No announcement yet.
(ww2 issue)What is the function of validator type "visi Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • (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
    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.

    Comment

    Working...
    X