0

Given the following controller:

@Controller
public class LandingPageController {
    @RequestMapping(value = "/landingPage", method = RequestMethod.GET)
    public String landingPage(Map<String, Object> model) {
        model.put("page", new LandingPage());
        return "landingPage";
    }
}

This would be my jsp:

<c:forEach items="${page.links}" var="link">
    <a href="${link.reference}">${link.label}</a>
</c:forEach>

IntelliJ shows the following warning:

Cannot resolve variable 'page'

Using the quickfix, IntelliJ adds:

<jsp:useBean id="page" scope="request" type="com.myApp.LandingPage"/>

This in return leads to a duplicate variable exception on loading the site.

Now my question:

How can I define the variable in JSP (including its type) without creating a duplicate?**

1 Answers1

1
<%--@elvariable id="page" type="com.myApp.LandingPage"--%>
<c:forEach items="${page.links}" var="link">
    <a href="${link.reference}">${link.label}</a>
</c:forEach>

Using the @elvariable, type information is now available and IntelliJ gives code completion as well as warnings if method (getLinks in this example) does not exist

See this question