File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Server side validation - not working. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Server side validation - not working." Watch "Server side validation - not working." New topic
Author

Server side validation - not working.

Dean Pullen
Ranch Hand

Joined: May 30, 2003
Posts: 58
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

Joined: Dec 19, 2002
Posts: 374
Did you remember to enable the validator plugin in the struts-config.xml?
i.e.


"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
David Hibbs
Ranch Hand

Joined: Dec 19, 2002
Posts: 374
Oh, and one other question... does your form extend ValidatorForm instead of just ActionForm?
Dean Pullen
Ranch Hand

Joined: May 30, 2003
Posts: 58
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

Joined: May 30, 2003
Posts: 58
Yep...
public class CopySchedulesForm extends ValidatorForm { etc }
Dean Pullen
Ranch Hand

Joined: May 30, 2003
Posts: 58
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

Joined: May 29, 2003
Posts: 167
Check that CopySchedulesForm validation method calls validation from super
Check that JSP contains <html:errors /> or equivalent tags.
Dean Pullen
Ranch Hand

Joined: May 30, 2003
Posts: 58
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

Joined: May 29, 2003
Posts: 167
About validate method - "Struts In Action", Chapter 12, Page 391
http://www.theserverside.com/resources/articles/StrutsInAction/chap12.pdf
Dean Pullen
Ranch Hand

Joined: May 30, 2003
Posts: 58
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

Joined: May 29, 2003
Posts: 167
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

Joined: May 30, 2003
Posts: 58
So super the method and put some debugging info in it to ensure its being called?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
That's what I would do.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Dean Pullen
Ranch Hand

Joined: May 30, 2003
Posts: 58
Yep done that. Its not calling the Validate method at all.
Very perculiar. Any ideas?
Dean Pullen
Ranch Hand

Joined: May 30, 2003
Posts: 58
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Server side validation - not working.