• 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

regarding exception handling in struts

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can we write multiple keys for a single exception class ???
or is it necessary to uniquely identify every class with a key?

eg Class passwordexception {}

can we associate two diff errors (key pair values )
with same exception on same page (jsp)


or shud it be done this way and write unique key for every class

Class passwordcannotbenumber extends passwordexception{}
Class passwordcannotbemorethan5char extends passwordexception{}
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to our Struts fourm.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Error message keys in Struts don't have to be associated with an Exception class at all, and generally they aren't. In the example of the password checking that you just gave, the standard method of validation would be to have an ApplicationResources.properties file with these messages:

error.password.numeric=The password cannot be a number
error.password.length=The password cannot be more than 5 characters

You would then put code in the validate() method of your ActionForm to check for these conditions and if they exist, add an ActionMessage object with the appropriate key to an ActionMessages object that gets returned by the method. These messages are displayed in your JSP with the <html:errors> tag.

In this scenario, there are no Exception classes involved at all.

You can define global exceptions or action specific exceptions along with message keys, but these are intended for more "show stopping" exceptions such as "unable to establish database connection". If you don't have a try/catch block in your action that catches the exceptions first, Struts will catch these exceptions and take the appropriate action.

In the case of global and action specific exceptions, the answer to your original question is no, you can't have more than one error message associated with a single exception class.
[ August 25, 2006: Message edited by: Merrill Higginson ]
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please refrain form duplicate posting the same question in multiple forums. I have deleted the same question in the EJB J2EE Tech forum.

Thanks and good luck

Mark
 
We should throw him a surprise party. It will cheer him up. We can use this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic