Announcement Announcement Module
Collapse
No announcement yet.
Controller-backed index page Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Controller-backed index page

    I would like to have my main index page backed by a controller so I can fill the "welcome" page with data from my Entities. I created a controller as such:
    Code:
    web mvc controller --class ~.web.SiteController
    Then I modified the RequestMapping of that controller to:
    Code:
    @RequestMapping("/**")
    The full class now looks like this:
    Code:
    package com.gradient.art.web;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.ModelMap;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    
    @RequestMapping("/**")
    @Controller
    public class SiteController {
    
        @RequestMapping
        public void get(ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) {
        }
    
        @RequestMapping(method = RequestMethod.POST, value = "{id}")
        public void post(@PathVariable Long id, ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) {
        }
    
        @RequestMapping
        public String index() {
            return "site/index";
        }
    }
    However, when I hit my main URL, I get an error saying the resource was not found:
    Requested Resource Not Found

    Sorry, we did not find the resource you were looking for.

    Details

    Exception Message
    No matching handler method found for servlet request: path '/', method 'GET', parameters map[[empty]]
    Exception Stack Trace
    org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter$ServletHandlerMethodRe solver.resolveHandlerMethod(AnnotationMethodHandle rAdapter.java:626)
    org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.invokeHandlerMethod(An notationMethodHandlerAdapter.java:421)
    org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.handle(AnnotationMetho dHandlerAdapter.java:414)
    org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:790)
    org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:719)
    org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:549)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:722)
    org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:304)
    org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:210)
    org.springframework.orm.jpa.support.OpenEntityMana gerInViewFilter.doFilterInternal(OpenEntityManager InViewFilter.java:113)
    org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
    org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:243)
    org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:210)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 368)
    org.springframework.security.web.access.intercept. FilterSecurityInterceptor.invoke(FilterSecurityInt erceptor.java:109)
    org.springframework.security.web.access.intercept. FilterSecurityInterceptor.doFilter(FilterSecurityI nterceptor.java:83)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 380)
    org.springframework.security.web.access.ExceptionT ranslationFilter.doFilter(ExceptionTranslationFilt er.java:97)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 380)
    org.springframework.security.web.session.SessionMa nagementFilter.doFilter(SessionManagementFilter.ja va:100)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 380)
    org.springframework.security.web.authentication.An onymousAuthenticationFilter.doFilter(AnonymousAuth enticationFilter.java:78)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 380)
    org.springframework.security.web.servletapi.Securi tyContextHolderAwareRequestFilter.doFilter(Securit yContextHolderAwareRequestFilter.java:54)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 380)
    org.springframework.security.web.savedrequest.Requ estCacheAwareFilter.doFilter(RequestCacheAwareFilt er.java:35)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 380)
    org.springframework.security.web.authentication.http://www.BasicAuthenticationFilter...lter.java:177)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 380)
    org.springframework.security.web.authentication.Ab stractAuthenticationProcessingFilter.doFilter(Abst ractAuthenticationProcessingFilter.java:187)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 380)
    org.springframework.security.web.authentication.lo gout.LogoutFilter.doFilter(LogoutFilter.java:105)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 380)
    org.springframework.security.web.context.SecurityC ontextPersistenceFilter.doFilter(SecurityContextPe rsistenceFilter.java:79)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 380)
    org.springframework.security.web.FilterChainProxy. doFilter(FilterChainProxy.java:169)
    org.springframework.web.filter.DelegatingFilterPro xy.invokeDelegate(DelegatingFilterProxy.java:237)
    org.springframework.web.filter.DelegatingFilterPro xy.doFilter(DelegatingFilterProxy.java:167)
    org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:243)
    org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:210)
    org.springframework.web.filter.HiddenHttpMethodFil ter.doFilterInternal(HiddenHttpMethodFilter.java:7 7)
    org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
    org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:243)
    org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:210)
    org.springframework.web.filter.CharacterEncodingFi lter.doFilterInternal(CharacterEncodingFilter.java :88)
    org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
    org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:243)
    org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:210)
    org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:224)
    org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:175)
    org.apache.catalina.authenticator.AuthenticatorBas e.invoke(AuthenticatorBase.java:462)
    org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:164)
    org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:100)
    org.apache.catalina.valves.AccessLogValve.invoke(A ccessLogValve.java:851)
    org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:118)
    com.springsource.insight.collection.tcserver.reque st.HttpRequestOperationCollectionValve.traceNextVa lve(HttpRequestOperationCollectionValve.java:112)
    com.springsource.insight.collection.tcserver.reque st.HttpRequestOperationCollectionValve.invoke(Http RequestOperationCollectionValve.java:94)
    org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:405)
    org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:278)
    org.apache.coyote.AbstractProtocol$AbstractConnect ionHandler.process(AbstractProtocol.java:515)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProce ssor.run(JIoEndpoint.java:300)
    java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExecutor.java:886)
    java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:908)
    java.lang.Thread.run(Thread.java:680)
    Can someone with more knowledge point me in the right place?

  • #2
    You simply cannot. It is a limitation from the servlet spec, the welcome file has to be an actual file existing on the file system. You can work around it by creating an index.jsp (or whatever you want) which simply redirects to your site controller.

    Comment


    • #3
      Well, that sucks . Guess I will have to use JSPs or something then.

      Comment


      • #4
        mbabauer, You're on the right path. I created a controller and commented out the static view root path:
        Code:
        <!-- <mvc:view-controller path="/" view-name="index"/> -->
        in the webmvc-config.xml file.
        I added
        Code:
        @RooWebScaffold(path = "", formBackingObject = [ClassName].class)
        to my controller as I had a form on my index page, index.jspx.
        When you use the @RooWebScaffold annotation Roo will create controller methods in an .aj file which you can use after you push-in the generated methods in order to modify them and expose and work with your entity, if needed.

        Steps:

        1. Remove the static view root path from webmvc-config.xml.
        2. Add @RooWebScaffold(path = "" ..... to your Controller.
        3. Check the return strings in the "...Controller_Roo_Controller.aj file. If they are faulty push them in and correct them in java source.
        4. Edit the managed views.xml file and remove the extra slashes, if any, from the generated paths of the put-attribute element.

        There could still be some problems you'd need to address, but generally that would work I think.
        It may also help to make the whole concept the regular way in another path first and consult that as a reference.

        I made a Roo bug report on this matter last march: "Controller scaffold command which works for the rootpath". Please vote for it if you feel this would be a welcome feature.
        Last edited by MiB; Dec 27th, 2011, 01:15 AM. Reason: Corrected

        Comment


        • #5
          Ah, so it IS possible. Thanks so much for the info on how to do it.

          Also, I voted for your JIRA story.

          Comment


          • #6
            I added some steps above.

            Comment

            Working...
            X