How does Spring MVC-support work?

Hi, I'm using IntelliJ 8.0.1, and was reading on the Spring-feature-list that "Code completion also recognizes MVC model attributes". I was wondering how this work, as I can't get code completion myself. This is my spring config:


<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


    <context:component-scan base-package="no.frameworked"/>


    <bean id="handlerMapping"
          >
        <property name="interceptors">
            <list>
                <ref bean="authenticationInterceptor"/>
            </list>
        </property>
    </bean>


    <bean />
    <bean id="viewResolver"
          p:viewClass="org.springframework.web.servlet.view.JstlView" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>
</beans>


And this is my controller:

@Controller
public class ServersController {


    @RequestMapping("/servers.html")
    public ModelAndView handleRequest()  {


        ModelMap model = new ModelMap();
        model.addAttribute("springstring", "springstring");
        return new ModelAndView("servers", model);

    }
}


And even though I'm able to get code-complete on the URLs in my servers.jsp, I can't get code-complete on the 'springstring' from the model. (It does resolve when runned.) What do I have to do to get this working?

7 comments
Comment actions Permalink

Such attributes are not supported yet. Feel free to file a JIRA for that.


0
Comment actions Permalink

For now, only attributes marked by @ModelAttribute are recognized.


0
Comment actions Permalink

But isn't this what is shown on this page:
http://www.jetbrains.com/idea/features/spring_framework.html
on the second screenshot under the section Spring MVC?

It even says "Code completion also recognizes MVC model attributes". So, how do I use this functionality?

0
Comment actions Permalink

<deleted>

Message edited by Thibaut : My bad, forget my contribution

0
Comment actions Permalink

For now, only attributes marked by @ModelAttribute are recognized.


0
Comment actions Permalink

Sorry for what I'm sure is a raw newbie question here, but how do I "mark" attributes with @ModelAttribute?  I have code like this in my controller:

Map<String, Object> model = new HashMap<String, Object>();
model.put("firstname", "ralph");
return new ModelAndView(getViewName(), model);


so I can refer to 'firstname' in my view like this:

Hello, ${firstname}!


Where do I put the @ModelAttribute bit so that 'firstname' isn't highlighted as unrecognized in my view, and so I can do code completion stuff with it?

This question probably reflects my inexperience, so something as simple as a "go read this" link would be very much appreciated. I've tried to do some reading about annotations and I don't have the Java chops yet to understand what's going on there. Thanks!

0
Comment actions Permalink

Well, it could look like

@RequestMapping("/servers.html")
@ModelAttribute("springstring")
public String handleRequest() {
return "springstring";
}


0

Please sign in to leave a comment.