ProcessAction, ProcessResultBase combo is handy but evilll as it is
full of pitfalls and can cost u hrs of debugging.

To save u  time, here is the lessons i learned the hard way
(no guarantee they r right)

1. Only ActionError can be added to ProcessResult.addMessage or else
ClassCastException

2.
 problem displaying ActionError's messages
    with ProcessResult:

    For some reason, only messages can be displayed, not
    errors. Has to use messages tag to display ActionError
    added to ProcessResultBase subclass

    E.g. from error.jsp

    <logic:messagesPresent message="true">
  <UL>
  <html:messages id="message" message="true">
  <LI><bean:write name="message"/></LI>
  </html:messages>
  </UL>
</logic:messagesPresent>

Looks like ActionError messages are stored by a key
 accessed only in <logic:messagesPresent message="true">

---------------

3.
Always let singleForm property of ProcessResultBase
   = false (default) if want 'LIST' attribute to exist
   in session.
   false => 0 or more records
   true => exactly 1 record

4.

if ProcessResult.setSingleForm( true ), make sure call pr.setName("LIST")
if want to use a bean named 'LIST' to exist in forwarded JSP

5.

*** BaseForm's mergeAlert method seems to have bugs. When
    I add ActionError to it by ProcessResult.addMessage( error ),
    ClassCastException happens.
    E.g.
    java.lang.ClassCastException
   at org.apache.struts.scaffold.BaseAction.mergeAlerts(Unknown Source)
   at org.apache.struts.scaffold.BaseAction.saveMessages(Unknown Source)
   at org.apache.struts.scaffold.ProcessAction.checkMessages(Unknown Source)
   at org.apache.struts.scaffold.ProcessAction.checkOutcome(Unknown Source)
   at app.ProcessSessionAction.executeLogic(Unknown Source)
   at org.apache.struts.scaffold.BaseHelperAction.executeLogic(Unknown
Source)
 at org.apache.struts.scaffold.BaseAction.execute(Unknown Source)

Fix: Follow
http://www.mail-archive.com/[EMAIL PROTECTED]/msg65765.html
to modify mergeAlerts method of BaseAction, compile to make new scaffold
jar.
Use that jar.

6. To access Session object in business bean, subclass of ProcessBeanBase,
create ur own subclass of
  ProcessAction  and a corresponding business bean

E.g.
package app;

import org.apache.commons.scaffold.util.ProcessBeanBase;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;

/* A convinence class that will allow business objects
 * to have access to web tier objects (i.e. request
 *   and session).
 */
public class BusinessBean extends ProcessBeanBase {

   private HttpSession session;
   public void setSession( HttpSession session ) {
    this.session = session;
   }
   public HttpSession getSession() {
    return session;
     }

   private HttpServletRequest request;
   public void setRequest( HttpServletRequest request ) {
    this.request = request;
   }
   public HttpServletRequest getRequest() {
    return request;
     }

} // end FileBean

-----------

package app;

import org.apache.struts.scaffold.ProcessAction;
import javax.servlet.http.HttpSession;

import java.io.IOException;
import java.io.PrintWriter;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.beanutils.BeanUtils;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import org.apache.struts.util.MessageResources;

import org.apache.commons.scaffold.lang.Log;
import org.apache.commons.scaffold.lang.Tokens;
import org.apache.commons.scaffold.util.ProcessBean;
import org.apache.commons.scaffold.util.ProcessResult;
import org.apache.commons.scaffold.util.ResultList;
import org.apache.commons.scaffold.util.ResultListBase;

import org.apache.commons.scaffold.lang.Tokens;
import org.apache.struts.scaffold.BaseForm;


public class ProcessSessionAction extends ProcessAction {

  protected void executeLogic(
             ActionMapping mapping,
             ActionForm form,
             HttpServletRequest request,
             HttpServletResponse response,
             Object[] helpers) throws Exception {

             // Retrieve user profile, if any
         BaseForm userBean =
             getUserProfile(mapping,form,request,response);

         servlet.log(Log.HELPER_PROCESSING,Log.DEBUG);
         Map properties = null;
         for (int i = 0; i < helpers.length; i++) {

                 // Get helper instantiated by ancestor
             ProcessBean dataBean = (ProcessBean) helpers[i];

             if ( dataBean == null )
              System.out.println("dataBean is null");

             System.out.println("111");

             properties = null;
             if (null!=form) {
                 if (form instanceof BaseForm) {

                    BaseForm formBean = (BaseForm) form;

                     if ( formBean == null )
                 System.out.println("formBean is null");

                 System.out.println("222");

                    // Custom code below. Use MyBaseForm since
                    // merge method of BaseForm is protected,
                    // can't call it here directly
        MyBaseForm myFormBean = new MyBaseForm();
        BeanUtils.copyProperties(myFormBean,formBean);


         if ( myFormBean == null )
                 System.out.println("myFormBean is null");

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

         System.out.println("333");

         // Pass up the Locale and RemoteServer (if any)
        dataBean.setLocale(myFormBean.getSessionLocale());
                      dataBean.setRemoteServer(getRemoteServer());

                 }
                 else {
                     properties = PropertyUtils.describe(form);
                      System.out.println("444");
                 }
             } // end null form
             else if (null!=userBean) {
                     // if no form, but is profile, still use profile
                 properties = PropertyUtils.describe(userBean);
                  System.out.println("555");
             }


     /* Code change starts ...
      * Note:
      * This method remains the same as ProcessAction
      * except for the addition of the block of code below.
      * It is expected that any busineess bean (sub-class
      * of ProcessBean that wishes to use session and request
      * objects should include setter and getter method
      * for this session object.
      */
     HttpSession session = request.getSession();
     properties.put( Tokens.SESSION, session );
     properties.put( Tokens.REQUEST, request );

      /* Code change ends */

      if ( dataBean == null )
              System.out.println("final dataBean is null");

             // Execute business logic, using values from  map
             servlet.log(Log.HELPER_EXECUTING,Log.DEBUG);
             ProcessResult result =
(ProcessResult)dataBean.execute(properties);


                 // Analyze result of business logic
             checkOutcome(mapping,request,result);



         } // end for

    } // end executeLogic

}

Now u can model each use case from UML by 1 subclass of
BusinessBean.


----- Original Message ----- 
From: "Ruben Cepeda" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, August 26, 2004 5:43 AM
Subject: RE: Scaffold


> Tate,
>
> http://www.manning.com/catalog/view.php?book=husted&item=source
>
>
> Download the husted_src.zip file it has the source.
>
>
>
> *************************************
> Ruben Cepeda
> [EMAIL PROTECTED]
> *************************************
>
>
>
>
>
> ----Original Message Follows----
> From: "Tate Austin" <[EMAIL PROTECTED]>
> Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> Subject: Scaffold
> Date: Wed, 25 Aug 2004 12:24:42 -0400
>
> I am trying to track down the Apache struts scaffold source?  I need a
copy
> of the org.apache.struts.scaffold.ProcessAction .java file for instance,
and
> for the life of me I cannot seem to locate a working version of it?
>
> _________________________________________________________________
> Express yourself instantly with MSN Messenger! Download today - it's FREE!
> hthttp://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
>
>
> ---------------------------------------------------------------------
> 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]

Reply via email to