Re: [S2] ModelDriven, Preparable and SessionAware do not work with Spring

2007-03-12 Thread Shih Lee

Hi All,

I managed to achieve what I wanted by using Struts 2 interceptor without
having Spring aoping the action class through dynamic proxy. Here is the
updated example.xml:

http://struts.apache.org/dtds/struts-2.0.dtd";>












   

/example/HelloWorld.jsp



/example/Login.jsp
Menu



/example/Menu.jsp





/example/{1}.jsp







An updated TimeLoggingInterceptor.java:

package interceptor;

import org.apache.log4j.Logger;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class TimeLoggingInterceptor extends AbstractInterceptor {

protected final Logger logger = Logger.getLogger(getClass());

public String intercept(ActionInvocation invocation) throws Exception {

long startTime = System.currentTimeMillis();

String result = invocation.invoke();

long endTime = System.currentTimeMillis();

logger.info("MenuAction: Time took = " + (endTime - startTime) 
+ " ms");

return result;
}
}

So, I think it is better to go through the framework interceptor (Struts 2)
to aop the action class instead of using Spring interceptor. For other
purpooses, we can use Spring interceptors.

Thanks http://www.nabble.com/file/7125/applicationContext.xml
applicationContext.xml ,
Lee


Shih Lee wrote:
> 
> 
> Hi All,
> 
> I think I know what is the trouble but am still not sure why is this a
> problem for Struts 2.0. I hope someone from the Struts community can help
> to
> shed some light.
> 
> The problem is when I use
> "org.springframework.aop.framework.ProxyFactoryBean" to AOP the Action
> class. Once I remove the AOP piece such as the following, everything work
> just fine:
> 
> 
>   
>   
> 
> Any help is appreciated!
> 
> Thanks,
> Lee
> 
> 
> Shih Lee wrote:
>> 
>>  Hi All,
>> 
>> I have been playing with Struts 2.0 sample application, struts-blank, and
>> integrates it with Spring 2.x. So far, I have not been having great
>> success
>> with it.
>> 
>> 
>> 
>> I have followed all the steps needed to integrate Struts 2.0 with Spring
>> 2.0.
>> Here is what I have done so far:
>> 
>> 1) Included struts2-spring-plugin-2.0.6.jar, spring.jar,
>> struts2-core-2.0.6.jar and the dependent jars.
>> 
>> 2) Modified the example.xml to include spring object factory:
>> 
>>> Configuration 2.0//EN"
>> "http://struts.apache.org/dtds/struts-2.0.dtd";>
>> 
>>
>> 
>>   
>>   > extends="struts-default">
>> 
>>   
>> 
>> 
>> /example/HelloWorld.jsp
>> 
>> 
>> 
>> /example/Login.jsp
>> Menu
>> 
>> 
>> 
>> /example/Menu.jsp
>> 
>> 
>> 
>> /example/{1}.jsp
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 3) I have edited the spring applicationContext.xml
>> 
>>   
>> 
>>   > http://www.springframework.org/dtd/spring-beans.dtd";>
>> 
>>   
>> 
>>   
>> 
>>   > class="advice.TimeLoggingInterceptor"/>
>> 
>>   
>> 
>>   
>> 
>> 
>>
>>   execute
>>
>>  
>> 
>>   
>> 
>>   
>> 
>>   
>> 
>>   > singleton="false"/>
>> 
>>   
>> 
>> 
>>   example.IMenu
>> 
>> 
>>
>>   
>> timeLoggingAdvisor
>>   
>> 
>> 
>>   
>> 
>>   
>> 
>> 
>>   
>> 
>> 
>> 4) Implemented ModelDriven, Preparable and SessionAware interfaces in
>> Menu.java:
>> 
>> package example;
>> import java.util.Map;
>> import org.apache.struts2.interceptor.SessionAware;
>> import com.opensymphony.xwork2.ModelDriven;
>> import com.opensymphony.xwork2.Preparable;
>> 
>> /**
>> 
>>  * Set welcome message.
>> 
>>  */
>> 
>> public class Menu extends ExampleSupport implements IMenu, ModelDriven,
>> Preparable, SessionAware {
>> 
>> private Map _session;
>> 
>> private User user;
>> 
>> public String execute() throws Exception {
>> 
>> return SUCCESS;
>> 
>> }
>> 
>> public Object getModel() {
>> return user;
>> }
>> 
>> public void prepare() throws Exception {
>> if (getSession().get("user") != null) {
>> user = (User)
>> getSession().get("user");
>> } else {
>> user = new User();
>> 

ModelDriven, Preparable and SessionAware do not work with Spring

2007-03-08 Thread Shih-gian Lee

Hi All,


I think I know what is the trouble but am still not sure why is this a
problem for Struts 2.0. I hope someone from the Struts community can help to
shed some light. Or what is the recommended way of aoping the action class
if spring proxy is not the route to go.

The problem is when I use "
org.springframework.aop.framework.ProxyFactoryBean" to AOP the Action class.
Once I remove the AOP piece such as the following, everything work just
fine:



   



Any help is greatly appreciated!

Thanks,
Lee


Re: [S2] ModelDriven, Preparable and SessionAware do not work with Spring

2007-03-08 Thread Adam Ruggles
One quick thing I see wrong is you have singleton="false" that is a 
spring 1 attribute.


Shih Lee wrote:

Hi All,

I think I know what is the trouble but am still not sure why is this a
problem for Struts 2.0. I hope someone from the Struts community can help to
shed some light.

The problem is when I use
"org.springframework.aop.framework.ProxyFactoryBean" to AOP the Action
class. Once I remove the AOP piece such as the following, everything work
just fine:





Any help is appreciated!

Thanks,
Lee


Shih Lee wrote:
  

 Hi All,

I have been playing with Struts 2.0 sample application, struts-blank, and
integrates it with Spring 2.x. So far, I have not been having great
success
with it.



I have followed all the steps needed to integrate Struts 2.0 with Spring
2.0.
Here is what I have done so far:

1) Included struts2-spring-plugin-2.0.6.jar, spring.jar,
struts2-core-2.0.6.jar and the dependent jars.

2) Modified the example.xml to include spring object factory:

   http://struts.apache.org/dtds/struts-2.0.dtd";>

   

  
  

  


/example/HelloWorld.jsp



/example/Login.jsp
Menu



/example/Menu.jsp



/example/{1}.jsp







3) I have edited the spring applicationContext.xml

  

  http://www.springframework.org/dtd/spring-beans.dtd";>

  

  

  

  

  


   
  execute
   
 

  

  

  

  

  


  example.IMenu


   
  
timeLoggingAdvisor
  


  

  


  


4) Implemented ModelDriven, Preparable and SessionAware interfaces in
Menu.java:

package example;
import java.util.Map;
import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

/**

 * Set welcome message.

 */

public class Menu extends ExampleSupport implements IMenu, ModelDriven,
Preparable, SessionAware {

private Map _session;

private User user;

public String execute() throws Exception {

return SUCCESS;

}

public Object getModel() {
return user;
}

public void prepare() throws Exception {
if (getSession().get("user") != null) {
user = (User)
getSession().get("user");
} else {
user = new User();
}
}


public void setSession(Map session) {
_session = session;
}


public Map getSession() {
return _session;
}
}

When I let Spring manages the creation of objects, the methods for the
implemented interfaces such as getModel() and prepare() are not invoked.
If
I change the class="Menu" to class="example.Menu", the interfaces methods
were invoked since I am not letting spring manages object creation.

Could someone let me know what I may have done wrong? How can I use Spring
and Struts at the same time without losing either functionality?

Any help is greatly appreciated.

Thanks!

Lee





  




Re: [S2] ModelDriven, Preparable and SessionAware do not work with Spring

2007-03-08 Thread Shih Lee

Hi All,

I think I know what is the trouble but am still not sure why is this a
problem for Struts 2.0. I hope someone from the Struts community can help to
shed some light.

The problem is when I use
"org.springframework.aop.framework.ProxyFactoryBean" to AOP the Action
class. Once I remove the AOP piece such as the following, everything work
just fine:





Any help is appreciated!

Thanks,
Lee


Shih Lee wrote:
> 
>  Hi All,
> 
> I have been playing with Struts 2.0 sample application, struts-blank, and
> integrates it with Spring 2.x. So far, I have not been having great
> success
> with it.
> 
> 
> 
> I have followed all the steps needed to integrate Struts 2.0 with Spring
> 2.0.
> Here is what I have done so far:
> 
> 1) Included struts2-spring-plugin-2.0.6.jar, spring.jar,
> struts2-core-2.0.6.jar and the dependent jars.
> 
> 2) Modified the example.xml to include spring object factory:
> 
> Configuration 2.0//EN"
> "http://struts.apache.org/dtds/struts-2.0.dtd";>
> 
>
> 
>   
>extends="struts-default">
> 
>   
> 
> 
> /example/HelloWorld.jsp
> 
> 
> 
> /example/Login.jsp
> Menu
> 
> 
> 
> /example/Menu.jsp
> 
> 
> 
> /example/{1}.jsp
> 
> 
> 
> 
> 
> 
> 
> 3) I have edited the spring applicationContext.xml
> 
>   
> 
>http://www.springframework.org/dtd/spring-beans.dtd";>
> 
>   
> 
>   
> 
>   
> 
>   
> 
>   
> 
> 
>
>   execute
>
>  
> 
>   
> 
>   
> 
>   
> 
>   
> 
>   
> 
> 
>   example.IMenu
> 
> 
>
>   
> timeLoggingAdvisor
>   
> 
> 
>   
> 
>   
> 
> 
>   
> 
> 
> 4) Implemented ModelDriven, Preparable and SessionAware interfaces in
> Menu.java:
> 
> package example;
> import java.util.Map;
> import org.apache.struts2.interceptor.SessionAware;
> import com.opensymphony.xwork2.ModelDriven;
> import com.opensymphony.xwork2.Preparable;
> 
> /**
> 
>  * Set welcome message.
> 
>  */
> 
> public class Menu extends ExampleSupport implements IMenu, ModelDriven,
> Preparable, SessionAware {
> 
> private Map _session;
> 
> private User user;
> 
> public String execute() throws Exception {
> 
> return SUCCESS;
> 
> }
> 
> public Object getModel() {
> return user;
> }
> 
> public void prepare() throws Exception {
> if (getSession().get("user") != null) {
> user = (User)
> getSession().get("user");
> } else {
> user = new User();
> }
> }
> 
> 
> public void setSession(Map session) {
> _session = session;
> }
> 
> 
> public Map getSession() {
> return _session;
> }
> }
> 
> When I let Spring manages the creation of objects, the methods for the
> implemented interfaces such as getModel() and prepare() are not invoked.
> If
> I change the class="Menu" to class="example.Menu", the interfaces methods
> were invoked since I am not letting spring manages object creation.
> 
> Could someone let me know what I may have done wrong? How can I use Spring
> and Struts at the same time without losing either functionality?
> 
> Any help is greatly appreciated.
> 
> Thanks!
> 
> Lee
> 
> 

-- 
View this message in context: 
http://www.nabble.com/ModelDriven%2C-Preparable-and-SessionAware-do-not-work-with-Spring-tf3371304.html#a9381353
Sent from the Struts - User mailing list archive at Nabble.com.


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



ModelDriven, Preparable and SessionAware do not work with Spring

2007-03-08 Thread Shih-gian Lee

Hi All,



I have been playing with Struts 2.0 sample application, struts-blank, and
integrates it with Spring 2.x. So far, I have not been having great success
with it.






I have followed all the steps needed to integrate Struts 2.0 with Spring 2.0.
Here is what I have done so far:



1) Included struts2-spring-plugin-2.0.6.jar, spring.jar,
struts2-core-2.0.6.jar and the dependent jars.



2) Modified the example.xml to include spring object factory:



   http://struts.apache.org/dtds/struts-2.0.dtd";>







 



   



 



   

   /example/HelloWorld.jsp

   



   

   /example/Login.jsp

   Menu

   



   

   /example/Menu.jsp

   



   

   /example/{1}.jsp

   



   

   





3) I have edited the spring applicationContext.xml



 

 http://www.springframework.org/dtd/spring-beans.dtd";>



 



 

 



 

 

   

  

 execute

  



   

 

   

 



 



 



 

   

 example.IMenu

   

   

 

   timeLoggingAdvisor

 

   

   

 

   

 



 



  



4) Implemented ModelDriven, Preparable and SessionAware interfaces in
Menu.java:



   package example;



import java.util.Map;



import org.apache.struts2.interceptor.SessionAware;



import com.opensymphony.xwork2.ModelDriven;

import com.opensymphony.xwork2.Preparable;



/**

* Set welcome message.

*/

public class Menu extends ExampleSupport implements IMenu, ModelDriven,
Preparable, SessionAware {



   private Map _session;

   private User user;



   public String execute() throws Exception {



   return SUCCESS;

   }



   public Object getModel() {

   return user;

   }



   public void prepare() throws Exception {

   if (getSession().get("user") != null) {

   user = (User) getSession().get("user");

   } else {

   user = new User();

   }

   }



   public void setSession(Map session) {

   _session = session;

   }



   public Map getSession() {

   return _session;

   }

}







When I let Spring manages the creation of objects, the methods for the
implemented interfaces such as getModel() and prepare() are not invoked. If
I change the class="Menu" to class="example.Menu", the interfaces methods
were invoked since I am not letting spring manages object creation.



Could someone let me know what I may have done wrong? How can I use Spring
and Struts at the same time without losing either functionality?



Any help is greatly appreciated.



Thanks!

Lee