JSP Tag Libraries

Скачать в pdf «JSP Tag Libraries»


Generally, we can make a clear distinction between:


■    Tags that need to enable/disable their entire body evaluation conditionally. Tags that belong in this group either don’t include their body, or include it unchanged, after the JSP engine has processed it.


   Tags that need to obtain their body content, either to send a modified version of the body to the user or to use it as an input to another application component.


These two cases differ greatly in the APIs that enable them, and also in the way that the JSP runtime executes the tag. The next few sections are going to tackle these issues, starting with the simple conditional body execution.

6.7.1 Tag body evaluation


As explained in chapter 4, enabling and disabling a tag’s body evaluation is performed using the dostartTag () return code protocol. As a rule, whenever dostartTag() returns a value of skip_body, the JSP runtime will ignore the tag’s body (if there is one) and neither evaluate it nor include it in the response to the user. Alternatively, a tag can enable its body evaluation by returning a value of eval_body_include (for simple tags) or eval_body_tag (for BodyTags, that is, tags that implement the BodyTag interface).


To illustrate this, we’ll modify the ShowFormParamTag such that its body can contain text to be shown if the parameter cannot be found (similar to the “alt” attribute for images in the HTML <img> tag). Our goal is to add functionality to the ShowFormParamTag that enables us to specify alternative content like this:


<td>

Скачать в pdf «JSP Tag Libraries»