views:

157

answers:

1

Hello colleagues!

At first some precondition to my question, I'm using struts2 + tiles2 + toplink. NO spring at all. The simplest scenario - is to display list of entities on the page. To optimize resolving JPA's EntityManager I would like to create helper (JPAResourceBean) that implements lazy load of entity manager. For this purposes I'm going to use struts2's bean declaration:

<bean  name="myfactory" class="my.model.JPAResourceBean" 
       scope="session" optional="false"/>

Why bean is not instantiated neither in session? (I'm using s:property just for debug)

...
<s:property value="#session.myfactory" default="buka.1"/>
...

nor in plain bean list:

...
<s:property value="#myfactory" default="buka.2"/>
...

May be the second part of question is - how to resolve this bean from java code?

A: 

I've found solution.

The matter is struts using lazy load (resolve on demand) approach to instantiate beans, so my JPAResourceBean was successfully resolved when I've accessed it over following syntax:

ActionContext.getContext().getContainer().getInstance(JPAResourceBean.class);
Dewfy

related questions