• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Interceptor state - specification question

 
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
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • 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
 
knowledge is the difference between drudgery and strategic action -- tiny ad
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic