Iterating with tags 101 to export the values
Iterating with tags 101 to export the values of the iterator, we ll create a TagExtraInfo class for it that will inform the runtime of this. We ll call this class ForeachTagExtraInfo. Its implementation is in listing 10.2 wherein you see that it merely notifies the JSP runtime that a new scripting variable of type String is exported. Listing 10.2 Source code for the ForeachTagExtraInfo class package book.iteration; import javax.servlet.jsp.tagext.TagData; import javax.servlet.jsp.tagext.TagExtraInfo; import javax.servlet.jsp.tagext.VariableInfo; public class ForeachTagExtraInfo extends TagExtraInfo { public VariableInfo[] getVariableInfo(TagData data) { VariableInfo[] rc = new VariableInfo[1]; rc[0] = new VariableInfo(data.getId(), java.lang.String, true, VariableInfo.NESTED); return rc; } } NOTE Note that the scope defined for the scripting variable is NESTED, meaning the variable exists and is accessible only within the body of the tag that exported it. This is important since the variable we export is our iterator, and so should exist only within the body of the loop. SimpleForeachTag in action Having written SimpleForeachTag and its TagExtraInfo we can now write JSP code to work with it. Since this is only the beginning of our iteration tags discussion, we will take that same JSP fragment and make it the content of our JSP as seen in listing 10.3. Listing 10.3 JSP driver for SimpleForeachTag < %@ page errorPage="error.jsp" %> < %@ taglib uri="http://www.manning.com/jsptagsbook/iteration-taglib" prefix="iter" %>
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services