JSP EL and autoCompletion
Asked Answered
B

1

15

In my servlet:

request.setAttribute("list", myList);

In my Jsp:

<c:forEach var="item" items="${list}">
   ${item.name} and ${item.address}
</c:forEach>

How do I get autocompletion for item.name and item.address in IDE (IntelliJ)?

Can I use <jsp:useBean> for any other feature to make the type of 'item' explicit?

Beersheba answered 3/8, 2013 at 23:9 Comment(1)
item could be anything. Did you try with usebean? Did you check what, if any, options are available for item quick fixes?Corrales
F
28

For IntelliJ, you can use comment annotations, such as this:

<%--@elvariable id="list" type="java.util.List<your.item.class.Here>"--%>

To get this automatically, IntelliJ should be coloring ${items} as a warning, since it wont have any idea what it is. Click on it and when the lightbulb pops up, click the option "Declare external variable in comment annotation." That will generate a comment annotation such as the one listed above.

Fauman answered 4/8, 2013 at 3:38 Comment(2)
This is awesome! In fact Alt + Enter (quick-fix) gives two options - declare external variable as (a) useBean, (b) comment annotation.Beersheba
Yeah, I use comment annotations personally.Fauman

© 2022 - 2024 — McMap. All rights reserved.