Strecks uses user interface technologies already in use in Struts applications - it does not aim to replace any of these. However, it does add a few JSP custom tags in support of the existing Struts tag libraries and to support Strecks-specific functionality.
Class Name: org.strecks.web.tag.FieldLabelTag
The field label tag is used to help co-ordinate the display of form field labels. It allows the label formatting to be modified if a field has failed validation. It also allows the display of required markers (e.g. *) to be set up in a modular way.
property | The form property with which the label is associated |
label | The string used for the label. Will not be used if labelKey attribute is defined (see below) |
labelKey | The message key used to look up the label for the field |
errorPrefix | The messages key used for the prefix if the field is in error. Defaults to "field.error.prefix " |
errorSuffix | The messages key used for the suffix if the field is in error. Defaults to "field.error.suffix " |
required | Whether a value for the field is required.
Normally, will be used in conjuction with a field with the @ValidateRequired annotation |
requiredPrefix | The messages key used to look up the required text.
If none is specified, then the key "field.required.prefix " is used |
requiredSuffix | The messages key used to look up the required text.
If none is specified, then the key "field.required.suffix " is used |
The example below shows two field labels. In the first, for the property title, the defaults are used. In this case, the default message keys will be used to look up the required and error suffix text. In the second property, error and required prefixes and suffixes are explicitly set, allowing for more control on a field-by-field basis at the expense of more verbose markup.
... <tr> <td><strecks:fieldLabel labelKey="holidaybookingform.title" property="title" required = "true"/></td> <td><html:text property="title" size="80" /></td> </tr> <tr> <td><strecks:fieldLabel errorPrefix="field.error.prefix" errorSuffix="field.error.suffix" requiredPrefix = "field.required.prefix" requiredSuffix = "field.required.suffix" labelKey="holidaybookingform.startDate" required="true" property="startDate" /></td> <td><html:text property="startDate" size="17" /></td> </tr>
The Strecks bind tag is used to bind a page context attribute to an object referenced in either request, session or application scope. This is particularly useful when using view helper objects or using the page class, and you want the current iteration in a loop to be accessible from the helper class.
Class Name: org.strecks.web.tag.BindTag
sourceAttribute | The source attribute in the context used to obtain the attribute value |
targetExpression | The target expression for binding the attribute value |
targetScope | The scope for looking up the root object idenitified using the target expression. Must be 'page', 'request', 'session' or 'application' ('request' by default) |
In the example below, the object referenced by the current iteration is
bound to the currentValue
property of the action bean. The action bean is held in
page scope using the attribute name actionBean
.
<c:forEach items="${actionBean.values}" var="currentItem"> <strecks:bind sourceAttribute="currentItem" targetExpression="actionBean.currentValue" targetScope="page"/> <li><c:out value="${actionBean.stringValue}" /></li> </c:forEach>
Notice how the action bean has a synthetic property getStringValue()
which can be used
to transform or format the value of the bound object. The implemementation of getStringValue()
is shown below.
public String getStringValue() { return "Number " + currentValue; }
This tag exposes the action bean instance for the current request as a user-defined page scoped attribute. This allows properties of the action bean to be accessed directly via JSTL.
Class Name: org.strecks.web.tag.ActionBeanTag
var | The name of the page context variable to which the action bean should be bound |
The example shows how the action bean used in the bind tag example is exposed as a page scoped attribute.
<strecks:actionBean var = "action"/>
This tag exposes the page bean instance associated with the current page (if there is one) as a user-defined page scoped attribute. This allows properties of the page bean to be accessed directly via JSTL.
Class Name: org.strecks.web.tag.PageBeanTag
var | The name of the page context variable to which the page bean should be bound |
This example shows how the current page bean instance is exposed as a page-scoped attribute
named page
.
<strecks:pageBean var = "page"/>