Code assist in (jsp /jstl) view for Spring MVC model objects in Eclipse
Asked Answered
M

2

5

In Spring MVC when placing an object in the view model like so:

public String getUser( Model model ) {
    //...fetch user...
    model.addAttribute( "user", user );
    return "viewName";
}

and accessing it's values in the JSP / JSTL view like this:

...
<p>
    ${user.name}
</p>
...

I'm wondering if it is possible to have code assist for the user object in the view?

The IDE I'm using is MyEclipse but it would be interesting to know if this is possible in other editors as well.

Thanks.

Mycenae answered 17/3, 2010 at 11:40 Comment(0)
F
3

Ideally you want the JSP/JSTL standard tags to be agnostic of the technology that supplies these objects but you are correct in that atleast while designing the support will be useful.

However it looks like Intellij IDEA seems to have something similar to what you want http://www.jetbrains.com/idea/features/spring_framework.html (towards the end)!

You have to add a JSP comment like this:

<%--@elvariable id="pet" type="com.mycompany.Pet"--%>

IntelliJ will then autocomplete based on that type.

alt text
(source: jetbrains.com)

Is using IntelliJ ruled out for you?

Freer answered 17/3, 2010 at 12:7 Comment(5)
That screenshot shows exactly the feature I'd like to have. IntelliJ isn't ruled out and actually another team member is using that on the same project. We tried this in IntelliJ but didn't get code assistance for the objects added to the view model by the controller. Do you have some extra setup (includes?) to get this functionality?Mycenae
You need the Ultimate edition (payware). This isn't supported by the (free) Community edition.Lanner
Yes, this is only in the full ultimate edition that costs £470 for professional and £170 for personal commercial licenseFreer
@CalmStorm I have the full paid for version, but this feature is rather temperamental - any tips ? https://mcmap.net/q/689441/-intellij-not-resolving-el-variables-within-jsp-code-inspection-or-autocomplete/106261Bianchi
you need to add <%--@elvariable id="foo" type="com.mycompany.SomeObject"--%> to the jsp to get this to work thoughBianchi
L
2

In other words: you want code assist for EL (Expression Language, the ${} things)? This is not to be confused with JSP, JSTL nor Spring MVC.

Eclipse doesn't have any builtin EL autocompletion support, the JBoss Tools plugin adds some (JSF) EL autocompletion support. MyEclipse and IntelliJ have code assist for at least implicit EL objects. Not sure about custom EL objects though.

Lanner answered 17/3, 2010 at 12:22 Comment(1)
Yes, that's correct, I'm looking for code assist for EL and am confusing technologies :)Mycenae

© 2022 - 2024 — McMap. All rights reserved.