aspose file tools*
The moose likes Struts and the fly likes xml form validation UI error message not shown? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "xml form validation UI error message not shown?" Watch "xml form validation UI error message not shown?" New topic
Author

xml form validation UI error message not shown?

Rob Hope
Ranch Hand

Joined: Mar 31, 2012
Posts: 42
I have an action.class that submits to a database from a .jsp form.
I have placed action-vaildator.xml along side my action class as documented here
http://struts.apache.org/2.2.3/docs/form-validation-using-xml.html

Although it successfully prevents data being submitted unless the required field is populated the warning message does not appear

below is my action class, vaildator .xml and jsp page





Rob Hope
Ranch Hand

Joined: Mar 31, 2012
Posts: 42
should it be
<message>First name is required.</message>
<param name="fieldName">name</param>
Rob Hope
Ranch Hand

Joined: Mar 31, 2012
Posts: 42
I changed the vaildation.xml to


<validators>
<validator type="requiredstring">
<param name="fieldname">customer.name</param>
<message>First name is required.</message>
</validator>
</validators>

but now no input is successfully validated and no UI error message is recieved
Rob Hope
Ranch Hand

Joined: Mar 31, 2012
Posts: 42
Can anyone confirm do I need a struts.properties file for struts2 .xml vaildation?
It does reference it here
http://struts.apache.org/2.3.1/docs/form-validation.html

but in this forum post it seems to provide the answer
http://www.coderanch.com/t/552422/Struts/Form-Validation-xml-struts

somthing like

label.name= OS
label.notes= notes

errors.OS= Required Field
errors.name = Reqjuired Field

Rob Hope
Ranch Hand

Joined: Mar 31, 2012
Posts: 42
humm still not seeing any warning message




Is it important to set a 'Key' variable for the field?

Rob Hope
Ranch Hand

Joined: Mar 31, 2012
Posts: 42
I think we are going down the wrong avenue here because the xml validation is working; so the correct fields are being identified its only the messages that are not being shown.

It makes me think the problem is on the .jsp view not holding the required error field

<s:form action="addCustomerAction">
<s:fielderror><s:param>name</s:param></s:fielderror>
<s:textfield name="name" key="global.name" label="OS" value=""/>
<s:textarea name="notes" key="global.notes" label="Notes" value="" cols="50" rows="5" />
<s:submit validate="true" />
</s:form>
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Hi Hope,
I never worked with struts 2 but for 1.x, however could you see what the servlet converted from JSP (from the cache) is rendering as. May be the servlet might give more insight on -from where it is trying to read the content/message.


Have Fun with Java
little,little.. little by little makes a lot..
Rees Byars
Greenhorn

Joined: Feb 13, 2012
Posts: 12
Rob, in your validation.xml you have the field specified as "customer.name", but in the jsp you have just "name". Have you tried using "customer.name" in the jsp?
Rob Hope
Ranch Hand

Joined: Mar 31, 2012
Posts: 42
That will not work

if I change the field in the .jsp to customer.name then it is impossible to successfully validate the form

<s:form action="addCustomerAction">
<s:fielderror><s:param>customer.name</s:param></s:fielderror>
<s:textfield name="customer.name" key="customer.name" label="OS" value=""/>
<s:textarea name="notes" key="global.notes" label="Notes" value="" cols="50" rows="5" />
<s:submit validate="true" />
</s:form>

Because my validation.xml is looking for a field called name

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="name">
<field-validator type="requiredstring">
<message>OS is required</message>
</field-validator>
</field>
</validators>
Rob Hope
Ranch Hand

Joined: Mar 31, 2012
Posts: 42
*bump

Still struggling with this problem;can anyone take a fresh look?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xml form validation UI error message not shown?
 
Similar Threads
result display error
Null Point Exception
Issue with Vaanilla Struts 2/Hibernate CRUD example
simple struts2 validation needed on my action class
Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]