Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This page contains high level information about the Stripes tag library. Other more detailed sources of information concerning the tag library include:

...

The Stripes standard tag library does not permit the use of non-standard attributes for an tag that is the analog of an HTML tag, for example <stripes:text>. As a result they also do not allow dynamic attributes (dynamic attributes are a JSP system for accepting arbitrary attributes who's names are not know when the tag is written). The primary reason for this is to cut down on runtime errors for JSP developers. Most modern IDEs will catch mistakes in tag attributes and alert the developer. A fairly benign example might be:

Code Block
xml
languagexml
<stripes:submit name="save" onlick="validate(this)"/>

...

However with the advent of AJAX and JavaScript libraries it is sometimes desirable to use non-HTML attributes in HTML tags. For the reasons outlined above Stripes includes two slightly different TLDs that can be used. The standard one does not allow dynamic attributes in HTML tags and should be used in most cases. The second one allows dynamic attributes. It is possible (even recommended) to use both TLDs in one page. Doing so will allow the standard library to be used where possible, and the dynamic attribute one only where absolutely necessary. E.g.:

Code Block
xml
languagexml
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %>
<%@ taglib prefix="d" uri="http://stripes.sourceforge.net/stripes-dynattr.tld" %>

<s:form action="/my/NewsSearch.action">
	<s:text name="keywords"/>
	<d:text name="publicationDate" dojoType="calendar"/>
	<s:submit name="search"/>
</s:form>

...

If neither of these strategies meets your needs, worry not! It is very easy to change this behaviour - the DefaultPopulationStrategy was built with subclassing in mind. It provides individual methods to fetch an approprate value for the tag from the request, from the ActionBean and from the tag itself. It also contains a helper method to determine if the form is in error - in case it is desirable to modify behaviour based on error state. In order to change the PopulationStrategy all you need to do is subclass the DefaultPopulationStrategy and override the getValue(InputTagSupport tag) method to search in a different order. An example class is below:

Code Block
languagejava
titleAn alternative population strategy
public class MyPopulationStrategy extends DefaultPopulationStrategy {
	/** Strategy to look at the ActionBean first, then the request, then the page.*/
	public Object getValue(InputTagSupport tag) throws StripesJspException {
		Object value = getValueFromActionBean(tag);
		if (value==null) value = getValuesFromRequest(tag);
		if (value==null) value = getValueFromTag(tag);

	return value;
	}
}

Configuring the alternative population strategy is as simple as adding an initialization parameter for the StripesFilter, e.g.

Code Block
xml
languagexml
titleConfiguring an alternative population strategy
....
<init-param>
	<param-name>PopulationStrategy.Class</param-name>
	<param-value>com.myco.web.MyPopulationStrategy</param-value>
</init-param>
....