Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xml form validation UI error message not shown?

 
Rob Hope
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
should it be
<message>First name is required.</message>
<param name="fieldName">name</param>
 
Rob Hope
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
humm still not seeing any warning message




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

 
Rob Hope
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rees Byars
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
*bump

Still struggling with this problem;can anyone take a fresh look?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic