How to intercept only the public methods of a managed bean?

2

If you have a managed bean (annotation @ManagedBean), how could you intercept only the public methods of this bean?

The motivation for this would be as follows, suppose you have a ControllerBean bean that can be accessed from an xhtml page. But, you wanted that when any public method of this bean was accessed, it would go through another method before it would check whether the user is allowed to access that area or not. If it does not, that area would not be accessed.

How can we do this? Could someone give me a working example?

    
asked by anonymous 09.06.2014 / 03:44

1 answer

1

You can use Interceptor . The problem is that they, as far as I know, do not work with @ManagedBeans, only with beans via CDI and EJB. What you can do in this case is to change your bean to @Named instead of @ManagedBean

Here is a very clear and simple example of how to work with interceptors: link

Hugs.

    
09.06.2014 / 13:51