You're not going to be able to get around some kind of mapping. Either the backend has to know what the front end looks like or vice-versa. In my experience, the back end changes less frequently than the front end, so it makes sense for the front-end developers to perform the mapping.
That being said, you can create a helper class that takes a DynaActionForm (or simply a Map with name-value pairs) with some predictable set of keys and maps them onto a set of POJOs. Once that mapping helper is done it can be re-used when appropriate, and if changes are necessary they only need to be done in one place.
If you want to get really sophisticated, you can create an XML mapping document that maps named keys to property names and use that to drive the mapping helper. That way you could (potentially) change the mapping behavior without changing code. For example, suppose a developer adds a property to a struts <form> element (configuration), adds a field to a JSP (might as well be configuration), and then adds a mapping to the XML document (configuration), which accomplishes the change without bothering the back end folks.
But then you have configurations to deal with...on top of web.xml, struts-config.xml, and your Hibernate mapping files. It really depends on the size of the project and the required flexibility as to whether it would be worth it. Personally, I would start with a plain old Java helper class to do the mapping and expand on that as needed (i.e. establish the API and then change the implementation later if necessary).
Hope that helps,
- Jesse
|