You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Puneet Agarwal <pu...@delhi.tcs.co.in> on 2003/05/21 09:06:08 UTC

[Solved ; but ???.]Declarative Excp Handling and Error Categorries

Hi All,
I got the answer to my question.

All I had to do was RTFC(C=Code)

Here is the solution:

If we have all our exception classes a child of
org.apache.struts.util.ModuleException and
after creating the exception class, we should call the method setProperty()
to set the key. Here property is the variable against which
it stores the ActionError object in ActionErrors class.

If we don't call the setProperty method, it will use the same key for both
creating the ActionError object
and
adding the ActionError object to ActionErrors

This was how I could solve my problem.

Would be greatful if some commiter could say as to why has this been done,
this way.
should it not have the two different?

Regards,
Puneet Agarwal

Tata Consultancy Services,
C-56, Phase - II, NOIDA 201305 (India)
Phone: +91-120-2461001, 2, 7, 8, 9, 12, 13 (Ext. 1031)
FAX              : +91-120-246 1521

Struts ... Action ... Struts in Action ... Action in Struts ... Action
"with" Struts ...
----- Forwarded by Puneet Agarwal/PLs/TCSDELHI/TCS on 05/21/03 12:23 PM
-----
                                                                                                                     
                    "Puneet                                                                                          
                    Agarwal"               To:     struts-user@jakarta.apache.org                                    
                    <puneeta@delhi.        cc:                                                                       
                    tcs.co.in>             Subject:     Declarative Excp Handling and Error Categorries              
                                                                                                                     
                    05/20/03 07:56                                                                                   
                    PM                                                                                               
                    Please respond                                                                                   
                    to "Struts                                                                                       
                    Users Mailing                                                                                    
                    List"                                                                                            
                                                                                                                     
                                                                                                                     




We have implemented, Error categories with the help of ActionErrors.

Following is the example code that we used

The action class contains......
ActionErrors errors = new ActionErrors();
errors.add(Constants.ERROR, new ActionError("ER.00001"));
errors.add(Constants.WARNING, new ActionError("ER.00002"));
errors.add(Constants.FATAL, new ActionError("ER.00003"));
errors.add(Constants.SUGGESTION, new ActionError("ER.00004"));
saveErrors(request, errors);

A common TILE contains...
<logic:messagesPresent property="<%=Constants.FATAL %>">
  <html:messages property="<%=Constants.FATAL %>" id="fatal">
  <script>
    setFatal('<bean:write name="fatal"/>')
  </script>
  </html:messages>
</logic:messagesPresent>

and so on for error, warning and suggestions.

We want to use Declarative exception handling and utilise the above
infrastrucure for showing the errors.

if I define an exception for my action class  in struts-config.xml as
<exception type="com.tiger.inf.exceptions.MyException" path
="/pages/MNT0250S.jsp" key="info" scope="request"/>

It looks for the key "info" in application resource file and also stores
the ActionError against the same key.

Should the two keys not be different,
 is it a bug, or has this been done intentionally.

I want to store the exceptions against a key as "Constants.ERROR" and use
different key to be looked into the application resource file for every
exception.

How Can I achieve this.




---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org