I don't really like the first solution.

Second solution sounds promising but there's an extra call. But thats
still better than the first solution or using hidden fields in JSP.

I thought of putting the TO in session as well to prevent another DB
call. But that will make everything very confusing and complex on the
web tier..

Still looking for an ideal solution.

This problem is quite common I think, someone here must have a best
practices for this so I am waiting for one..

Thanks Rick.

Sebastian Ho


On Wed, 2004-08-25 at 14:39, Rick Reumann wrote:
> Sebastian Ho wrote:
> 
> > 
> > Say I retrieve a TO from database and convert it into a actionForm for
> > display. In this case I have 4 fields for my actionForm but 10 in my TO.
> > (6 are not needed for display). A user updates the 4 fields and the
> > action convert those into TO. In this case, the other 6 fields will be
> > reset to null(or empty) in my database!
> > 
> > To prevent this, I actually need to use hidden fields in my JSP or some
> > other ugly solutions in my Action class. They are still dependent on
> > each others afterall.
> 
> You can handle this several ways...
> 
> For example, one solution is you create a TransferObject that refers to 
> only the fields you care about - in this case the 4 fields you 
> mentioned. So your call to the business layer would return that 
> TransferObject and you could then convert that easily to your form 
> (using BeanUtils). Then going back the other way your business layer 
> would take as an arguemnt the same type of TransferObject.
> 
> I actually don't prefer the above, though, because say later on you 
> decide you want to add another field to your form now your backend has 
> to worry about handling a new object with different fields.
> 
> I think the best solution is to simply make another call to get back the 
> initial TO from the db, then simply use BeanUtils to populate that TO 
> with the form fields. It will only set the fields in which it has the 
> same names for so your other data will be fine.
> 
> So it looks like...
> 
> TransferObject to = BackendEnd.getMyTransferObject(..);
> MyForm myForm = (MyForm)form;
> BeanUtils.copyProperties( to, myForm);
> BackEnd.doUpdate( to );
> 
> Pretty simple I think. Just make sure your ActionForm doesn't contain 
> properties that you don't care about editing otherwise it will 
> over-write the TO properties. If the JSP form is going to be very 
> dyanmic, as in it will sometimes have some properties and sometimes have 
> others, then you will have to use more complex 'tricks' such as using 
> hidden variables.. or I'd just prefer to manually set the TO fields in 
> the Action.


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

Reply via email to