Using varargs in a Tag Library Descriptor

后端 未结 4 1636
情话喂你
情话喂你 2021-01-11 17:18

Is it possible to have a TLD map to the following function:

public static  T[] toArray(T... stuff) {
    return stuff;
}

So that I

4条回答
  •  醉酒成梦
    2021-01-11 18:00

    Unfortunately that's not possible. The EL resolver immediately interprets the commas in the function as separate arguments without checking if there are any methods taking varargs. Your best bet is using JSTL fn:split() instead.

    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
    ...    
    
        ${item}

    It would have been a nice feature in EL however, although implementing it would be pretty complex.

提交回复
热议问题