JavaSercer Pages You may be wondering why the method is called getPreviousOut( ) as opposed to getOut( ). The name is intended to emphasize the fact that you want to use the object assigned as the output to the enclosing element in a hierarchy of nested action elements. Say you have the following action elements in a page: Some template text The JSP container first creates a JspWriter and assigns it to the out variable for the page. When it encounters the action, it creates a BodyContent object and temporarily assigns it to the out variable. It creates another BodyContent for the action and, again, assigns it to out. The container keeps track of this hierarchy of output objects. Template text and output produced by the standard JSP elements end up in the current output object. Each element can get access to its own BodyContent object by calling the getBodyContent( ) method and reading the content. For the element, the content is the template text. After processing the content, it can write it to the body by getting the BodyContent for this element through the getPreviousOut( ) method. Finally, the element can process the content provided by the element and add it to the top-level output object: the JspWriter object it gets by calling the getPreviousOut( ) method. The tag handler in Example 16.2 converts all the special characters it finds in its BodyContent object using the toHTMLString( ) method in the com.ora.jsp.utils.StringFormat class, introduced in Chapter 6. It gets the content of the BodyContent by using the getString( ) method, and uses it as the argument to the toHTMLString( ) method. The result is written to the JspWriter obtained by calling getPreviousOut( ). The doAfterBody( ) method then returns SKIP_BODY, since no iteration is needed. 16.4 Letting Actions Cooperate Now that you’ve seen how to develop basic tag handlers, let’s discuss some more advanced features. In this section, we look at tag handlers that let a page author use custom actions that cooperate with each other. You have seen examples of this throughout this java blog. For instance, in Chapter 9, various types of value actions are nested within the body of an action to set the values of place holders in the SQL statement. Another example is the action with nested actions, which are used in Chapter 8: servlet hosting services
This entry was posted
on Thursday, January 18th, 2007 at 3:42 am and is filed under Java.
You can follow any responses to this entry through the RSS 2.0 feed.
Responses are currently closed, but you can trackback from your own site.