You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by David Tobey <dt...@dtobey.com> on 2003/06/11 03:25:50 UTC

Dynamic DynaActionForms?

Hello all:

I'm writing what (I hope) will be a highly-configurable generic shopping 
cart program using (we hope) Struts. My issue is I want to be able to 
modify the elements of various forms on the fly, and I'm struggling with 
the best way to do this. For example, I have defined an order form as a 
subclass of DynaActionForm, like so:

<form-beans>
  <form-bean name="orderForm" 
type="org.netpush.cart.customer.order.OrderForm">
   <form-property name="billingFirstName" type="java.lang.String"/>
   <form-property name="billingLastName" type="java.lang.String"/>
   <form-property name="billingOrganization" type="java.lang.String"/>
   <form-property name="billingAddress1" type="java.lang.String"/>
   <form-property name="billingAddress2" type="java.lang.String"/>
   <form-property name="billingCity" type="java.lang.String"/>
   <form-property name="billingState" type="java.lang.String"/>
   <form-property name="billingPostalCode" type="java.lang.String"/>
...
   <form-property name="creditCardNumber" type="java.lang.String"/>
   <form-property name="creditCardType" type="java.lang.String"/>
   <form-property name="creditCardExpDate" type="java.lang.String"/>
   <form-property name="creditCardName" type="java.lang.String"/>
...
</form-bean>

Within this form I would like to be able to swap out different fields, 
depending on if the shopping cart is configured in certain ways. For 
example if instead of capturing credit card information, the store 
administrator wants to capture a purchase order number and an account id 
number.

The administrator must be able to change settings like this in a 
separate web-based application talking to a database (not by logging on 
to the server and modifying the config files!). I have no problem 
reading the settings from the database and exposing them to the view and 
to the controller. The issue is what's the best to dynamically change 
the fields in this DynaActionForm given the database settings.

My thoughts are revolving around two options:

1. Subclass the RequestProcessor. I could create mutilple ActionForms, 
one for address info, one for credit card info, and one for PO info, and 
then revamp the RequestProcessor to accept more than one Form per 
action, and populate and validate each one in turn. (During validation, 
I could check the settings to find out which of the optional forms must 
pass validation.)

2. Write functions to dynamically modify the struts-config.xml file and 
reload the settings whenever the administrator changes what information 
they want to collect. The problem with this is I have to worry about 
file locking, and interruptions in service as the configuration is 
reloaded. (Has anyone written tools to modify the config file through a 
web application?)

If anyone has come across or has any thoughts about the best way to 
approach this sort of thing, I would be very grateful to hear what you 
have to say.

Many thanks,
dave


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Dynamic DynaActionForms?

Posted by Sandeep Takhar <sa...@yahoo.com>.
Why not have the form capture all the info.

Have the administrator control a switch to suggest
which radio boxes should appear and if they only
choose one then don't show any radio boxes.

After filling in the address info have a next button
and take them to the additional info about credit etc.

At this point you can validate according to the radio
button (which will be auto-populated according to how
the user selected).

I have always found it better to add all the
attributes instead of getting too fancy on the
actionForms.

I believe Ted Husted mentions the same in his book. 
This is more like a "Domain DTO" pattern for action
forms.

sandeep
--- David Tobey <dt...@dtobey.com> wrote:
> Hello all:
> 
> I'm writing what (I hope) will be a
> highly-configurable generic shopping 
> cart program using (we hope) Struts. My issue is I
> want to be able to 
> modify the elements of various forms on the fly, and
> I'm struggling with 
> the best way to do this. For example, I have defined
> an order form as a 
> subclass of DynaActionForm, like so:
> 
> <form-beans>
>   <form-bean name="orderForm" 
> type="org.netpush.cart.customer.order.OrderForm">
>    <form-property name="billingFirstName"
> type="java.lang.String"/>
>    <form-property name="billingLastName"
> type="java.lang.String"/>
>    <form-property name="billingOrganization"
> type="java.lang.String"/>
>    <form-property name="billingAddress1"
> type="java.lang.String"/>
>    <form-property name="billingAddress2"
> type="java.lang.String"/>
>    <form-property name="billingCity"
> type="java.lang.String"/>
>    <form-property name="billingState"
> type="java.lang.String"/>
>    <form-property name="billingPostalCode"
> type="java.lang.String"/>
> ...
>    <form-property name="creditCardNumber"
> type="java.lang.String"/>
>    <form-property name="creditCardType"
> type="java.lang.String"/>
>    <form-property name="creditCardExpDate"
> type="java.lang.String"/>
>    <form-property name="creditCardName"
> type="java.lang.String"/>
> ...
> </form-bean>
> 
> Within this form I would like to be able to swap out
> different fields, 
> depending on if the shopping cart is configured in
> certain ways. For 
> example if instead of capturing credit card
> information, the store 
> administrator wants to capture a purchase order
> number and an account id 
> number.
> 
> The administrator must be able to change settings
> like this in a 
> separate web-based application talking to a database
> (not by logging on 
> to the server and modifying the config files!). I
> have no problem 
> reading the settings from the database and exposing
> them to the view and 
> to the controller. The issue is what's the best to
> dynamically change 
> the fields in this DynaActionForm given the database
> settings.
> 
> My thoughts are revolving around two options:
> 
> 1. Subclass the RequestProcessor. I could create
> mutilple ActionForms, 
> one for address info, one for credit card info, and
> one for PO info, and 
> then revamp the RequestProcessor to accept more than
> one Form per 
> action, and populate and validate each one in turn.
> (During validation, 
> I could check the settings to find out which of the
> optional forms must 
> pass validation.)
> 
> 2. Write functions to dynamically modify the
> struts-config.xml file and 
> reload the settings whenever the administrator
> changes what information 
> they want to collect. The problem with this is I
> have to worry about 
> file locking, and interruptions in service as the
> configuration is 
> reloaded. (Has anyone written tools to modify the
> config file through a 
> web application?)
> 
> If anyone has come across or has any thoughts about
> the best way to 
> approach this sort of thing, I would be very
> grateful to hear what you 
> have to say.
> 
> Many thanks,
> dave
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org