Step 3: Create attributes in the label handler Java class
Page 5 (9 pages a total)
We want to specify three properties for the MaPDefine tag, as shown below:
Property Description ID The name of the new Scriptlet variable. Scope new ScriptleT variables are located. Type new Scriptlet variable (HashMap, FasthashMap, TreeMap, or FastTreeMap). If Type is set to Hash, you will create a HashMap. If Type is set to Fasthash, FasthashMap will be created. When using this tag in the JSP page, it looks like this:
Step 4: Define properties in a TLD file
Page 6 (9 pages a total)
Just as in the previous section, the custom property is defined by declaring the JavaBean property, and then declare these properties in the TLD file. Each JavaBean property must match the corresponding custom tag properties. The attribute defined in the TLD must match the JavaBeaN property, but it can have a javabean property that does not match the tag properties. Here is the property declaration of mapdefinetag:
Page 7 of 9
Call the dostarttag () method at the start of the label - From the developer's point of view, this is when the engine encounters
Determine the properties of the MAP to be created according to the Type property. Determine the new MAP object in what range according to the Scope property. Determine the name of the range of the new MAP object to be placed based on the id attribute. Let us analyze this process in more detail. The MAPDefine class checks the Type property is set to fasttree, haveh, Tree or Fasthash. And then create the appropriate map, as shown below: / * String constants for the different types of maps we support * / public static final String FASTHASH = "FASTHASH"; public static final String FASTTREE = "FASTTREE"; public static final String HASH = "HASH"; public static final String TREE = "TREE"; / ** The map we are going to create * / private Map map = null; / ** The member variable that holds the type attribute * / private String type = FASTTREE ; ... public int doStartTag () throws JspException {/ ** Based on the type attribute, determines which type of Map to create * / if (type.equalsIgnoreCase (FASTTREE)) {map = new FastTreeMap ();} else if (Type.equalsignorecase (HASH)) {map = new hashmap ();} else if (Type.Equalsignorecase (Tree)) {map = new treemap ();} else f (type.equalsignorecase (fasthash) {map = new FastHashMap ();} then uses the ID and Scope properties to set the HashMap to a given range in a given name: private string id; private intendTAG () throws jspexception {... if (Scope == null) {pageContext.setttribute (ID, m ap);} else if ( "page" .equalsIgnoreCase (scope)) {pageContext.setAttribute. (id, map);} else if ( "request" .equalsIgnoreCase (scope)) {pageContext.getRequest () setAttribute (id, map);} else if ( "session" .equalsIgnoreCase (scope)) {pageContext.getSession () setAttribute (id, map);.} else if ( "application" .equalsIgnoreCase (scope)) {pageContext.getServletContext (). SetAttribute (ID, MAP);} returnval_body_includ;} If the range attribute is null, the MAP will put into the page range.