Java Reference
In-Depth Information
Figure 6.7: Highlighting labels and input fields for errors
The DefaultTagErrorRenderer adds the class= "error" attribute to tags that
are in error. If the tag already had another class= defined, such as
"myClass", the renderer produces class="error myClass" to preserve any
previously specified CSS classes.
Suppose we want to display ** after tags that are in error, as illustrated
in Figure 6.8 , on the following page. We can do this with a simple imple-
mentation of TagErrorRenderer :
Download email_11/src/stripesbook/ext/MyTagErrorRenderer.java
package stripesbook.ext;
public class MyTagErrorRenderer implements TagErrorRenderer {
private InputTagSupport tag;
public void init(InputTagSupport atag) { tag = atag; }
public void doBeforeStartTag() { }
public void doAfterEndTag() {
try { tag.getPageContext().getOut().write(" ** "); }
catch (IOException exc)
{ throw new StripesRuntimeException(exc); }
}
}
TagErrorRenderer implementations are Stripes extensions, so having the
MyTagErrorRenderer class in the stripesbook.ext package is enough to have
it automatically loaded by Stripes. Remember that on page 115 we con-
figured stripesbook.ext in web.xml as an extension package with the Exten-
sion.Packages parameter.
 
 
Search WWH ::




Custom Search