3

I have read carefully the article about Interceptors in the Seam/Weld documentation and implemented a InterceptorBinding:

@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface MyLog {}

and a Interceptor class:

@MyLog @Interceptor
public class ErpLogInterceptor implements Serializable
{
  @AroundInvoke
  public Object logMethodEntry(InvocationContext invocationContext) throws Exception
  {..}

  @PostConstruct
  public Object logPostConstruct(InvocationContext invocationContext) throws Exception
  {...}
}

No I tried to activated the interceptor in the @Named @ViewScoped bean:

@javax.inject.Named;
@javax.faces.bean.ViewScoped
public class MyBean implements Serializable
{
  @PostConstruct @MyLog
  public void init()
  {...}

  @MyLog public void toggleButton()
  {..}
}

If I push a button on my JSF page the method toggleButton is invoked correctly and the Interceptor method logMethodEntry is called. But it seems the method @PostConstruct (I am interested in) is never intercepted by my class.

The question seems to be related to Java EE Interceptors and @ViewScoped bean but actually my interceptor is working in normal methods.

Community
  • 1
  • 1
Thor
  • 6,607
  • 13
  • 62
  • 96
  • Are you using CODI as outlined in the answer of the linked question? The JSF-specific `@ViewScoped` otherwise simply don't work in CDI-specific `@Named`. – BalusC Nov 08 '12 at 12:37
  • Are you sure the interceptors work for lifecycle methods? – Adrian Mitev Nov 08 '12 at 20:16
  • @AdrianMitev: At least these interceptors are described in the document I'm referencing. – Thor Nov 09 '12 at 05:21
  • What happens if you use a CDI scope instead of the JSF one (yes I know Seam 3 changes it, but there may be something with the interceptors it isn't doing)? – LightGuard Nov 09 '12 at 05:50
  • @LightGuard: Changed the scope to `@javax.enterprise.context.SessionScoped`, but nothing during `@PostConstruct` – Thor Nov 09 '12 at 07:17
  • Sounds like it's probably a bug, however, we're no longer doing work on Seam 3. – LightGuard Nov 10 '12 at 06:00
  • @LightGuard: I know you're heavily involved in Seam3, and this question is most probably off-topic, but what exactly do you mean with "we're no longer doing work on Seam 3"? Can you point to a URL? – Thor Nov 10 '12 at 06:13
  • The last release was 3.1.0.Final nearly a year ago. We're putting our efforts into Apache DeltaSpike. – LightGuard Nov 10 '12 at 17:59

1 Answers1

1

You should set return type of @PostConstruct interceptor to void not Object. Change:

  @PostConstruct
  public Object logPostConstruct(InvocationContext invocationContext) throws Exception
  {...}

to:

  @PostConstruct
  public void logPostConstruct(InvocationContext invocationContext) throws Exception
  {...}
A.Panzer
  • 391
  • 3
  • 15