• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interceptor state - specification question

 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


In the specification in the section 12.1.Overview (page 301 in my version) I found this text :

It is possible to carry state across multiple interceptor method invocations for a single business method invocation or lifecycle callback event for a bean in the context data of the InvocationContext
object.


What I understand is : if I invoke more interceptor methods with the same call (business method) I can preserve the state. The same logic for the life cycle methods.
Or more simple the state is preserved as long as I am in the same InvocationContext.

Am I right ?


Regards,
Mihai
 
Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the method invocationContext.getContextData() for getting a Map in which you can store different objects by a name.

These objects can be shared between the different interceptors.

If you use

invocationContext.getContextData().put("objectname","object") in one interceptor.

You will retrieve the value with

invocationContext.getContextData().get("objectname") in the next interceptors in the invocation chain.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, then I have an other related question.

An Interceptor can have state or not. By state I mean fields (can base its logic on the fields values).
IMHO no, with only one exception, the interceptors for the statefull bean.
I base this assumption on the next extract from "12.2 Interceptor Life Cycle"

The lifecycle of an interceptor instance is the same as that of the bean instance with which it is associated. When the bean instance is created, interceptor instances are created for each interceptor class defined for the bean. These interceptor instances are destroyed when the bean instance is removed.


Am I right ?

Regards,
Mihai
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic