XSnapshot 1.1 beta was just released to SourceForge.

http://xsnapshot.sourceforge.net/

This is an XDoclet module that helps you generate ActionForms from POJOs with functionality for data binding/conversion between the two. You can use it for a lot of other things besides ActionForms too, like generating DTOs for remoting (Hessian, SOAP, AJAX/DWR, etc.) and I suppose you could use it with JSF too but it hasn't been tried.

The advantage XSnapshot has over simpler solutions like BeanUtils.copyProperties or the existing @struts.form tags is its more robust conversion model. This can handle cases like POJOs with a many-to-one relationship controlled by an <html:select> in the HTML form. The HTTP POST only sends back an ID, represented by a Long in the ActionForm, and somehow that has to be reconstituted into an actual POJO to update the persistent relationship (with Hibernate, anyhow).

An example of how you would mark up an object to generate a form:

/**
 * @hibernate.class table="employee"
 * @xsnapshot.snapshot-class name="form"
class="net.sf.xsnapshot.example.presentation.web.struts.forms.EmployeeForm"
 *   extends="org.apache.struts.validator.ValidatorActionForm"
 */
public class Employee {

/**
 * @hibernate.many-to-one column="location_id"
 * @xsnapshot.property match="form" name="locationId"
type="java.lang.Long" nested-property="id" copy-to-model="true"
 */
  public Location getLocation()
}

This will result in an EmployeeForm with methods "Long getLocationId()" and "setLocationId(Long)". (Simple string/int properties are much simpler.)

Then in your Actions, you call XSnapshotUtils:
employeeForm =
  (EmployeeForm)m_xsnapshotUtils.createSnapshot(employee, "form");
or
   m_xsnapshotUtils.copyIntoModel(employeeForm, employee);

this presumes that a xsnapshotUtils instance is configured, normally via Spring. There is an example app in the source distribution that shows you how to do this.

The documentation is somewhat lacking, as there are only two regular contributors to the project and we both have very limited time to devote to it (darned customers!) But the example app in the source distribution would show you how to set it up.

-- Bill
--
Bill Schneider
Chief Architect

Vecna Technologies
5004 Lehigh Rd.
College Park, MD 20740
[EMAIL PROTECTED]
t: 301-864-7253 x1140
f: 301-699-3180


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

Reply via email to