ignore

Developing Forms

ActionForms in Strecks fundamentally no different from regular Struts ActionForms, with two major differences. First, annotations can be used to define validators for fields as well as to perform data binding from form properties to domain objects. Second, Strecks applications will tend to use fewer ActionForms than plain Struts applications. This is because the @RequestParameter annotation provides a mechanism to capture and type convert request parameters, a feature missing from plain Struts. This means that ActionForms are only really required for handling input in situations where validation is required. In other words, ActionForms are only really necessary for handling HTML form input.

As in plain Struts, Strecks ActionForm properties tend to be Strings, especially for single value fields. Data binding and type conversion occurs within the form itself, that is, from the form property to a typed property of a domain object nested within the form.

An example of a Strecks action form is shown below:

public class ExampleActionForm extends ActionForm
{

	private static final long serialVersionUID = 7423616982362263002L;

	private String numberField;

	private DomainObject domainObject;

	/* ************** form property getters and setters ************* */	
	
	@BindSimple(expression = "domainObject.domainInteger")
	public String getNumberField()
	{
		return numberField;
	}

	@ValidateRequired(key = "number.required")
	@ValidateInteger(key = "field.must.be.number")
	public void setNumberField(String numberField)
	{
		this.numberField = numberField;
	}

	/* ************** domain getters and setters ************* */
	
	public DomainObject getDomainObject()
	{
		return domainObject;
	}

	public void setDomainObject(DomainObject domainObject)
	{
		this.domainObject = domainObject;
	}

}

The form has getters and setters both for form properties and domain model objects. In the above example, there is just one form property, numberField. Using the @BindSimple annotation, it is type converted and bound to an Integer property (named domainInteger) of the class DomainObject. Data binding and type conversion annotations are applied to form property setter methods.

Validators can also be applied to form properties, this time using setter method validation annotations. Note that the ActionForm's validate() method will still be called, allowing for programmatic validation to handle scenarios that the annotations cannot cover. The current behaviour of Strecks is to call the annotation-based validations first, then call ActionForm.validate(), merging any ActionMessages returned into a single ActionErrors object. In future versions, it is likely that this behaviour will be customisable on a per-form basis.

SourceForge.net logo java.net Member logo Copyright © 2005-2007 Realsolve Solutions