struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve_Ak...@national.com.au
Subject Re: scaffold ProcessBaseBean and sessions
Date Tue, 25 Mar 2003 23:03:45 GMT

If you set up a userProfile form object in your struts config and store
your user info in it, Scaffold will merge information coming from the
request form and the userProfile form and pass them to the execute method.

If you want to see how it works, have a look at the source for
ProcessAction in the executeLogic method.  In particular the following
code:

                if (form instanceof BaseForm) {

                    BaseForm formBean = (BaseForm) form;

                        // Merge user profile (if found)
                        // and our form into a single map
                    servlet.log(Log.HELPER_POPULATE,Log.DEBUG);
                    properties = formBean.merge(userBean);

                        // Pass up the Locale, RemoteNode, and RemoteServer
(if any)
                    dataBean.setLocale(formBean.getSessionLocale());
                    dataBean.setRemoteNode(getRemoteNode(request));
                    dataBean.setRemoteServer(getRemoteServer());
                }
                else {
                    properties = PropertyUtils.describe(form);
                }


As you can see it calls a merge method on the form bean which returns all
the properties of the request form and the userProfile form merged into the
properties map.

I'm using this for a few projects here but there is one restriction.  The
merge method expects all the properties of the userProfile form to be
Strings so you can't have nested objects.  I've overcome this by altering
the code so that it treats the properties in the userProfile as Objects and
not Strings.  This seems to be working fine.  See the code below from the
merge method:

            Iterator i = userMap.keySet().iterator();
            while (i.hasNext()) {
                String key = (String) i.next();
                Object formValue = formMap.get(key);
                if (formValue == null) {
                    formMap.put(key,userMap.get(key));
                }

/*  CHANGED AS IT ONLY HANDLES STRINGS THIS IS NOT GOOD ENOUGH

                String formValue = (String) formMap.get(key);
                if (isBlank(formValue)) {
                    formMap.put(key,userMap.get(key));
                }
*/


This feature does not seem to be mentioned in Ted's book but I came across
it by accident when looking at the code.


Regards,

Steve Akins
Team Leader, Frameworks, J2EE Engineering
Development Centre
Financial Services Australia Technology


( +61 3 8641 2846 2 +61 3 8641 4152 : steve_akins@national.com.au


National Australia Bank Limited
4th Floor/ 500 Bourke St
Melbourne, Victoria 3000


|---------+---------------------------->
|         |           Kirby Vandivort  |
|         |           <kvandivo@ks.uiuc|
|         |           .edu>            |
|         |                            |
|         |           26/03/2003 05:07 |
|         |           Please respond to|
|         |           "Struts Users    |
|         |           Mailing List"    |
|         |                            |
|---------+---------------------------->
  >--------------------------------------------------------------------------------------------------------------|
  |                                                                                      
                       |
  |       To:       struts-user@jakarta.apache.org                                       
                       |
  |       cc:                                                                            
                       |
  |       Subject:  scaffold ProcessBaseBean and sessions                                
                       |
  >--------------------------------------------------------------------------------------------------------------|




I'm trying to write a webapp using scaffold, where I set my action to point
to:
   type="org.apache.struts.scaffold.ProcessAction"
   parameter="my.class.that.extends.ProcessBaseBean"


and I'm wondering how, in the execute() method of the ProcessBaseBean
that I can get session information.  In particular, I have a user
object stored in the session that I need for the execute().  It seems
as though I probably wouldn't want to tighten the connection between
the controller and the bean by making the session info available
directly, but I'm not sure how to make the jump.

>From looking at the cvs code, it looks like ProcessAction has the
ability to expose the session, but it is still a bit nebulous as
to how everything works together.

Thanks,

--

Kirby Vandivort                      Theoretical and Computational
Biophysics
Email: kvandivo@ks.uiuc.edu          3051 Beckman Institute
http://www.ks.uiuc.edu/~kvandivo/    University of Illinois
Phone: (217) 244-5711                405 N. Mathews Ave
Fax  : (217) 244-6078                Urbana, IL  61801, USA

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org






---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message