Page 1 of 1

How to implement my own CustomerState?

Posted: Sun Jul 06, 2014 12:25 pm
by gowthamgutha
I would like to write a class that is like the CustomerState. But that takes different parameters other than Customer type.
So, I would like to write new classes corresponding to that type.

Could you explain me what these classes do..

    CustomerState
    CustomerStateRefresher
    CustomerStateInterceptor
    CustomerStateRequestProcessor

and any if I have missed (related to this)? What each classes do and the architectural flow of it? When and where the customer attribute is added to the templates and when it is removed etc?

Thanks in advance. Hope you will reply as soon as possible.

Re: How to implement my own CustomerState?

Posted: Tue Jul 08, 2014 2:44 am
by phillipuniverse
CustomerState - a request-attribute-based DTO object that just provides a convenient way to grab the current Customer
CustomerStateRefresher - this ensures that the Customer object in CustomerState is always the most recent one from the database. Whenever a Customer is saved, this component goes and updates CustomerState with the saved version of the customer.
CustomerStateInterceptor - not required to be used when you are in a servlet application (CustomerStateFilter is used instead) but this can be used for non-servlet applications where you are still using Spring MVC (like Java Portlets)
CustomerStateRequestProcessor - the thing that is responsible for looking up the Customer and populating CustomerState on every request. This was generalized into a common component that both the CustomerStateFilter (used in Servlet applications) and CustomerStateInterceptor (used in non-servlet applications like Portlets) can use.