Maybe I'm misinterpreting your suggestion, but wouldn't this be putting
logic in your ActionForm that should be in the ActionServlet?  What about
defining several additional perform methods in your ActionServlet that
handle specific superclasses of ActionForm, and an abstract method
visit(YourActionServlet caller, ActionMapping mapping, ServletRequest
request, ServletResponse response) to the ActionList.  The concrete visit()
methods in all your derived classes would just call caller.perform(),
passing itself as the ActionForm parameter.

-----Original Message-----
From: Ted Husted [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, October 23, 2001 6:08 PM
To: [EMAIL PROTECTED]
Subject: Re: What is proper way to determine ActionForm type?


I'd consider using some type of polymorphism, where all of these
ActionForms share a common ancestor, with a known method, like
addItem(object), that would act as a wrapper. Each ActionForm could then
override addItem to call whatever list is appropriate. 

ProductList extends ActionList
 addItem(addProductItem(o)) ; 
AddressList extends ActionList
 addItem(addAddressItem(o)); 

In your framework Action, you could then just cast as the ancestor
method and call the overridden method

ActionList actionList = (ActionList) form; 

actionList.addItem(o);

If you are still interested in determining the ActionForm bean type, see
the source of the processActionForm method for how the ActionServlet
does it.

If you need to call a method based on a parameter, see the source for
DispatchAction in the Actions package, which calls a local method based
on the string given as the parameter property.

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel +1 716 737-3463
-- http://www.husted.com/struts/


Stephen Hood wrote:
> 
> I am trying to write a generic Action class that I can use with any
> ActionForm to add an item to any collection property it may contain.  For
> example, if I had two ActionForms which each contain a collection (say
> "AddressList" and "ProductList"), I could call the same Action with either
> form, pass it the name of the collection, and have it add a new item to
it,
> passing control back to the calling View.
> 
> In order to make it generic, I want the class to figure out the ActionForm
> type specified in the mapping, recast the generic ActionForm as the proper
> type, and then add another item to the collection indicated by a passed
> request attribute.
> 
> To dynamically determine the ActionForm type, I'm trying to use the
> equivalent of ActionMapping.getFormClass(), which has been deprecated.
The
> suggested alternative is to use ActionMapping.getName() and then use it to
> look-up the ActionFormBean.  It seems the way to do this is to use
> ActionFormBeans.findFormBean(String beanName).  However, the following
code
> returns a null ActionFormBean.
> 
>   String formBeanName = mapping.getName();
>   ActionFormBeans actionFormBeans = new ActionFormBeans();
>   ActionFormBean theFormBean = actionFormBeans.findFormBean(formBeanName);
> 
> I assume that my ActionFormBeans object itself is empty and I am not
> creating or populating it properly, but I could not find details in the
> Struts javadoc.
> 
> Is this the correct approach?
> 
> thanks for any suggestions,
> --Steve

Reply via email to