How to declare a custom jsp tag with required HashMap<String, String>?
-
14-07-2021 - |
質問
In my class, I need a HashMap. How to declare this in tld?
<attribute>
<name>map</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.util.HashMap</type>
</attribute>
Update: The above code works. But I want to specify the type of HashMap
How is:
HashMap<?,?>
How I want:
HashMap<String, String>
解決
I found the solution:
<type><![CDATA[java.util.HashMap<java.lang.String, java.lang.String>]]</type>
他のヒント
I don't think you can specify the type there on a tag. You can do that with a custom el function:
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="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 web-jsptaglibrary_2_0.xsd"
version="2.0">
<tlib-version>1.0</tlib-version>
<short-name>shortname</short-name>
<uri>http://some/uri</uri>
<function>
<name>testMethod</name>
<function-class>
somePackage.TestFunction
</function-class>
<function-signature>
java.lang.String testMethod( java.util.HashMap)
</function-signature>
</function>
</taglib>
Corresponing class:
public class TestFunction {
public static String testMethod(HashMap<?, ?> map) {
return map.toString();
}
}
所属していません StackOverflow