Hi Kirby,

You're right about the struts-user group, not much talk of Scaffold but we
should try and change that.
Another place to look is http://sourceforge.net/projects/struts/


I've been off the air for the last couple of days but will try to answer
what I can when I can.



This is what we do:

import org.apache.commons.scaffold.lang.Tokens;
   .
   .
   .
   .
ProcessResult result = new ProcessResultBase(this, true);

// DO STUFF

if (error) {
      result.setDispatch(Tokens.FAILURE);
      result.addMessage(new ActionError
("error.something.bad.has.happened"));
}



OR


ProcessResult result = new ProcessResultBase(this, true);

// DO STUFF

if (error) {
      result.setDispatch(Tokens.FAILURE);
      ActionErrors errors = new ActionErrors();
      errors.add("password", new ActionError
("error.you.have.stuffed.up","password"));
      errors.add("userid", new ActionError
("error.you.have.stuffed.up","userid"));
      result.addMessage(errors);
}




I have also made a modification to the Scaffold code so that you can add
multiple ActionError objects to the message response.  Here you can either
add an ActionError or ActionErrors object as a message response  (See
above). The original code for this method looks a bit odd.  It looks like
you have to add the message key and message parameters as separate adds to
the messages list object.  Strange!  I think what I've done makes a little
more sense but that's up to others to interpret.


The following method is in BaseAction



      protected void mergeAlerts(
            HttpServletRequest request,
            ActionErrors alerts,
            List list) {

            if ((null != list) && (0 != list.size())) {

                  for (int i = 0; i < list.size(); i++) {
                        Object obj = list.get(i);

                        // if the obj is an ActionError_s_ then pull out
each
                        // ActionError and merge into the alerts with the
field key
                        if (obj instanceof ActionErrors) {

                              ActionErrors errors = (ActionErrors) obj;

                              Iterator itr = errors.properties();
                              while(itr.hasNext()){
                                    String key = (String)itr.next();
                                    Object value = errors.get(key);
                                    Iterator itrError = (Iterator) value;
                                    while(itrError.hasNext()){
                                          alerts.add(key, (ActionError)
itrError.next());
                                    }
                              }

                        } else {
                              // assume anything else is going to be an
ActionError
                              alerts.add(ActionErrors.GLOBAL_ERROR,
(ActionError) list.get(i));
                        }

                  }
            }

      }



Hope this helps.


Regards,

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


( +61 3 8641 2846 2 +61 3 8641 4152 : [EMAIL PROTECTED]


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


|---------+---------------------------->
|         |           Kirby Vandivort  |
|         |           <[EMAIL PROTECTED]|
|         |           .edu>            |
|         |                            |
|         |           01/04/2003 02:08 |
|         |                            |
|---------+---------------------------->
  
>--------------------------------------------------------------------------------------------------------------|
  |                                                                                    
                          |
  |       To:       [EMAIL PROTECTED]                                                  
                |
  |       cc:                                                                          
                          |
  |       Subject:  Re: scaffold ProcessBaseBean and sessions                          
                          |
  
>--------------------------------------------------------------------------------------------------------------|




Steve,

Thanks for responding earlier.  It was helpful and was close to what I
was doing at the time.

For the most part, the struts-user group doesn't seem very responsive for
any scaffold related questions.  Right now, I'm having trouble with a
simple question and I was wondering if you could enlighten me on how
you handle this case.

I've got my logic bean that inherits from ProcessBean.  This bean has the
simple job of changing a password.  It gets 3 values in (old pass, new
pass,
and verification pass).

How do I send back a failure message from the bean?  Let's say that their
old pass isn't correct, or the two new passwords don't match.  As best
I can tell, I only have two routes to go:

* I can use 'addMessage' but that doesn't set any failure flags.  In fact,
  I haven't yet had a whole lot of luck getting this to work.  But, it
  seems to be designed for cases where you want to say 'Update successful'
  or something similiar.  But, it always just goes to the successful
  forward, which isn't what I want.

* I can throw an exception from the bean, but this seems to designed for
  cases where extreme errors have occurred.  The default handler,
  catchException, in BaseAction prints errors to stdout and other things.
  I don't want or need this.  I realize that I could overload the
  catchException method....  But it seems like in some cases I _would_
  want this behavior.

So, I guess I am wanting something in between, and I am just curious
how you handle this situation.

Thanks!

Kirby



On Wed, Mar 26, 2003 at 10:03:45AM +1100, [EMAIL PROTECTED]
wrote:
>
> 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 : [EMAIL PROTECTED]
>
>
> National Australia Bank Limited
> 4th Floor/ 500 Bourke St
> Melbourne, Victoria 3000
>
>
> |---------+---------------------------->
> |         |           Kirby Vandivort  |
> |         |           <[EMAIL PROTECTED]|
> |         |           .edu>            |
> |         |                            |
> |         |           26/03/2003 05:07 |
> |         |           Please respond to|
> |         |           "Struts Users    |
> |         |           Mailing List"    |
> |         |                            |
> |---------+---------------------------->
>   >
--------------------------------------------------------------------------------------------------------------|

>   |
|
>   |       To:       [EMAIL PROTECTED]
|
>   |       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: [EMAIL PROTECTED]          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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>
>

--

Kirby Vandivort                      Theoretical and Computational
Biophysics
Email: [EMAIL PROTECTED]          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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to