Export function to TLD

I want to export this function to custom-functions.tld :

 package com.site.vo; public class Utils { public static String concat(String... values) { String out = ""; for (String value : values) { out.concat(value); } return out; } } 

Here is my custom-functions-tld file:

 <?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 http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0"> <tlib-version>2.0</tlib-version> <uri>/WEB-INF/custom-functions.tld</uri> <function> <description>Concatenate strings</description> <name>concat</name> <function-class>com.site.vo.Utils</function-class> <function-signature>java.lang.String concat(java.lang.String...)</function-signature> </function> </taglib> 

That function-signature did not work, I got the following exception:

org.apache.jasper.JasperException: The class java.lang.String... specified in the method signature in TLD for the function f:concat cannot be found. java.lang.String...

Tried java.lang.String[] , but it expects only one parameter (list, d'oh!). I am looking for the right signature function to export functions with multiple parameters.

Thank you in advance!

+4
source share
1 answer

You should try switching to Java EE 6. Then you can use the new Unified Expression Language and save yourself from the nightmare of creating your own taglib.

It allows you to directly call methods on your specific beans.

+5
source

Source: https://habr.com/ru/post/1383273/


All Articles