The problem is that html:form is looking for the ActionForm associated
with its ActionMapping. 

Having one Action handle more than one ActionForm isn't a problem. But
getting html:form to handle more than ActionForm is problematic. 

If the *properties* for each registration type are the same, then you
may not need two different ActionForm beans at all. 

The Action just needs a way to tell the registeration types apart,
perhaps by using a hidden property. 

This is admittedly not a very OOP approach, but HTTP is not a OO
protocol, so we have to make allowances on this tier ;-)

Interally, you might want to have different beans for the different user
types; these should not be ActionForm beans, but some other bean
representing your internal model, and not bound to HTTP.

You should also omit the "scope" property from the html:form, since, in
this case, it will get all that out of the Struts config.

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


Richard Dallaway wrote:
> 
> I've been wondering about the best way to go about using struts in this
> situation....
> 
> I have two types of forms (for different kind of web registrations) which
> are very similar, but not quite identical.  The associated
> RegistrationAction will perform slightly different tasks depending on which
> form it is given.  So I could go for two actions, one for each of the
> forms.  That'll work.
> 
> But I was wondering if instead I could do have a base RegistrationForm
> (containing lots of common stuff), and then extend it to give me say
> UserRegistrationForm and StaffRegistrationForm.  A single action would
> accept a form of type "RegistrationForm" and do whatever it needed to
> do.  (For the sake of argument, assume that the JSP form can be shared, so
> validation is OK).
> 
> So I tried this, by having a startRegistrationAction that created an
> instance of either StaffRegistrationForm or UserRegistrationForm , casting
> it to be of type RegistrationForm, and put it in session scope under the
> name "registrationForm" before forwarding on to the JSP form for the end
> user to complete.
> 
> When the form is submitted to the RegistrationAction I get a null form
> passed.   The config I have is....
> 
>     <form-bean
>        name="registrationForm"
>        type="RegistrationForm" />
> 
>      <!-- Register a new user -->
>      <action
>          path="/register"
>          name="registrationForm"
>          type="RegistrationAction"
>          unknown="false"
>          input="/register.jsp"
>          validate="true">
>      </action>
> 
> The form tag looks like:
>    <html:form action="/register" scope="session" >
> 
> ....and of course if I change the form-bean type to be
> "StaffRegistrationForm" or "UserRegistrationForm" it will work for one of
> those specific instances.
> 
> Am I right in thinking that because my form is of type (say)
> StaffRegistraionForm (which happens to extend RegistrationForm), struts
> won't be able to find a RegistrationForm type object in the session? Which
> is why my Action sees a null form.
> 
> So my questions are really....
> (1) is this a sane thing to be trying?
> (2) is there a way to do this?
> 
> Many thanks
> Richard
> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to