views:

196

answers:

2

With a code like this:

<c:forEach items="${customers}" var="customer">
    ${customer.name}
</c:forEach>

IntelliJ Idea is able to infer that the type of the "customer" variable in the ForEach loop is of the class "Customer" (given that Customers is something like List<Customer>). If I refactor the java customer class and change getName to getFullName, it'll change the jstl to read ${customer.fullName}.

I downloaded the source of standard.jar, and I cannot see how this can really be done. I know you're supposed to be able to emit type information with a tei-class, but the TEI class in Jakarta Taglibs does not do this. Anyone know what I am missing ?

(I am trying to make my own foreach, but will not do so unless I can get the same level of support, but I just don't see how to do it..)

+2  A: 

I believe that intellij is inferring things specifically because it is aware of the common libraries in JSF/Facelets/JSP. I don't think that there is anything exposed by the taglibs to indicate this to the IDE.

I am not sure if they offer any hooks for you to make the feature support your own tag extensions, but I doubt it.

jsight
+2  A: 

I think that Idea has code written specifically to support the JSTL, rather than being able to do this dynamically for any tag library, based on the tag and TLD.

In your example, how is "customers" initialized? If Idea can see that a method like List<Customer> getCustomers() is invoked somewhere, it can reflect on that Method and discover that the type parameter of the List is Customer. Otherwise, I don't know how it can figure this out.

Perhaps there are hooks in Idea for you to provide such support for your own tag library.

erickson