form validation problem with velocity-struts and errortool

Discussion in 'Java' started by Leo Gaggl, Apr 5, 2004.

  1. Leo Gaggl

    Leo Gaggl Guest

    I have been trying to get display validation errors from a velocity
    template using the velocity-struts errortool. It seems a straight
    forward task but I can not seem to get it to work.
    I have searched eberything I can think of but apart from a few
    references to similar problems there were no actual solutions.

    Is anybody using this in a real-live setup ? i have been looking for a
    working example somewhere but can't seem to see one that uses the error
    tool.

    The setup is the following

    Validation seems to be working as the following snippet does produce
    some return errorvalues and the validator returns back to the input form

    #if ($errors.exist())
    <div id="contentArea">
    <span class="error">Test 1: $errors.getMsgs()</span><br/>
    <span class="error">Test 2:
    $errors.getMsgs("error.empl.datejoined.date")</span><br/>
    <span class="error">Test 3:
    $errors.getMsgs("error.empl.datejoined.date",
    "com.a8.administr8.employee.Employee")</span><br/>
    <ul>
    #foreach ($e in $errors.all )
    <li><span class="error">$e</span></li>
    #end
    </ul>
    </div>
    #end

    The produces $errors.getMsgs() line produces the following: Test 1:
    error.empl.datejoined.date error.empl.dateleft.date which are the two
    validation error keys that are fired.

    The #foreach loop has the following output in the logfile:
    2004-04-05 19:47:37 Velocity [warn] ActionMessagesTool: Message for
    key error.empl.datejoined.date could not be found in message resources.
    2004-04-05 19:47:37 Velocity [warn] ActionMessagesTool: Message for
    key error.empl.dateleft.date could not be found in message resources.
    2004-04-05 19:47:37 Velocity [warn]
    org.apache.velocity.runtime.exception.ReferenceException: reference :
    template = /templates/employee/empl_mod.vm [line 15,column 37] : $e is
    not a valid reference.
    2004-04-05 19:47:37 Velocity [warn]
    org.apache.velocity.runtime.exception.ReferenceException: reference :
    template = /templates/employee/empl_mod.vm [line 15,column 37] : $e is
    not a valid reference.


    validation.xml:
    ------------------------------------------------------
    <form name="employeeForm">
    <field property="employeeid" depends="required,integer">
    <msg name="required" key="error.empl.equipmentid.required"/>
    <msg name="integer" key="error.empl.equipmentid.integer"/>
    <arg0 key="error.equipmentid.displayname"/>
    </field>
    <field property="firstname" depends="required">
    <msg name="required" key="error.empl.firstname.required"/>
    <arg0 key="error.empl.firstname"/>
    </field>
    <field property="lastname" depends="required">
    <msg name="required" key="error.empl.lastname.required"/>
    <arg0 key="error.empl.lastname"/>
    </field>
    <field property="email" depends="email">
    <msg name="email" key="error.empl.email.email"/>
    <arg0 key="error.empl.email"/>
    </field>
    <field property="typeid" depends="required">
    <arg0 key="error.empl.typeid"/>
    </field>
    <field property="datejoined" depends="date">
    <msg name="date" key="error.empl.datejoined.date"/>
    <arg0 key="error.empl.datejoined"/>
    </field>
    <field property="dateleft" depends="date">
    <msg name="date" key="error.empl.dateleft.date"/>
    <arg0 key="error.empl.dateleft"/>
    </field>
    </form>
    ------------------------------------------------------


    struts-config.xml:
    ------------------------------------------------------
    <form-bean name="employeeForm" type=
    "org.apache.struts.validator.DynaValidatorForm">
    <form-property name="employeeid" type="java.lang.Integer"/>
    <form-property name="displayno" type="java.lang.String"/>
    <form-property name="title" type="java.lang.String"/>
    <form-property name="firstname" type="java.lang.String"/>
    <form-property name="middlename" type="java.lang.String"/>
    <form-property name="lastname" type="java.lang.String"/>
    <form-property name="jobtitle" type="java.lang.String"/>
    <form-property name="typeid" type="java.lang.Integer"/>
    <form-property name="datejoined" type="java.lang.String"/>
    <form-property name="dateleft" type="java.lang.String"/>
    <form-property name="address1" type="java.lang.String"/>
    <form-property name="address2" type="java.lang.String"/>
    <form-property name="town" type="java.lang.String"/>
    <form-property name="postcode" type="java.lang.String"/>
    <form-property name="state" type="java.lang.String"/>
    <form-property name="country" type="java.lang.String"/>
    <form-property name="phone" type="java.lang.String"/>
    <form-property name="fax" type="java.lang.String"/>
    <form-property name="mobile" type="java.lang.String"/>
    <form-property name="email" type="java.lang.String"/>
    <form-property name="sms" type="java.lang.String"/>
    <form-property name="pager" type="java.lang.String"/>
    <form-property name="instmsgid" type="java.lang.String"/>
    <form-property name="msgprotocolid" type="java.lang.Integer"/>
    <form-property name="act" type="java.lang.String"/>
    </form-bean>
    ------------------------------------------------------


    The errortool is declared in toolbox.xml and the messages for the keys
    are in the application resource file as well as in a seperate properties
    file which works elsewhere on the same velocity template


    Any takers ? Any suggestions and pointers would be much appreciated. I
    am going blind here.

    Could there be a version conflict between:

    struts-1.1.jar
    velocity-1.3.1.jar
    velocity-tools-1.1-dev.jar

    Thanks in advance !

    --

    Leo Gaggl
    Adelaide, South Australia
     
    Leo Gaggl, Apr 5, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sumith Mathur
    Replies:
    0
    Views:
    2,206
    Sumith Mathur
    Sep 23, 2004
  2. Tarkin

    Struts + Velocity + GWT

    Tarkin, May 8, 2007, in forum: Java
    Replies:
    7
    Views:
    2,000
    sokol
    Jun 25, 2007
  3. HemantS
    Replies:
    0
    Views:
    395
    HemantS
    Jun 12, 2007
  4. HemantS
    Replies:
    0
    Views:
    788
    HemantS
    Jun 12, 2007
  5. bond
    Replies:
    1
    Views:
    3,207
    Mark Jeffcoat
    Jun 28, 2007
Loading...

Share This Page