I would appreciate any comments as to whether this is an 'ok' design
practice and/or suggestions on a better way to handle this...
For a simple example picture a case where an administrator can enter
inventory items. Admins would also want the ability to see a view
of inventory items based on certain criteria (ie only items entered
during the past 30 days or items all over $300).
Normally for such a scenario I've been doing it like this:
o Create dynamic form bean of String values in struts-config
called "InventoryItem"
o Create a value object/data transfer object for this bean with
the correct data types "InventoryItemBean"
o Create dynamic form bean of String values in struts-config
called "InventorySearchCriteria"
o Create a value object/data transfer object for this bean with
the correct data types "InventorySearchBean"
Now since I'm just using normal JDBC calls what I have on insert is my
form submits to action class which converts the dynamic form bean to
the value object with BeanUtils.copyProperties(..). Then valueObject
gets passed on to a service object (
ServiceObject.insertInventoryItem( obj ) which in turn calls a
Database repository class (not a true DAO I guess) which will do the
insert into the DB through JDBC.
Similarly when the admin would want to view inventory records they
could enter their search criteria and that would in turn populate the
InventorySearchBean and then in the business layer the SQL would be
created dynamically based on those criteria and a List of
InventoryItem objects would eventually be returned to the Action
class.
I tend to think this process is pretty clean and does separate the
view from the business. I'm wondering though about the search part. It
would seem easier to skip the whole business layer bean that is
created to just hold search criteria and instead just grab what you
need from the DynamicFormBean and populate it in a method passed on to
the business layer. For example...
Instead of:
BeanUtils.copyProperties( inventorySearchBean, dynFormBean );
ArrayList items = ServiceObject.getInventoryList( inventorySearchBean );
you could do:
ArrayList items = ServiceObject.getInventoryList(
(String)dynFormBean.get("invDate"),
(String)dynFormBean.get("minimumPrice" ),
(String)dynFormBean.get("itemType"), ..etc );
I'm interested in other's opinions.
Thanks,
--
Rick
mailto:[EMAIL PROTECTED]
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>