• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts framework

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I would like to know if it is possible for an action class to retrieve the errors validated by the struts validator framework.
Thanks.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.
 
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please note that your topic description line of Struts framework is pretty useless in a forum dedicated to Struts.
 
tanalyw tan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, sorry for putting a generic heading. Thanks for the heads up.

Thanks for the quick reply. Could you tell me how I am suppose to go about it?
I cant seems to find a way to do that. Thanks
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which version of Struts?
 
tanalyw tan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using struts 1.3.5
 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Under the Action class if there any errors , make an ActionErrors object and put data into it .

You can display the Errors on to your UI using html:errors tag

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd try getErrors() first, although if validation is set to true I don't believe your action will fire, and instead will be forwarded to the input forward.
 
tanalyw tan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i tried using getErrors() in my action. However, it doesnt even hit my action. I tried with both validation true and false. Any idea?

Following is my code

validation.xml


input.jsp


action
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It won't hit the action if you have validation turned on.

Personally, I never used automatic validation--rather turn off validation and call it manually.
 
tanalyw tan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to do validation manually in action using struts validation framework?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, either *actually* manually, by dealing with the form, or by calling the framework mechanism.

For example, I always had a base action class that went to the input forward on a GET, and called validate() on a POST.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aside, there is no html:errors element in the JSP. This is what is used to display the errors returned by the validation.
 
tanalyw tan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been trying it around and searching for tutorials. I am able to get the error message printed out using <html:errors>.
However, what I am really looking for is something like this:

When user click on the submit button, the form will be sent to the action class.
Validation using struts validation framework will be used in the action class itself, to check for errors like duplicate name (compare with values from database) etc..

However, what I am doing now is before the form reach the action, it is already validated. But that is not what I need. I need the validation to be done in the action class itself. Correct me if I am wrong.. thanks. Any idea??

Thanks for the replies, appreciate it.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just told you: turn off automatic validation. Do it manually.
 
tanalyw tan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I had heed your advice and turn off the validation. But how do you do validation in action using struts validation?

Check for errors normally and add an ActionMessage to the ActionErrors?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Call the form's validate() method if you're using the default Struts 1 validation mechanisms.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

how do you do validation in action using struts validation?



You can write the validation logic in the code of the Action class or in the ActionForm class, as already mentioned.
 
tanalyw tan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I would like to check if what I am doing is correct and comply to the struts validation framework.

I did some checking in the action class and use the following code to send the error message to the jsp.

String msg = "Error Found";
ActionMessages am = new ActionMessages();
ActionMessage msg = new ActionMessage(message, false);
am.add("error", msg);
saveErrors(request, msg);
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
saveErrors takes the request and an ActionMessages, not a single message.

As an aside, the variable name "am" is a little confusing.
 
tanalyw tan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya.. sorry for the mistake.
should be saveErrors(request, am) instead.
Thanks. I'll change the variable name
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, please UseAMeaningfulSubjectLine when posting. Explaining your question or remark briefly on the subject line allows us to know what we are getting into, and if we will be able to help. A subject of "Struts framework" in a forum dedicated to Struts isn't very helpful. Thanks!
 
tanalyw tan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okie will do. Thanks all for the help =)
 
reply
    Bookmark Topic Watch Topic
  • New Topic