Yea, you can't use the same exception class for 
different exception elements. The RequestProcessor looks 
up the exception element to use based on the exception  
type. You would need to have different exceptions 
specified in the "type" attribute for each exception 
element.

Here's a thought. Extend the RequestProcessor and 
override the processException() method. The exception 
object is one of the arguments in the method. Use the 
exception to get your specific exception code.

Then create your own ExceptionHandler that uses the 
exception code to lookup the proper key and creates the 
ActionError and stores it. 

So, you might have to extend 2 classes, but it should be 
very little work to do this and modify the behavior.

Someone else may have a better idea, but this shouldn't 
be that bad. Again, the only reason the framework can't 
do this for you is because you have the same exception 
class for different exception types.

Chuck
> Chuck,
> 
> I have already tried that but I wonder if it works. In my case struts-config
> looks like below.  
>     <global-exceptions>
>         <exception
>             key="service.id.null"
>             type="java.myexception.GenericException"
>             path="/error.jsp"/>                               
>        <exception
>             key="template.id.null"
>             type="java.myexception.GenericException"
>             path="/error.jsp"/>
> 
>     </global-exceptions> 
> 
> Now whenever java.myexception.GenericException is thrown, the message
> corresponding to last entry is getting displayed, i.e., message corresponding
> to "template.id.null" key. Please correct me if I am wrong.
> 
> -Harvinder
> 
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Monday, October 07, 2002 10:06 PM
> To: Struts Users Mailing List
> Subject: RE: Declarative Exception handling with Struts 1.1-b2
> 
> 
> Ah, I see the confusion. The Struts framework will use 
> the value from the "key" attribute in the exception 
> element to automatically build ActionErrors for you. You 
> just need to use the <html:errors> tag to display them.
> 
> To see where in the framework all of this takes place, 
> check out the source code for the ExceptionHandler class.
> 
> Hope this helps,
> 
> Chuck
> > Thanks Chuck,
> > 
> > Actually we are porting existing code and hence there are pre defined set
> of
> > Exception classes and we have decided not to add any more exception
> classes.
> > We are using error code to identify the exact problem.
> > 
> > >In your case, since you want all errors to go to the same 
> > >page, the path attribute would be "error.jsp" for all of 
> > >your exception elements. 
> > 
> > I agreed that I can define path variables for all the keys to "error.jsp",
> > like
> > <global-exceptions>
> >         <exception
> >             key="name.not.found"
> >             type="com.myexception.ServiceException"
> >             path="/error.jsp"/>                   
> > 
> >      <exception
> >             key="name.system.error"
> >             type="com.myexception.SystemException"
> >             path="/error.jsp"/>
> > 
> > </global-exceptions>
> > 
> > But how do I fetch corresponding error message in my "error.jsp" file.
> Don't
> > I need to hardcode the "key" in the "error.jsp" like below. If not, please
> > point out how do I do it.
> > 
> > --------------------------------------------------------------
> > <%@ page language="java" %>
> > <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
> > <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
> > 
> > 
> > <html>
> > 
> > <p><b>Error Message is :- <bean:message key="name.not.found"/> </b></p>
> > 
> > </html>
> > 
> > -------------------------------------------------------------------
> > 
> > Thanks,
> > Harvinder
> > 
> > -----Original Message-----
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, October 07, 2002 8:44 PM
> > To: Struts Users Mailing List
> > Subject: RE: Declarative Exception handling with Struts 1.1-b2
> > 
> > 
> > I may be misunderstanding your situation completely. If 
> > I have, I apologize ahead of time. Here's the short 
> > version of what I think.
> > 
> > Can you not throw more specific exceptions, ones that 
> > imply a little more about what went wrong? Then setup 
> > exception elements in the global section (or in the 
> > Action mappings if they are specific to the Action) and 
> > configure the application resource key for that specific 
> > exception.
> > 
> > I'm sure you understand this, but let me emphasize 
> > anyway, the point of declarative exception handling is 
> > that you shouldn't have to do anything programmatically 
> > to display errors. You specify what the error page is 
> > using the "path" attribute in the exception element. In 
> > your case, since you want all errors to go to the same 
> > page, the path attribute would be "error.jsp" for all of 
> > your exception elements. 
> > 
> > Does that make sense? Again, let me know if I 
> > misunderstood the question completely.
> > 
> > Chuck
> > > Chuck,
> > > 
> > > I have gone through this chapter but I didn't find anyway to retrieving
> key
> > > during run time for declarative exception handling. My requirement is to
> > > maintain single error.jsp file, and hence the error key should not be
> > > hardcoded. I am specifying a global exception, say, java.lang.Exception
> and
> > > for two different situation and I am throwing new Exception("key1"), and
> > new
> > > Exception(key2). I would love to get key (key1 or key2) in runtime and
> > > replacing it will appropriate messages from
> ApplicationResources.properties
> > > file. Please point out if I missed sth in chapter 10 and there is a way
> to
> > > handle the situation I mentioned above.
> > > 
> > > Thanks,
> > > Harvinder
> > > 
> > > 
> > > -----Original Message-----
> > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> > > Sent: Monday, October 07, 2002 5:50 PM
> > > To: Struts Users Mailing List
> > > Subject: Re: Declarative Exception handling with Struts 1.1-b2
> > > 
> > > 
> > > If you haven't already, may I suggest you download the 
> > > draft of Chapter 10 from my book. It covers Struts and 
> > > Exception Handling (both programmatic and declarative). 
> > > 
> > > Here's a link:
> > > http://www.theserverside.com/resources/strutsreview.jsp
> > > 
> > > Sorry for the shameless plug, but I think the material 
> > > will help.
> > > 
> > > Chuck
> > > > Hi,
> > > > Can anybody help me in understanding declarative exception handling
> with
> > > > Struts1.1b2? My requirement is maintaining only single "error.jsp"
> file,
> > > > which should be displayed when an exception is thrown. We are having
> > > multiple
> > > > exception classes and when an exception is thrown an error id is
> > associated
> > > > with it to get appropriate message. If I put all the error code vs
> error
> > > > messages in ApplicationResources.properties, there should be a way to
> > fetch
> > > > the error code from the thrown exception, and then displaying the
> > > appropriate
> > > > message. Any help is appriciated.
> > > > Thanks,
> > > > Harvinder
> > > > 
> > > > --
> > > > To unsubscribe, e-mail:
> > > <mailto:[EMAIL PROTECTED]>
> > > > For additional commands, e-mail:
> > > <mailto:[EMAIL PROTECTED]>
> > > > 
> > > 
> > > --
> > > To unsubscribe, e-mail:
> > <mailto:[EMAIL PROTECTED]>
> > > For additional commands, e-mail:
> > <mailto:[EMAIL PROTECTED]>
> > > 
> > > 
> > > --
> > > To unsubscribe, e-mail:
> > <mailto:[EMAIL PROTECTED]>
> > > For additional commands, e-mail:
> > <mailto:[EMAIL PROTECTED]>
> > > 
> > 
> > --
> > To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
> > 
> > 
> > --
> > To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
> > 
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> 

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to