myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bernhard Huemer <bernhard.hue...@gmail.com>
Subject Re: Log each call to an JSF action method
Date Thu, 30 Aug 2007 14:41:43 GMT
Hello,

you could also use a custom ActionListener implementation if the method 
expression being processed is sufficient (for example, "Processing the 
action '#{actionBean.processAction}'."), as Andrew has already mentioned.

///
import javax.faces.component.ActionSource;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class LoggingActionListener implements ActionListener {

    private static final Log log = 
LogFactory.getLog(LoggingActionListener.class);
   
    private ActionListener delegate;
   
    public LoggingActionListener(ActionListener delegate) {
        this.delegate = delegate;
    }
   
    public void processAction(ActionEvent actionEvent)
            throws AbortProcessingException {
        if (log.isDebugEnabled()) {
            ActionSource actionSource = (ActionSource) 
actionEvent.getComponent();
            log.debug("Processing the action '" + 
actionSource.getAction().getExpressionString() + "'.");
        }

        delegate.processAction(actionEvent);
    }

}
\\\

///
// faces-config.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE faces-config PUBLIC
    "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
    "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>
   
    <application>
        <action-listener>demo.LoggingActionListener</action-listener>
    </application>
   
</faces-config>
\\\

regards,
Bernhard

Svilen Ivanov wrote:
> Andrew,
>
> I think it is fine to wait for the action to end. However, if
> NavigationHandlerImpl does it for me - all I have to do is to enable
> the log. Thank you for your reply - I'll give it a shot.
>
> Regards,
> Svilen
>
> 2007/8/29, Andrew Robinson <andrew.rw.robinson@gmail.com>:
>   
>> If you can wait until after the action has been called, you can use
>> the ActionListener of the JSF Application or the NavigationHandler as
>> both have access to the action EL expression. BTW - the myfaces
>> NavigationHandlerImpl already logs each call at debug level.
>>
>> -Andrew
>>
>> On 8/29/07, Svilen Ivanov <svilen.ivanov@gmail.com> wrote:
>>     
>>> For audit and debugging purposes I want to log the name of action
>>> method that is being called. Is it possible to hook somewhere in JSF
>>> lifecycle? Or should I use Aspect oriented approach?
>>>
>>> Any ideas are appreciated?
>>>
>>> --
>>> Svilen Ivanov
>>> http://svilen-online.blogspot.com
>>>
>>> There is no dark side of the moon really.
>>> Matter of fact it's all dark.
>>>
>>>       
>
>
>   


Mime
View raw message