📄 jsptags6.html
字号:
The unique name of the attribute being declared. A translation error results if more than one <code class="cCode">attribute</code> element appears in the same tag with the same <code class="cCode">name</code>.</div></td></tr> <tr align="left"> <td><a name="wp90399"> </a><div class="pCellBody"><code class="cCode">required</code></div></td> <td><a name="wp90401"> </a><div class="pCellBody">(optional) Whether the attribute is required. The default is <code class="cCode">false</code>.</div></td></tr> <tr align="left"> <td><a name="wp90403"> </a><div class="pCellBody"><code class="cCode">rtexprvalue</code></div></td> <td><a name="wp90405"> </a><div class="pCellBody">(optional) Whether the attribute's value may be dynamically calculated at runtime by an EL expression. The default is <code class="cCode">false</code>.</div></td></tr> <tr align="left"> <td><a name="wp90407"> </a><div class="pCellBody"><code class="cCode">type</code></div></td> <td><a name="wp90409"> </a><div class="pCellBody">(optional) The runtime type of the attribute's value. Defaults to <code class="cCode">java.lang.String</code> if not specified.</div></td></tr> <tr align="left"> <td><a name="wp90411"> </a><div class="pCellBody"><code class="cCode">fragment</code></div></td> <td><a name="wp90413"> </a><div class="pCellBody">(optional) Whether this attribute is a fragment to be evaluated by the tag handler (true) or a normal attribute to be evaluated by the container prior to being passed to the tag handler. </div><a name="wp90414"> </a><div class="pCellBody"> </div><a name="wp90415"> </a><div class="pCellBody">If this attribute is true:</div><a name="wp90416"> </a><div class="pCellBody">You do not specify the <code class="cCode">rtexprvalue</code> attribute. The container fixes the <code class="cCode">rtexprvalue</code> attribute at <code class="cCode">true</code>.</div><a name="wp90417"> </a><div class="pCellBody">You do not specify the <code class="cCode">type</code> attribute. The container fixes the <code class="cCode">type</code> attribute at <code class="cCode">javax.servlet.jsp.tagext.JspFragment</code>.</div><a name="wp90418"> </a><div class="pCellBody"> </div><a name="wp90419"> </a><div class="pCellBody">Defaults to <code class="cCode">false</code>.</div></td></tr></table></div><p class="pBody"></p><a name="wp90420"> </a><p class="pBody">If a tag attribute is not required, a tag handler should provide a default value.</p><a name="wp90421"> </a><p class="pBody">The <code class="cCode">tag</code> element for a tag that outputs its body if a test evaluates to true declares that the <code class="cCode">test</code> attribute is required and that its value can be set by a runtime expression. </p><div class="pPreformattedRelative"><pre class="pPreformattedRelative"><tag> <name>present</name> <tag-class>condpkg.IfSimpleTag</tag-class> <body-content>scriptless</body-content> ... <attribute> <name>test</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> ...</tag><a name="wp90422"> </a></pre></div><a name="wp90424"> </a><h3 class="pHeading2">Declaring Tag Variables for Tag Handlers</h3><a name="wp90428"> </a><p class="pBody">The example described in <a href="JSPTags4.html#wp89646">Tags That Define Variables</a> defines an EL variable <code class="cCode">departmentName</code>:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative"> <tlt:iterator var="departmentName" type="java.lang.String" group="${myorg.departmentNames}"> <tr> <td><a href="list.jsp?deptName=${departmentName}"> ${departmentName}</a></td> </tr> </tlt:iterator><a name="wp90429"> </a></pre></div><a name="wp90430"> </a><p class="pBody">When the JSP page containing this tag is translated, the Web container generates code to synchronize the variable with the object referenced by the variable. To generate the code, the Web container requires certain information about the variable: </p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp90432"> </a><div class="pSmartList1"><li>Variable name</li></div><a name="wp90433"> </a><div class="pSmartList1"><li>Variable class</li></div><a name="wp90434"> </a><div class="pSmartList1"><li>Whether the variable refers to a new or existing object</li></div><a name="wp90435"> </a><div class="pSmartList1"><li>The availability of the variable </li></div></ul></div><a name="wp90436"> </a><p class="pBody">There are two ways to provide this information: by specifying the <code class="cCode">variable</code> TLD subelement or by defining a tag extra info class and including the <code class="cCode">tei-class</code> element in the TLD (see <a href="JSPTags7.html#wp90643">TagExtraInfo Class</a>). Using the <code class="cCode">variable</code> element is simpler, but less dynamic. With the <code class="cCode">variable</code> element, the only aspect of the variable that you can specify at runtime is its name (via the <code class="cCode">name-from-attribute</code> element). If you provide this information in a tag extra info class, you can also specify the type of the variable at runtime. </p><a name="wp90511"> </a><p class="pBody"><a href="JSPTags6.html#wp90451">Table 15-11</a> lists the subelements of the <code class="cCode">variable</code> element.</p><div align="left"><table border="1" summary="variable Subelements" id="wp90451"> <caption><a name="wp90451"> </a><div class="pTableTitle">Table 15-11 variable Subelements </div></caption> <tr align="center"> <th><a name="wp90455"> </a><div class="pCellHeading">Element</div></th> <th><a name="wp90457"> </a><div class="pCellHeading">Description</div></th></tr> <tr align="left"> <td><a name="wp90459"> </a><div class="pCellBody"><code class="cCode">description</code></div></td> <td><a name="wp90461"> </a><div class="pCellBody">(optional) A description of the variable.</div></td></tr> <tr align="left"> <td><a name="wp90463"> </a><div class="pCellBody"><code class="cCode">name-given | name-from-attribute</code></div></td> <td><a name="wp90465"> </a><div class="pCellBody">Defines an EL variable to be used in the page invoking this tag. Either <code class="cCode">name-given</code> or <code class="cCode">name-from-attribute</code> must be specified. If <code class="cCode">name-given</code> is specified, the value is the name of the variable. If <code class="cCode">name-from-attribute</code> is specified, the value is the name of an attribute whose (translation-time) value at of the start of the tag invocation will give the name of the variable. </div><a name="wp90466"> </a><div class="pCellBody">Translation errors arise in the following circumstances:</div><a name="wp90467"> </a><div class="pCellBody"> </div><a name="wp90468"> </a><div class="pCellBody">1. Specifying neither <code class="cCode">name-given</code> or <code class="cCode">name-from-attribute</code> or both. </div><a name="wp90469"> </a><div class="pCellBody">2. If two <code class="cCode">variable</code> elements have the same <code class="cCode">name-given</code>.</div></td></tr> <tr align="left"> <td><a name="wp90471"> </a><div class="pCellBody"><code class="cCode">variable-class</code></div></td> <td><a name="wp90473"> </a><div class="pCellBody">(optional) The fully qualified name of the class of the object. <code class="cCode">java.lang.String</code> is the default.</div></td></tr> <tr align="left"> <td><a name="wp90475"> </a><div class="pCellBody"><code class="cCode">declare</code></div></td> <td><a name="wp90477"> </a><div class="pCellBody">(optional) Whether the object is declared or not. True is the default.A translation error results if both <code class="cCode">declare</code> and <code class="cCode">fragment</code> are specified.</div></td></tr> <tr align="left"> <td><a name="wp90479"> </a><div class="pCellBody"><code class="cCode">scope</code></div></td> <td><a name="wp90481"> </a><div class="pCellBody">(optional) The scope of the variable defined. Can be either <code class="cCode">AT_BEGIN</code>, <code class="cCode">AT_END</code>, or <code class="cCode">NESTED</code> (see <a href="JSPTags6.html#wp90492">Table 15-12</a>). Defaults to <code class="cCode">NESTED</code>.</div></td></tr></table></div><p class="pBody"></p><div align="left"><table border="1" summary="Scripting Variable Availability" id="wp90492"> <caption><a name="wp90492"> </a><div class="pTableTitle">Table 15-12 Variable Availability </div></caption> <tr align="center"> <th><a name="wp90496"> </a><div class="pCellHeading">Value</div></th> <th><a name="wp90498"> </a><div class="pCellHeading">Availability</div></th></tr> <tr align="left"> <td><a name="wp90500"> </a><div class="pCellBody"><code class="cCode">NESTED</code></div></td> <td><a name="wp90502"> </a><div class="pCellBody">Between the start tag and the end tag.</div></td></tr> <tr align="left"> <td><a name="wp90504"> </a><div class="pCellBody"><code class="cCode">AT_BEGIN</code></div></td> <td><a name="wp90506"> </a><div class="pCellBody">From the start tag until the scope of any enclosing tag. If there's no enclosing tag, then to the end of the page.</div></td></tr> <tr align="left"> <td><a name="wp90508"> </a><div class="pCellBody"><code class="cCode">AT_END</code></div></td> <td><a name="wp90510"> </a><div class="pCellBody">After the end tag until the scope of any enclosing tag. If there's no enclosing tag, then to the end of the page. </div></td></tr></table></div><p class="pBody"></p><a name="wp90512"> </a><p class="pBody">You could define the following <code class="cCode">variable</code> element for the <code class="cCode">tlt:iterator</code> tag:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative"><tag> <variable> <name-given>var</name-given> <variable-class>java.lang.String</variable-class> <declare>true</declare> <scope>NESTED</scope> </variable></tag><a name="wp90513"> </a></pre></div> </blockquote> <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"> <table width="550" summary="layout" id="SummaryNotReq1"> <tr> <td align="left" valign="center"> <font size="-1"> <a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a> </td> <td align="center" valign="center"><a accesskey="p" href="JSPTags5.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="JSPTags7.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a> </td> <td align="right" valign="center"> <font size="-1"> <a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font> </font> </td> </tr> </table> <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"><p><font size="-1">All of the material in <em>The J2EE(TM) 1.4 Tutorial</em> is <a href="J2EETutorialFront2.html">copyright</a>-protected and may not be published in other workswithout express written permission from Sun Microsystems.</font> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -