• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Server side validation - not working.

 
Dean Pullen
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm trying to perform 'server-side' validation on a form, so I can allow for error text within the JSP as opposed to JavaScript pop-ups. When I attempt to use server-side validation (i.e. with no onsubmit function etc!) nothing happens - the form submits even when errors are clearly visible within form components. However when testing using the client-side validation, the JavaScript functionality works fine. Arghh.
Does anyone know what could be up with the server-side validation?
Thanks in advance.
Code example:
-----------------
StrutsConfig.xml ---
<form-bean
name="copySchedulesForm"
type="com.deano.CopySchedulesForm" />
<action
path="/CopySchedules"
type="com.deano.CopySchedulesAction"
name="copySchedulesForm"
scope="request"
validate="true">
<forward
name="success"
path=".deano.layout.copyschedules" />
<forward
name="failure"
path="/failure.jsp?type=CopySchedules" />
</action>

Validation.xml:
<formset>
<form name="copySchedulesForm"> etc etc etc
[ May 30, 2003: Message edited by: Dean Pullen ]
 
David Hibbs
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you remember to enable the validator plugin in the struts-config.xml?
i.e.
 
David Hibbs
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, and one other question... does your form extend ValidatorForm instead of just ActionForm?
 
Dean Pullen
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes as follows:
(But if I hadn't I'd imagine the client-side JavaScript wouldn't work...)
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
</plug-in>
 
Dean Pullen
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep...
public class CopySchedulesForm extends ValidatorForm { etc }
 
Dean Pullen
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see an input attribute must be added to my action decleration, which I missed out.
Thus I added:
input=".deano.layout.copyschedules"
But still no joy.
 
Sergey Smirnov
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check that CopySchedulesForm validation method calls validation from super
Check that JSP contains <html:errors /> or equivalent tags.
 
Dean Pullen
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My jsp contains the relevant logic:messagesPresent and html:errors tags
I know nothing about using the validate method in the Form though? I've not read I have to do this anywhere.
 
Sergey Smirnov
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
About validate method - "Struts In Action", Chapter 12, Page 391
http://www.theserverside.com/resources/articles/StrutsInAction/chap12.pdf
 
Dean Pullen
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I quote:
In most cases, the Struts Validator can completely replace the need to write a
custom validate method for an ActionForm. However, should you still need a
validate method, it can easily work alongside the validation framework. In most
cases, you would want to call the validator framework first, and then run your own
validations if these pass. Listing 12.8 shows how this is done.

So why am I needing to write a custom validate method when its not necessary in the usage I need? I've not read anywhere that I need to use the validate method. And I've had it working without the use of it before.
 
Sergey Smirnov
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not have to write custom validate method in this case. Just be sure that the validate method from super class is calling.
 
Dean Pullen
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So super the method and put some debugging info in it to ensure its being called?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I would do.
 
Dean Pullen
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep done that. Its not calling the Validate method at all.
Very perculiar. Any ideas?
 
Dean Pullen
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well guys/girls I seem to have sorted it.
I scrapped most of it and started again afresh, and whatever bug was there didn't creep again, thank god, changed most things.
(Now getting another error, but I'll post that elsewhere if need be).
Appreciate the help people, thanks muchly. I'll be visiting the forums on a daily basis to help out where I can, as this seems to be a cool place.
Thanks,
Dean Pullen.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic