【问题标题】:Custom tag with more than one attribute and function?具有多个属性和功能的自定义标签?
【发布时间】:2019-09-27 06:38:42
【问题描述】:

这是在单个 tld 文件(即自定义标签)中写入多个属性和多个函数的正确方法。

这是代码中的标签:


     <tag>
        <name>cardwidgettags</name>
        <tag-class>com.sciformix.sciportal.apps.dap.CardWidget</tag-class>
        <body-content>empty</body-content>

        <attribute>
            <name>title</name>
            <required>true</required>
        </attribute>
        <attribute>
            <name>link</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>icon</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>




    </tag> 
    <function>
            <name>addLineItem</name>
            <function-class>.dap.CardWidget</function-class>
            <rtexprvalue>true</rtexprvalue>
            <function-signature>void addLineItem(java.lang.String, java.lang.String, java.lang.String)</function-signature>
    </function>
</taglib>

如何从jsp页面一次性调用。

谢谢

【问题讨论】:

    标签: java jsp jstl


    【解决方案1】:

    在您的 tld 文件中,您可以执行以下操作:

    functions.tld

            <?xml version="1.0" encoding="UTF-8"?>
            <taglib version="2.1"
                xmlns="http://java.sun.com/xml/ns/javaee"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">
    
            <tlib-version>1.0</tlib-version>
            <short-name>functions</short-name>
            <uri>http://anyurl.com/myfunctions</uri>  <!-- define url to access functions from jsp file -->
    
            <function>
                <name>functionOne</name> <!-- function name -->
                <function-class>com.mypackage.MyUtilClass</function-class> <!-- full path to your class where define function -->
                <function-signature>void functionOne(java.lang.Integer, java.lang.Integer, java.lang.Integer)</function-signature>
            </function>
    
            <function>
                <name>functionTwo</name> <!-- function name -->
                <function-class>com.mypackage.MyUtilClass</function-class> <!-- full path to your class where define function -->
             <function-signature>void functionTwo(java.lang.String, java.lang.String, java.lang.String)</function-signature>
            </function>
    
      </taglib>
    

    myjsp.jsp

        <%@ page contentType="text/html;charset=UTF-8" language="java" %>
        <%@ taglib prefix="myfnc" uri="http://anyurl.com/myfunctions" %> <!-- url is defined above -->
    ...
    ${myfnc:functionTwo("str1","str2", "str3")}
    ${myfnc:functionOnw(1, 2, 3)}
    

    【讨论】:

      猜你喜欢
      • 2022-01-19
      • 1970-01-01
      • 2016-05-09
      • 2012-07-04
      • 2019-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多