It´s quite easy to change the handling for invoking action methods.
Simply wrap existing ActionListener Implementation of processAction
with an try and catch block:

FacesContext context = FacesContext.getInstance();
final ActionListener actionListener =
context.getApplication().getActionListener();
ActionListener wrappedActionListener = new ActionListener()
{
  public void processAction(ActionEvent actionEvent) throws
AbortProcessingException
 {
  try
  {
   actionListener.processAction(actionEvent);
  }
  catch(Throwable t)
  {
   // do generic action exception handling here
  }
 }
}
context.getApplication().setActionListener(wrappedActionListener);

You can implement it in a
javax.servlet.ServletContextListener.contextInitialized() method. and
register the listener in your web.xml file.

2005/11/5, Mike Kienenberger <[EMAIL PROTECTED]>:
> It doesn't appear that there's an easy way to do this.
> The events are triggered from UIComponentBase.broadcast() which calls
> each event.processListener() method which calls
> ActionListener.processAction() which calls methodBinding.invoke().
>
> Ideally, you'd want to specify a custom methodBinding.invoke() that
> wrapped the error for you.   Facelets does things differently -- maybe
> there's a way to create alternate MethodBinding rules for
> ActionSources which create your subclass of MethodBinding rather than
> the default MethodBinding instances.   You could try asking about that
> on the facelets mailing list.
>
> Another possiblity is to use aspect-oriented-programming (AOP) to
> intercept methodBinding.invoke().   However, I don't use AOP, so I
> can't tell you anything beyond that it appears to do what you need.
>
> On 11/5/05, Robert Parsons <[EMAIL PROTECTED]> wrote:
> >  Hi,
> >
> >  thanks for the reply. the wording of my question was a little bit off. I
> > was looking for an automatic way for Exceptions that were thrown in any
> > action method to automatically be added as a message (instead of the
> > horrible error screens i get from facelets at the moment).
> >
> >  The only other option other than an automatic method would be to wrap a
> > try-catch around all the code of every action I have and generate a message
> > when an exception is caught. Sounds like that might have to be the way I do
> > it.
> >
> >  Thanks anyway,
> >  -Robert.
> >
> >
> >  Volker Weber wrote:
> >  Hi,
> >
> > you can add a Message to FacesContect.
> >
> > See:
> > http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/api/javax/faces/context/FacesContext.html#addMessage(java.lang.String,%20javax.faces.application.FacesMessage)
> >
> > regards
> >  Volker
> >
> > Robert Parsons wrote:
> >
> >
> >  Hi,
> >
> > Is there an easy way to make exceptions thrown by action methods (on
> > backing beans) to generate messages? Or would this only be possible by
> > modifying the MyFaces code.
> >
> > Thanks heaps,
> > -Robert
> >
> >
> >
> >
> >
>


--
Mathias

Reply via email to