Announcement Announcement Module
Collapse
No announcement yet.
spring portlet mvc multiple annotated controllers rendermapping problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring portlet mvc multiple annotated controllers rendermapping problem

    Hello SpringForum,

    Thanks for the response about log4j in weblogic, and we are looking at that.

    Here is another issue I have run into, also using JSR286 JDeveloper 11.1.1.4/weblogic. I am changing an application from 4 portlets to only 1 portlet. I am keeping the original controllers. I am using RenderParameters to navigate to annotated @RenderMapping methods to process each view. I am using actionUrs to navigate to annotated @ActionMapping methods.

    I find that the first view must be default so the initial render method has no label - @RenderMapping.
    All other methods have specific labels.

    The problem I have is I am unable to map to Controller 2 from Controller 1 action method like so:

    User first runs app --> default @RenderMapping method in Controller 1 is invoked and jsp is displayed.
    User picks an action - matching @ActionMapping in Controller 1 executes.

    *problem * Controller 1 action sets a render parameter like so "response.setRenderParameter("wtf_view", "searchView");"

    The @RenderMapping target exists in Controller 2 - @RenderMapping(params="wtf_view=searchView") - but the default method in Controller 1 is what executes and remains on the original jsp.

    I have looked at my debug statements (none from Spring though) and determined that the RenderParameters were properly set. Thinking that the order of controllers found in the component scan was the issue I defined the beahs in the app-portlet.xml. However it did not fix it either.

    Here is the app-portlet.xml:

    <code>
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <context:annotation-config/>
    <context:component-scan base-package="gov.opm.epic"
    use-default-filters="true">
    <context:include-filter type="annotation"
    expression="org.springframework.stereotype.Control ler"/>
    </context:component-scan>
    <bean id="b1"
    class="gov.opm.epic.roi.controller.CaseReportContr oller"/>
    <bean id="b2"
    class="gov.opm.epic.roi.controller.QueryResultCont roller"/>
    <bean id="b3"
    class="gov.opm.epic.roi.controller.SearchControlle r"/>
    <bean id="b4" class="gov.opm.epic.roi.controller.RoiMain"/>
    <bean id="b5"
    class="gov.opm.epic.roi.controller.AdvancedSearchC ontroller"/>
    <bean class="org.springframework.web.portlet.mvc.annotat ion.DefaultAnnotationHandlerMapping">
    <property name="order" value="10"/>
    </bean>
    </beans>

    </code>

    Your time is appreciated!

    Thanks,
    Steve

  • #2
    Your configuration is flawed. I suppose your controllers are annotated with the @Controller annotations; you already do a component scan to register those as Spring beans so don't also declare them in xml or you will get 2 versions of the same bean in your context and this will lead to problems like those you are experiencing.
    Also, annotation-config is included in component-scan so you don't need that, nor you need to specify use-default-filters (true is the standard option - use convention over configuration when possible!) or that you want to include the @Controller annotation (this is included by default - again, coc!).
    Other thing, use mvc:annotation-driven which will not just register the DefaultAnnotationHandlerMapping but also a lot of other much needed and cool stuff for Spring mvc (read the reference guide).
    In short, you should reduce your config file to:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schem...-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
    
        <context:component-scan base-package="gov.opm.epic" />
    
        <mvc:annotation-driven />
    
    </beans>

    Comment


    • #3
      We have the same problem Spring version 3.1.1 in liferay 6.1

      We have even more then two controllers, if we put all the RenderMapping Methods together in the Controller which have also the default render mapping @RenderMapping() then the mapping works pretty well.
      But if we moved the RenderMapping to the suitable Controllers the first RenderMapping which resists in a foreign Controller, leads to a call on the default RenderMapping and not what was expected in the suitable RenderMapping in the second or third Controller.

      We cleaned up the Project as well and also the spring-context.xml file but nothing worked for us ...

      Maybe some one knows what to do except moving all RenderMethods to one Controller. :-)

      Comment


      • #4
        I had this problem

        Originally posted by straubej View Post
        We have even more then two controllers, if we put all the RenderMapping Methods together in the Controller which have also the default render mapping @RenderMapping() then the mapping works pretty well.
        But if we moved the RenderMapping to the suitable Controllers the first RenderMapping which resists in a foreign Controller, leads to a call on the default RenderMapping and not what was expected in the suitable RenderMapping in the second or third Controller.

        We cleaned up the Project as well and also the spring-context.xml file but nothing worked for us ...

        Maybe some one knows what to do except moving all RenderMethods to one Controller. :-)
        You must change methods annotation @RequestMapping to @RenderMapping in all controllers.

        For excample was:

        @RequestMapping(params = "operation=viewDepartments")
        public ModelAndView viewAllDepartments(RenderRequest request) {

        Stay:

        @RenderMapping(params = "operation=viewDepartments")
        public ModelAndView viewAllDepartments(RenderRequest request) {

        Comment


        • #5
          Exactly the same problem

          Originally posted by Vo1ishe View Post
          You must change methods annotation @RequestMapping to @RenderMapping in all controllers.

          For excample was:

          @RequestMapping(params = "operation=viewDepartments")
          public ModelAndView viewAllDepartments(RenderRequest request) {

          Stay:

          @RenderMapping(params = "operation=viewDepartments")
          public ModelAndView viewAllDepartments(RenderRequest request) {
          Hi, I am facing exactly the same problem. Have multiple controllers with methods in them annotated with for example @RenderMapping(params="action=mycontrolleraction1" ) and also using <mvc:annotation-driven /> in the spring context file.

          Could you please let me know if you have got the issue resolved and how? Thanks!

          Comment


          • #6
            Same problem

            Hi,
            I am having same problem, have one portlet with mulitple controllers.
            We are moving from spring 2.5 to Spring 3 and websphere portal 6.0 to 70.

            We dont have annotation based controller. Also we have jsr 168 portlets.

            In our scenario once we set "action" parameter to delegate rendering to appropriate controller then subsequently it just calls that controller for render rather calling default one.

            Comment

            Working...
            X