• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Trouble with struts validator

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
yacout dadoun
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
-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
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<form?

Are you not using <html:form ?
(Also, the id attribute is not necessary for html:errors to function)
 
yacout dadoun
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm running thin on ideas.

Are you declaring the taglib uri for "html" in your jsp?
 
yacout dadoun
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes i 've added the struts-html.tld uri
 
yacout dadoun
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
-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
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
There are 29 Knuts in one Sickle, and 17 Sickles make up a Galleon. 42 tiny ads in a knut:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic