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:



   !DOCTYPE struts PUBLIC

   -//Apache Software Foundation//DTD Struts Configuration 2.0//EN

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



struts



 constant name=struts.objectFactory value=spring /



   package name=example namespace=/example extends=struts-default



 default-interceptor-ref name=defaultStack/



   action name=helloWorld class=helloWorld

   result/example/HelloWorld.jsp/result

   /action



   action name=Login_* method={1} class=example.Login

   result name=input/example/Login.jsp/result

   result type=redirect-actionMenu/result

   /action



   action name=Menu class=Menu

   result/example/Menu.jsp/result

   /action



   action name=* class=example.ExampleSupport

   result/example/{1}.jsp/result

   /action



   !-- Add actions here --

   /package

/struts



3) I have edited the spring applicationContext.xml



 ?xml version=1.0 encoding=UTF-8?

 !DOCTYPE beans PUBLIC -//SPRING//DTD BEAN//EN 
http://www.springframework.org/dtd/spring-beans.dtd;



 beans default-autowire=autodetect



 !-- === Interceptors
= --

 bean id=timeLoggingAdvice class=advice.TimeLoggingInterceptor/



 !-- === Advisor
== --

 bean id=timeLoggingAdvisor class=
org.springframework.aop.support.NameMatchMethodPointcutAdvisor

   property name=mappedNames

  list

 valueexecute/value

  /list

/property

   property name=advice

 ref bean=timeLoggingAdvice/

   /property

 /bean



 !-- == Spring Beans
= --



 bean id=helloWorld class=example.HelloWorld singleton=false/



 bean id=Menu class=
org.springframework.aop.framework.ProxyFactoryBean

   property name=proxyInterfaces

 valueexample.IMenu/value

   /property

   property name=interceptorNames

 list

   valuetimeLoggingAdvisor/value

 /list

   /property

   property name=target

 ref local=MenuTarget/

   /property

 /bean



 bean id=MenuTarget class=example.Menu singleton=false/



  /beans



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;



/**

* codeSet welcome message./code

*/

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


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:

!--bean id=Menu class=
org.springframework.aop.framework.ProxyFactoryBean
   property name=proxyInterfaces
   valueexample.IMenu/value
   /property
   property name=interceptorNames
   list
   valuetimeLoggingAdvisor/value
   /list
   /property
   property name=target
   ref local=MenuTarget/
   /property
   /bean

   bean id=MenuTarget class=example.Menu singleton=false/--

   bean id=Menu class=example.Menu singleton=false/



Any help is greatly appreciated!

Thanks,
Lee


Re: caching large data in web application

2004-11-30 Thread Shih-gian Lee
Well, if the data is read only, then you can just cache the data in a
Hashtable and make it accessible through out the application.

If your data is volatile, then you may consider writing a simple time
based caching service -
http://www.javaworld.com/javaworld/jw-07-2001/jw-0720-cache_p.html

Hibernate provides two levels of caching. By default, Hibernates uses
first level caching. Hibernate also provides plugin for other cache
provider like JBoss. This is the second level caching. In first level
caching, Hibernate will check if data in a persistence class has
changed when saving a persistence class. If the related data is being
modified, Hibernate will update the modified data. Of course, this is
just one simple example. For more information, please visit Hibernate
reference document -
http://www.hibernate.org/hib_docs/reference/en/html/

HTH

Lee

On Mon, 29 Nov 2004 07:36:43 -0800 (PST), Ashish Kulkarni
[EMAIL PROTECTED] wrote:
 Hi
 The data which i want to cache has about 1 rows
 and i want to cache it in may be servlet context, what
 is the best way to cache it, do i just create a java
 bean and cache it or some kind of mechanism already
 exist like Hibernation (i am not sure what is does)
 
 Ashish
 
 
 --- Frank W. Zammetti [EMAIL PROTECTED] wrote:
 
  What kind of data is it?  Is it a read-only set of
  data?  How often is
  it updated?  Who or what can update it?
 
  There's any number of ways to do things like this,
  which is the best
  option depends on the particulars of your use case.
 
  You might be able to cache the data in Javascript
  arrays in the user's
  browser in a hidden frame.  This is a fantastic
  approach for data that
  doesn't change frequently and that is read-only.
  Removes potentially a
  lot of data being passed in different spots
  throughout the app, but it
  does complicate your front-end a little more.
 
  You might be able to cache it in the session.  This
  can be good if the
  data set is small, read-only and needed for server
  processing at various
  points.  This can lead to problems in distributed
  environments though,
  so you need to be careful.
 
  You might be able to have a small cache database
  server running along
  side your app server, something like MySQL for
  example, that has temp
  copies of the data.  The benefit to this is you have
  the full power of
  the RDBMS to work with, so you might be able to do
  triggers to update
  the DB2 database when appropriate if it's a one-way
  sort of thing.
 
  As for the idea of update triggers, sure, you can
  almost certainly put
  something together to do this.  I haven't done a
  whole lot with DB2, but
  I'd bet there's some mechanism you could use to
  notify your cache server
  of the update.  I'd suspect the best approach would
  be to notify it a
  change took place but DON'T send the updated data...
  Let the cache
  server do a query to DB2 and get the updated data
  set.  Writing a
  well-constructed stored procedure to do this would
  probably be the best
  bet.  You could also just poll DB2 for changes if
  your application can
  tolerate some lag in updates to the cached data.
 
  Really though, the first question to ask is whether
  what you want to
  cache is read-only or has to support updates.  If
  it's the former, you
  have a lot of options.  It it's the later, things
  get a little trickier.
By the way, I think I've done some variation of
  all these approaches
  at one time or other, so I can try and expand on
  things if you need me to.
 
  --
  Frank W. Zammetti
  Founder and Chief Software Architect
  Omnytex Technologies
  http://www.omnytex.com
 
  Dakota Jack wrote:
   Whatever code updates the database will have to
  somewhere and somehow
   notify the code that updates the cache.  It is
  that simple.
  
   Jack
  
  
  
  
   On Sun, 28 Nov 2004 15:25:56 -0800 (PST), Ashish
  Kulkarni
   [EMAIL PROTECTED] wrote:
  
  Hi
  what is the best way to cache data in web
  application,
  I have a table in AS400 DB2 database which i want
  to
  cache in application server to improve
  performance,
  Also is it possible to have a external trigger
  which
  will update the cache if the data base is updated
  by
  some external process
  
  Ashish
  
  __
  Do you Yahoo!?
  Meet the all-new My Yahoo! - Try it today!
  http://my.yahoo.com
  
 
 -
  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]
 
 
 

 __
 Do you Yahoo!?
 The all-new My Yahoo! - What will yours do?
 
 
 http://my.yahoo.com
 
 -
 To unsubscribe, e-mail: 

Re: How to retrieve parameters passed via GET method?

2004-11-28 Thread Shih-gian Lee
 In my Struts configuration file, an action element is defined as the 
 following:
 actionpath=/closeAccount
 type=org.apache.struts.actions.ForwardAction
 parameter=/closeAccount.jsp /
 
 When customer clicks on the hyperlink, ActionServlet receives the HTTP 
 request, pre-processes it and forwards it to ForwardAction, who will simply 
 forward the request to closeAccount.jsp. That page then asks customer to 
 confirm the operation (are you sure that you want to close account No. 
 100?). The problem is, ActionServlet seems to have modified the request, so 
 in my closeAccount.jsp, i cannot retrieve the accountId parameter: 
 request.getAttribute(accountId) returns null.
 
 I dumped the contents in the HTTP request that closeAccount.jsp receives. 
 They look like this:
 javax.servlet.forward.request_uri = /badba/closeAccount.do 
 javax.servlet.forward.context_path = /badba 
 javax.servlet.forward.servlet_path = /closeAccount.do 
 javax.servlet.forward.query_string = accountId=100 
 org.apache.struts.action.mapping.instance = 
 ActionConfig[path=/closeAccount,parameter=/closeAccount.jsp,scope=session,type=org.apache.struts.actions.ForwardAction
  org.apache.struts.action.MODULE = [EMAIL PROTECTED]
 

Is it possible that the accountId is saved in session scope instead of
request scope?

You need to specify the scope if you want to save it in request scope:

action path=/closeAccount
type=org.apache.struts.actions.ForwardAction   
parameter=/closeAccount.jsp scope=request/

HTH.

Lee

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