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]

Reply via email to