0

I want to use a tld function which is simply implemented, MyAccessManager being an abstract class and having 2 children overriding a function differently:

public static <T extends MyAccessManager> boolean isAllowed(T accessMan, MyTypeEnum otherUsersEnum){
    // trivial implementation
}

I defined above method also in my tld definition file (*.tld).

I have 2 classes which extends my MyAccessManager and I am using function via EL like:

<input name="foo" type="hidden" value="${mytaglib:isAllowed(param1, param2)}"/>

I pass right parameters (ie children class instances as param1) to my tld function but webapp throws below exception:

org.apache.jasper.JasperException: PWC6300: The class T specified in the method signature in TLD for the function mytaglib:isAllowed cannot be found. T

My tld file:

<function>
      <description>Processes users access to specific resources</description>
      <name>isAllowed</name>
      <function-class>com.myproj.MyUtil</function-class>
      <function-signature>boolean isAllowed(T,com.myproj.MyTypeEnum)</function-signature>
</function>

Does TLD not support java's Type Parameters? Or, is there any way to implement such a functionality?

px5x2
  • 1,495
  • 2
  • 14
  • 29

1 Answers1

1

I don't understand why do you need T at all.

It's a typical case of polymorphism, you don't need type parameters and other generic stuff here:

public static boolean isAllowed(MyAccessManager accessMan, MyTypeEnum otherUsersEnum){ ... }

.

<function-signature>boolean isAllowed(MyAccessManager,com.myproj.MyTypeEnum)</function-signature>  
axtavt
  • 239,438
  • 41
  • 511
  • 482
  • This creates error also, indeed that approach was my first attempt. The exception is java.lang.ClassCastException. It cannot cast my child class to its parent weirdly.. – px5x2 Aug 09 '12 at 10:17
  • My bad, I had 2 seperate AccessManager. I cast it to the right one, but I still wonder, whether this kind of usage above in my post is possible. – px5x2 Aug 09 '12 at 10:22
  • I guess it's not possible due to type erasure, so that you have to use erased version of the signature in TLD. But actually it doesn't make much sense anyway. – axtavt Aug 09 '12 at 10:24