Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > form validation problem with velocity-struts and errortool

Reply
Thread Tools

form validation problem with velocity-struts and errortool

 
 
Leo Gaggl
Guest
Posts: n/a
 
      04-05-2004
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.ReferenceExc eption: 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.ReferenceExc eption: 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





 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Struts validation for combine form fields validation Sumith Mathur Java 0 09-23-2004 06:26 PM
copy and paste form RTF document into field in asp form cause it to bypass field length and javascript validation - how to overcome? NotGiven Javascript 3 05-13-2004 12:15 AM
copy and paste form RTF document into field in asp form cause it to bypass field length and javascript validation - how to overcome? NotGiven ASP General 3 05-13-2004 12:15 AM
Form Validation Problem...Persisiting form fields on validation failure. bnp Javascript 4 05-12-2004 12:16 PM
Web form validation vs object validation Colin Basterfield ASP .Net 1 11-29-2003 12:10 AM



Advertisments