JSP custom TLD Method labels

Source: Internet
Author: User
Tags tld

Horizontal slot

With TLD files, we can customize a method label for use in the page, and the directory is usually placed in the TLDs folder below the Web-inf:

Introduction to an example of a TLD tag file directly on the JSP:

<% @ taglib Prefix = " FNS " URI = " /web-inf/tlds/fns.tld " %>
Fns.tld in the following:
<?XML version= "1.0" encoding= "UTF-8"?><taglibxmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"version= "2.0">      <Description>JSTL 1.1 Functions Library</Description>  <Display-name>JSTL functions Sys</Display-name>  <tlib-version>1.1</tlib-version>  <Short-name>Fns</Short-name>  <URI>Http://java.sun.com/jsp/jstl/functionss</URI><!--dictutils -  <function>    <Description>Get Dictionary Tags</Description>    <name>Getdictlabel</name>    <Function-class>Com.jeeplus.modules.sys.utils.DictUtils</Function-class>    <function-signature>Java.lang.String Getdictlabel (java.lang.String, java.lang.String, java.lang.String)</function-signature>    <Example>${fns:getdictlabel (value, type, defaultvalue)}</Example>    </function>    <function>    <Description>Get dictionary labels (multiple)</Description>    <name>Getdictlabels</name>    <Function-class>Com.jeeplus.modules.sys.utils.DictUtils</Function-class>    <function-signature>Java.lang.String getdictlabels (java.lang.String, java.lang.String, java.lang.String)</function-signature>    <Example>${fns:getdictlabels (values, type, defaultvalue)}</Example>    </function>  <function>    <Description>Get dictionary value</Description>    <name>Getdictvalue</name>    <Function-class>Com.jeeplus.modules.sys.utils.DictUtils</Function-class>    <function-signature>Java.lang.String Getdictvalue (java.lang.String, java.lang.String, java.lang.String)</function-signature>    <Example>${fns:getdictvalue (label, type, defaultvalue)}</Example>    </function>

Note:
Function-class is the classpath of the entity of the method,

Function-signature is the method name of the method, and this method must be a static method.
Example is an example of how to use

Background:

 Public Staticstring Getdictlabel (string value, String type, string defaultvalue) {if(Stringutils.isnotblank (type) &&Stringutils.isnotblank (value)) {             for(Dict dict:getdictlist (type)) {if(Type.equals (Dict.gettype ()) &&value.equals (Dict.getvalue ())) {                    returnDict.getlabel (); }            }        }        returnDefaultValue; }         Public Staticstring Getdictlabels (String values, String type, string defaultvalue) {if(Stringutils.isnotblank (type) &&Stringutils.isnotblank (values)) {List<String> valueList =lists.newarraylist ();  for(String Value:StringUtils.split (values, ",") {valuelist.add (Getdictlabel (value, type, defaultvalue)); }            returnStringutils.join (ValueList, ","); }        returnDefaultValue; }     Public Staticstring Getdictvalue (String label, String type, String Defaultlabel) {if(Stringutils.isnotblank (type) &&Stringutils.isnotblank (label)) {             for(Dict dict:getdictlist (type)) {if(Type.equals (Dict.gettype ()) &&label.equals (Dict.getlabel ())) {                    returnDict.getvalue (); }            }        }        returnDefaultlabel; }

Used in JSP pages:

< TD >        ${fns:getdictlabel (preparationmanage.preparationmode, ' samplingmode ', ')}             
</ TD >

JSP custom TLD Method labels

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.