JSP Tag Libraries

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


elementsList = null;


}


}

О Parses the list of strings into a Java list and creates an enumerator.
e If we have an element in the list, continues the body evaluation; otherwise skips the body (empty iteration).
e Sets the iterator variable with the first element in the list.


Iterating with tags

E Breaks the string list into a Java list.


F Writes the results of this iteration back to the user and clears the body buffer.


О If we have more elements in the list, exports a new iterator value and repeats evaluating the body.


The work in simpieForeachTag takes place in three designated locations:


■    The service phase initialization in dostartTag(). The tag initializes the set of objects on which we plan to iterate, and determines if we need to process the body. This is not necessary if the list of objects is empty.


■    The loop initialization in doinitBody(). The tag exports the needed iterator object by calling pageContext. setAttribute() with the name of the object and the object itself. In doing so, we publish the iterator as a scripting variable, so that it ends up in the scope in the JSP (a practice we first came across with JavaBean tags in chapter
8). By exporting the iterator object, other tags and scriptlets can take advantage of it.


■    The loop termination/repeating in doAfterBody(). The tag writes the results of the last loop into the previous writer (usually the writer that goes to the user) and then clears the body content to prepare it for the next iteration. In the final step, if there are additional items to iterate, the tag exposes a new iterator value and signals the JSP environment to repeat the execution by returning EVAL_BODY_TAG.

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