You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Phase Web and Multimedia <ma...@phase.ws> on 2002/04/04 03:06:37 UTC

DynaActionForm / DynaBean

I have read so much that talks about what the DynaBean DynaActionForm can
accomplish but have been unable to find concrete examples. Does anybody have
any code they could offer up to shed some light on the use.

Brandon Goodin
Phase Web and Multimedia
P (406) 862-2245
F (406) 862-0354
mail@phase.ws
http://www.phase.ws



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: DynaActionForm / DynaBean

Posted by Chuck Cavaness <ch...@attbi.com>.
I doubt this will be enough, but I'll offer it up to get you started. 
Suppose I have the following form-bean:

<form-beans>
   <form-bean
       name="itemDetailForm"
       dynamic="true"
       type="org.apache.struts.action.DynaActionForm">
         <form-property name="view" 
type="com.oreilly.struts.catalog.view.ItemView"/>
   </form-bean>
    ...
</form-beans>

I have specified that the form will hold an object of type 
"com.oreilly.struts.catalog.view.ItemView", using a name of "view".

Further supposed that I have a GetItemDetailAction that has this execute 
method:

  ...
  public ActionForward executeAction(ActionMapping  mapping,
                                      ActionForm     form,
                                      HttpServletRequest request,
                                      HttpServletResponse response,
                                      UserContainer  userContainer) throws 
BaseException {
     String itemId = request.getParameter( IConstants.ID_KEY );
     ICatalogController catalogController = 
userContainer.getCatalogController();

     // Get a value object representing the item from the business tier
     ItemView itemView = catalogController.getItemView(itemId);

     // Set the ItemView into the Dynamic Action Form
     ((DynaActionForm)form).set("view", itemView);

     // The parameter name 'view' is what is defined in the Dynamic form
     // in struts-config. Maybe should use a constant there too?

     // Return to the success resource for this action
     return mapping.findForward(IConstants.SUCCESS_KEY);
}

Now, in the JSP page that the user is forwarded to, they can use all of the 
Struts tags to get at the ItemView data inside of the dynamic form. I won't 
show the JSP page, it's too long. Here's a couple of lines from it:

     <bean:write name="itemDetailForm" property="view.name"/>

     <html:link
         page="/action/cart?method=addItem"
         paramId="id"
         paramName="itemDetailForm"
         paramProperty="view.id"
         paramId="id"
         paramScope="request">

Notice that view.name would be translated into getView().getName() like a 
standard ActionForm.

I hope this helps somewhat.

Chuck



At 06:06 PM 4/3/2002 -0700, you wrote:
>I have read so much that talks about what the DynaBean DynaActionForm can
>accomplish but have been unable to find concrete examples. Does anybody have
>any code they could offer up to shed some light on the use.
>
>Brandon Goodin
>Phase Web and Multimedia
>P (406) 862-2245
>F (406) 862-0354
>mail@phase.ws
>http://www.phase.ws
>
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>