aspose file tools*
The moose likes Struts and the fly likes Trouble with struts validator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Trouble with struts validator" Watch "Trouble with struts validator" New topic
Author

Trouble with struts validator

yacout dadoun
Greenhorn

Joined: Oct 05, 2004
Posts: 11
Hi,

I'm trying to use the struts validator, i have created a simple form with few inputs, i'd like to oblige the user to enter values into inputs.
I therefore :
1-added the validator pluing to strus-config.xml
2-added the action mapping with the path set to test, the type set to the path of the action form called TestAction, the name set to testForm, validate set to true and inut set the the jsp file called siteForm.jsp and forwards success and failure
3-created the TestAction.java taht extends Action and returns success
4-created the TestForm bean that extends ValidatorAction
5-created the testform.jsp added <html:errors/>whose fomr id is testForm
6-get teh applictaion.properties file from the struts blank project
7-in the validation.xml added the formset where the name is testForm and properties are required

However no errors is displayed

Any idea PLS

Thanks
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

My guess is the problem is probably in item 4 or 5.

In 4, I imagine you have it extending ValidatorActionForm. Did you override the validate method? If so, your method must add its ActionErrors given from super.validate to the one you are returning.

You say that no errors are displayed. I assume this means that the page is forwarded to the input. So validation works but no errors are displayed.

You mentioned in 5 something about a form id. I am not sure what you mean by that. There is no such attribute for that tag.


A good workman is known by his tools.
yacout dadoun
Greenhorn

Joined: Oct 05, 2004
Posts: 11
-No in item 4 i extend ValidatorForm not ValidatorActionForm
Yes i have added the super ActionErrors to mine

-Yes obviously validation wors but no errors a redusplayed cause whne i debug in item 4 i can see the errors

-in item 5 i said the form id is testForm (<form id="testForm" action="....> and this is the name i use in the validation.xml for the form name

Thanks
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

<form?

Are you not using <html:form ?
(Also, the id attribute is not necessary for html:errors to function)
yacout dadoun
Greenhorn

Joined: Oct 05, 2004
Posts: 11
No i'm not using <htm:form cause i'm trying to use jstl and as long as i have not found another way to display errors i wanted to test with <html:errors/> is this a problem ?
yacout dadoun
Greenhorn

Joined: Oct 05, 2004
Posts: 11
I switched my simple test to struts and used <html:form etc .. but still nothing is displayed in the <html:errors/>
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

I'm running thin on ideas.

Are you declaring the taglib uri for "html" in your jsp?
yacout dadoun
Greenhorn

Joined: Oct 05, 2004
Posts: 11
yes i 've added the struts-html.tld uri
yacout dadoun
Greenhorn

Joined: Oct 05, 2004
Posts: 11
What is weird is that in the validate method of the testForm, i can display the errors however i can't in the testAction, even when using the form.validate(mapping,request) in the testAction.
There are no erros in the testAction however there are errors in the testForm validate

Thanks
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

If you had validate set to true in the ActionMapping it should never enter the Action in the first place. It will run the validation automatically and return the input forward if validation fails, without ever entering the Action.

If, however, you do not set validate to true in the ActionMapping and call form.validate from Action, you should do this:
errors.add(form.validate(mapping, request));
if(!errors.isEmpty()){
saveErrors(request, errors);
return mapping.getInputForward();
}

Hope this does the trick.
[ October 06, 2004: Message edited by: Marc Peabody ]
yacout dadoun
Greenhorn

Joined: Oct 05, 2004
Posts: 11
-the validate is set to true and the validation is automticaly called however i can't get the errors to be displayed in teh jsp file
nor in the Action its like in teh Action, when it calls explicitally the validate, there is no more errors which is not true

errors.add(form.validate(mapping, request));
if(!errors.isEmpty()){
saveErrors(request, errors);
return mapping.getInputForward();
}
also did not work it gives no error
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

nor in the Action its like in teh Action, when it calls explicitally the validate, there is no more errors which is not true

It should never touch the Action if:
1) validate is set to true and
2) the form's validate method returns an ActionErrors that is not empty.
yacout dadoun
Greenhorn

Joined: Oct 05, 2004
Posts: 11
As i'm using struts1.4, and that ActionErrors have been deprecated i tried using ActionMessages as the following
<html:messages id="error"/>
<%= error %>
</html:messages>
But i get an error saying the end tag "<html:messages" is unbalanced
yacout dadoun
Greenhorn

Joined: Oct 05, 2004
Posts: 11
When i replaced <html:messages id="error"> by <html:messages id="error"/>, i no more have errors
And when i use
<html:messages id="error">
<%= messsages%>
</html:messages>

when there is an error, it displays null otherwise it displays nothing
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble with struts validator