But then your Service Bean/DAO has to be injected into every Action
that might need to load it and the code to check for the Data Object
and load it, then store it to the context has to be Cut-n-Pasted
between each of those Actions.  Way too many chances for Cut-n-Paste
errors or incomplete fixes for my taste.  By using the Interceptor
that code is consolidated in one place and the only thing the Action
has to worry about it what it was created specifically to accomplish,
not all the other housekeeping chores.
  (*Chris*)

On Wed, Jul 9, 2008 at 6:10 PM, Gabriel Belingueres
<[EMAIL PROTECTED]> wrote:
> Wow it is amazing how S2 can be used.
> This is a use of interceptor I've never seen before.
>
> IMHO, I think it is too much trouble to declare an xxxAware interface
> and an xxxInterceptor to just share the same database data across
> multiple pages. I would stick to store the data in session or
> application scope. You have available the SessionAware and
> ApplicationAware interfaces that injects into an action a
> java.util.Map that usually is enough for testability.
>
> My own common solution to this problem would be to use Spring to
> inject a service bean into the action that would retrieve the category
> list from a cache (OSCache works great for me and has easy Spring
> integration.) When data is not in the cache or it times-out, it is
> read from the database.
>
> 2008/7/9 Chris Pratt <[EMAIL PROTECTED]>:
>> That's usually how I start.  The one thing I usually add is an Aware
>> interface that allows me to inject the value into my Actions when it's
>> needed.  So in your case I'd add a simple interface:
>>
>> interface CategoryListAware {
>>  void setCategoryList(List<Category> categories);
>> }
>>
>> And at the end of your interceptor I'd add:
>>
>> Object action = invocation.getAction();
>> if(action instanceof CategoryListAware) {
>>  ((CategoryListAware)action).setCategoryList(categoryList);
>> }
>>
>> That way you can add the Interceptor to your default stack and the
>> Actions that need the category list can have it injected without
>> having to have any knowledge about the Session.  (which makes the
>> system much easier to unit test).
>>
>>  (*Chris*)
>>
>> On Wed, Jul 9, 2008 at 3:28 PM, Dhiraj Thakur <[EMAIL PROTECTED]> wrote:
>>> Hello there,
>>>
>>> There are 4 jsp page in which i want to show same category by retrieving it
>>> from database.
>>>  What is the best way to do that? should i write a intercepter which will
>>> retrieve Category from database and store it in session?
>>> something like this
>>>
>>>
>>>        if (session.getAttribute("category") == null) {
>>>
>>>            CategoryDAO categoryDAO = new CategoryDAO();
>>>
>>>            categoryList = categoryDAO.listCategory();
>>>
>>>            session.setAttribute(ConfigAPP.CATEGORY_KEY, categoryList);
>>>
>>>            categoryList = (List)
>>> session.getAttribute(ConfigAPP.CATEGORY_KEY);
>>>
>>>            System.out.println(categoryList.size());
>>>
>>>        } else {
>>>            categoryList = categoryList = (List)
>>> session.getAttribute(ConfigAPP.CATEGORY_KEY);
>>>        }
>>>
>>>
>>> or is there any other way to do that ?
>>>
>>>
>>>
>>> *Dhiraj*
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to