java - 具有多个属性和功能的自定义标签?
问题描述
这是在单个 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 页面一次性调用它。
谢谢
解决方案
在您的 tld 文件中,您可以执行以下操作:
函数.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>
我的jsp.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)}
推荐阅读
- javascript - 咖喱lodash api方法
- android - 服务器验证与设备验证
- c# - 使用 Selenium WebDriver 访问 Chrome 浏览器控制台
- multi-tenant - LibreOffice Online - 具有 access_header 的多个用户
- google-drive-api - 需要刷新令牌而不使用 G Suite 中的同意屏幕
- java - 有什么方法可以让@InitBinder 使用地图参数或覆盖spring默认的HandlerMethodArgumentResolver?
- netezza - 在 Netezza 中查找 VARCHAR 和 DATE 之间的年数
- javascript - Chrome 显示所有请求
- assembly - 汇编x86检查3个值是否可以形成一个三角形
- javascript - 在 div 中使用脚本(在 react .js 文件中)会引发错误