Pergunta

I have a webapp which is built using spring 3 and tiles 2 (not RESTful). I am using UrlBasedViewResolver to display views

my application-servlet.xml

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

    <mvc:annotation-driven />
    <mvc:resources mapping="/resources/**" location="/resources/" />

    <context:component-scan base-package="com.xxx.xxxx.xxxxx.web.controller" />

    <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles.xml</value>
            </list>
        </property>
    </bean>


    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />

    <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />
    </bean>

</beans>

my tiles.xml

<tiles-definitions>
    <definition name="base.definition" template="/WEB-INF/views/layout.jsp">
        <put-attribute name="header" value="/WEB-INF/views/header.jsp" />
        <put-attribute name="body" value="" />
        <put-attribute name="footer" value="/WEB-INF/views/footer.jsp" />
    </definition>

    <definition name="welcome" extends="base.definition">
        <put-attribute name="body" value="/WEB-INF/views/welcome.jsp" />
    </definition>
</tiles-definition>

Now my problem is - I have a dynamic form on client side that is generated on fly (using javascript) based on users options like, if a option is chosen from 1st drop down box, then I load rest of the form and so on. For my first drop down menu I have no issues, because those options are constants. but for my second drop down menu choice I need to load info that is specific and is only available on server, so I thought of making a AJAX call (RESTful call), so I created a Controller like this

my RESTful controller:

@Controller
public class UtilsController {

    private WebAdministration admin;

    public UtilsController() throws WebAdministrationException {
        this.admin = WebAdministration.getInstance();
    }

    @RequestMapping(value="/aaaa/${site}/${type}", method=RequestMethod.GET, headers="Accept=text/xml, application/json")
    public @ResponseBody List<String> getRemoteSites(@PathVariable("site") String site, @PathVariable("type") String type) {
        List<String> remoteSites = null;
        Config config = (Config) admin.getImplemantationData().get(Implementations.IMPL);
        if (type.equals(Config.PERSISTENCE)) {
            remoteSites = config.getRemoteSites().get(site).getNewRemoteSites();
        }
        else if (type.equals(Config.OLD)) {
            remoteSites = config.getRemoteSites().get(site).getOldRemoteSites();
        }
        return remoteSites;
    }
}

my ajax call:

<script type="text/javascript">
function getRemoteSites(site, type) {
    $.getJSON('/aaaa/'+site+'/'+type, {
        ajax : 'true'
    }, function(data) {
        var len = data.length;
        for ( var i = 0; i < len; i++) {
            document.write('<form:checkbox path="remoteSites" value="' + valueArray[i] + '" />');
        }
    });
};
</script>

and my Ajax request fails with 404 - no mapping found.

How can I make my REST url work. I know that I need a new view resolver, but I tried so many things and searching for right solution for past 2 days.

any help ?

Thank you

Nenhuma solução correta

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top