struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Tobey <dto...@dtobey.com>
Subject Dynamic DynaActionForms?
Date Wed, 11 Jun 2003 01:25:50 GMT
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


Mime
View raw message