Mini Book Example

The example below serves to introduce some of the basic features of StrutsLive, and particularly its new XHTML component templating capability. If you change one or more values in the Book Detail form (particularly if you try using values that are likely to trigger validation errors) and click Submit, you'll see that this modest example has some interesting dynamic behavior.

( Note: Red asterisks indicate required fields; one sure way to trigger validation errors is to blank out a required field or two prior to submitting.)

Book Details

Notes on this Example

The validation error messages displayed in this example are rendered by a nested XHTML component, ErrorMessages.xhtml, that happens to be reused in most of the examples. This little template contains a DIV whose visibility is controlled via a custom attribute ( s:isVisible) bound to an SLLayoutForm method which returns true only if the form currently has validation errors.

Field labels are automatically inserted in error messages for LABEL elements whose for attribute values can be matched up with corresponding properties fild entries. The mechanism responsible for this also automatically manages field label highlighting. These behaviors are configurable, though they're enabled by default.

Required field validation is configured via an s:required custom attribute settings on a given input element; the same setting causes a required field indicator to be rendered next to the field. The framework automatically right-pads fields that don't have the indicators so that they'll line up correctly with the ones that do.

The Title field in the example above has a s:minLength custom attribute setting with a value of 2, so submitting a title with only one or two characters will trigger a validation error.

The Price field has a s:minValue setting with a value of 1.00, so submitting a price less than one dollar will also trigger a validation error. Note that the error message is different if you submit something that isn't a currency amount than if you submit a value that is too small. Note also that the framework automatically performs type-based validations (the underlying property is a BigDecimal, so the 'validation' in this case is actually a type coercion error) even when there are no validation settings.

The framework mechanism that performs type coercion is also provides automatic formatting. Try submitting four digits, (for example, 1234) as the value for Shelf Price. Notice how the value comes back formatted as 1,234.00. You can observe similar behaviors with Dates, and other strongly typed values.