Results 1 to 5 of 5

Thread: Getting: You may need to switch newer MVC infraestructure

  1. #1
    Join Date
    Oct 2006
    Posts
    3

    Default Getting: You may need to switch newer MVC infraestructure

    I'm getting the following error when I try to get to the action mapping method on a controller after clicking a button that sends me there. Here's the exception >
    Code:
    java.lang.IllegalStateException: Argument [RedirectAttributes] is of type Model or Map but is not assignable from the actual model. You may need to switch newer MVC infrastructure classes to use this argument.
    What am I missing?

    web.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
        <display-name>prueba-portlet</display-name>
        
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                classpath*:/context/spring.xml
            </param-value>
        </context-param>
        
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    
        <servlet>
            <servlet-name>ViewRendererServlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        
        <servlet-mapping>
            <servlet-name>ViewRendererServlet</servlet-name>
            <url-pattern>/WEB-INF/servlet/view</url-pattern>
        </servlet-mapping>
        
        <session-config>
            <session-timeout>30</session-timeout>
        </session-config>
    </web-app>
    spring.xml
    Code:
    <?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:tx="http://www.springframework.org/schema/tx"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:mvc="http://www.springframework.org/schema/mvc"
           xsi:schemaLocation="
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
                http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
           ">
        
        <context:property-placeholder location="file:${user.home}/portal-ext.properties"/>
        
        <context:component-scan base-package="mx.edu.um.academia" />
    
        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
            <property name="cache" value="false" /> 
            <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> 
            <property name="prefix" value="/WEB-INF/jsp/" /> 
            <property name="suffix" value=".jsp" />
        </bean>
    
    </beans>
    portlet.xml
    Code:
    <?xml version="1.0"?>
    
    <portlet-app
        version="2.0"
        xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
    >
        <portlet>
            <description>Hola1</description>
            <portlet-name>Hola1</portlet-name>
            <display-name>Hola1</display-name>
            <portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
            <expiration-cache>0</expiration-cache>
            <supports>
                <mime-type>text/html</mime-type>
                <portlet-mode>VIEW</portlet-mode>
            </supports>
            <supported-locale>en</supported-locale>
            <supported-locale>es</supported-locale>
            <resource-bundle>hola1</resource-bundle>
            <portlet-info>
                <title>Hola1</title>
                <short-title>Hola1</short-title>
                <keywords></keywords>
            </portlet-info>
            <security-role-ref>
                <role-name>administrator</role-name>
            </security-role-ref>
            <security-role-ref>
                <role-name>guest</role-name>
            </security-role-ref>
            <security-role-ref>
                <role-name>power-user</role-name>
            </security-role-ref>
            <security-role-ref>
                <role-name>user</role-name>
            </security-role-ref>
        </portlet>
    </portlet-app>
    Hola1-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:mvc="http://www.springframework.org/schema/mvc"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
            ">
    
        <mvc:annotation-driven />
        
        <bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
            <property name="portletModeMap">
                <map> 
                    <entry key="view" value-ref="hola1Portlet" />
                </map> 
            </property>
        </bean>
        
    </beans>
    Hola1Portlet.java
    Code:
    /*
     * The MIT License
     *
     * Copyright 2012 Universidad de Montemorelos A. C.
     *
     * Permission is hereby granted, free of charge, to any person obtaining a copy
     * of this software and associated documentation files (the "Software"), to deal
     * in the Software without restriction, including without limitation the rights
     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     * copies of the Software, and to permit persons to whom the Software is
     * furnished to do so, subject to the following conditions:
     *
     * The above copyright notice and this permission notice shall be included in
     * all copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     * THE SOFTWARE.
     */
    package mx.edu.um.academia.web;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.portlet.bind.annotation.ActionMapping;
    import org.springframework.web.servlet.mvc.support.RedirectAttributes;
    
    /**
     *
     * @author J. David Mendoza <jdmendoza@um.edu.mx>
     */
    @Controller
    @RequestMapping("VIEW")
    public class Hola1Portlet {
        private static final Logger log = LoggerFactory.getLogger(Hola1Portlet.class);
        @RequestMapping
        public String hola() {
            log.debug("Hola");
            return "hola1";
        }
        
        @ActionMapping(params="action=test")
        public String test(RedirectAttributes redirectAttributes) {
            log.debug("test");
            redirectAttributes.addFlashAttribute("mensaje", "Hola desde el portlet");
            return "redirect:/";
        }
    }
    hola1.jsp
    Code:
    <%-- 
        Document   : hola1
        Created on : Jul 11, 2012, 5:44:12 PM
        Author     : J. David Mendoza <jdmendoza@um.edu.mx>
    --%>
    <%--
     * Copyright 2005-2008 the original author or authors.
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     *      http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
    --%>
    
    <%@ page contentType="text/html" isELIgnored="false" %>
    <%@ page import="com.liferay.portal.kernel.language.LanguageUtil" %>
    <%@ page import="com.liferay.portal.kernel.util.UnicodeFormatter" %>
    <%@ page import="javax.portlet.WindowState" %>
    
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
    <%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
    
    <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
    
    <%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
    <%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
    <%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
    <%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
    
    <%@ taglib prefix="html" tagdir="/WEB-INF/tags/html" %>
    
    <portlet:defineObjects />
    <liferay-theme:defineObjects />
    
    <div class="well">
        <h1>Hola Mundo</h1>
        <portlet:actionURL var="actionUrl">
            <portlet:param name="action" value="test"/>
        </portlet:actionURL>
        
        <a href="${actionUrl}" class="btn btn-primary btn-large">TEST</a>
    </div>
    Thank you very much for your help...

    David M.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Judging from your code you are mixing portlet and servlet packages. The RedirectAttributes are from the servlet package whereas you are using/creating a Portlet. I suspect that RedirectAttributes doesn't work for a Portlet environment.

    Could you post the full stacktrace/log?
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Dec 2008
    Location
    India
    Posts
    295

    Default

    Hi,

    You can't you Redirect Attribute in Portlet Environment. Read below(which i copied from here):

    RedirectAttributes (Servlet-only, @MVC 3.1-only) to specify the exact set of attributes to use in case of a redirect and also to add flash attributes (attributes stored temporarily on the server-side to make them available to the request after the redirect). RedirectAttributes is used instead of the implicit model if the method returns a "redirect:" prefixed view name or RedirectView.

    Also for Marten: I have replicated this issue at my end. Attaching log for same.

    Attached Files Attached Files
    Enjoy
    Rohan Chauhan
    ------------------------------------------------------------------------------
    SpringSource Certified Spring 3.0 Professional


  4. #4
    Join Date
    Oct 2006
    Posts
    3

    Default

    So I cannot use RedirectAttributes inside Portlets... Thanks... I got it...

    David M.

  5. #5
    Join Date
    Jul 2012
    Posts
    9

    Default

    Thanks this is really a useful one.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •