How to convert struts form bean to DTO using Common BeanUtils API?

0 comments



In struts, action form beans contains form data which is passed to the business layer and then passed to DAO layer for further processing of data. The form data is required to be transferred to DTO or VO before they are passed to business delegate classes.

There is one API that can make your life lot easier i.e. BeanUtils.copyProperties()

The only point to keep in mind is the that the business attributes names in the VO or transfer object needs to be same as form bean. This API also relieves you from data type conversion by automatically converting source bean attribute types to destination bean attribute types.

e.g. BeanUtils.copyProperties(actionForm, actionDTO);

This method is better than manually coding the transfer of data from each attribute of the form bean to the VO/DTO, which can be a tedious task. It increases maintainability of the code.

No comments:

Post a Comment

Recent Posts

Popular Posts

© 2011-2019 Web Portal Club