2014-02-26 30 views
1

我試圖克隆Spring MVC的Portlet項目,但在發佈形式todo性質均爲空。在Liferay的6.2 Spring MVC中的portlet,型號屬性爲null在成形後的

回購可以用Github

這裏是控制器代碼

@Controller 
@RequestMapping("VIEW") 
public class ToDoListController { 

    @RenderMapping 
    public String view() { 
     return "list"; 
    } 

    @ActionMapping 
    public void save(@Valid ToDo toDo, BindingResult result, @CookieValue("JSESSIONID") String jsessionid, 
      PortletSession session, ModelMap modelMap) { 
     if (!result.hasErrors()) { 
      // could use entityManager to persist; put in session for this example 
      List<ToDo> toDos = (List<ToDo>) session.getAttribute("toDos"); 
      if (toDos == null) { 
       toDos = new ArrayList<ToDo>(); 
      } 
      toDos.add(toDo); 
      session.setAttribute("toDos", toDos); 

      modelMap.put("msg", String.format("You added a TODO: %s", toDo.getTitle())); 
     } 
    } 

    @ModelAttribute 
    private ToDo loadModel() { 
     return new ToDo(); 
    } 
} 

這裏是查看:

<%@ page contentType="text/html" %> 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@ taglib prefix="portlet" uri="http://java.sun.com/portlet_2_0" %> 
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 

<c:if test="${msg ne null}"> 
    <div class="portlet-msg-success"><c:out value="${msg}" /></div> 
</c:if> 

<portlet:actionURL var="save" /> 

<form:form modelAttribute="toDo" action="${save}" method="POST"> 
    <fieldset> 
     <legend>Add a TODO</legend> 
     <div> 
      <form:label path="title" cssStyle="display:block">Title:</form:label> 
      <form:input path="title" /> 
      <form:errors path="title" cssClass="portlet-msg-error" /> 
     </div> 
     <div> 
      <form:label path="due" cssStyle="display:block">Due (MM/DD/YYYY):</form:label> 
      <form:input path="due" /> 
      <form:errors path="due" cssClass="portlet-msg-error" /> 
     </div> 
     <div> 
      <form:label path="description" cssStyle="display:block">Description:</form:label> 
      <form:textarea path="description" /> 
      <form:errors path="description" cssClass="portlet-msg-error" /> 
     </div> 
     <div> 
      <input type="submit" value="Save" /> 
     </div> 
    </fieldset> 
</form:form> 

這裏是上下文:

<?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" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
         http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
         http://www.springframework.org/schema/mvc 
         http://www.springframework.org/schema/mvc/spring-mvc.xsd 
         http://www.springframework.org/schema/context 
         http://www.springframework.org/schema/context/spring-context-2.5.xsd"> 

    <mvc:annotation-driven validator="validator" /> 

    <bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="cache" value="true" /> 
     <property name="viewClass" 
      value="org.springframework.web.servlet.view.JstlView" /> 
     <property name="prefix" value="/WEB-INF/view/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 


    <bean id="validator" 
     class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" /> 

    <bean id="annotationMethodHandlerAdapter" 
     class="org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter"> 
     <property name="webBindingInitializer"> 
      <bean id="configurableWebBindingInitializer" 
       class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer"> 
       <property name="validator"> 
        <ref bean="validator" /> 
       </property> 
      </bean> 
     </property> 
    </bean> 
</beans> 

========= ================================================== ==========
更新:

這裏的工作版本:https://github.com/jzinedine/FirstPortlet

+0

我有一些類似的問題。你使用哪種LR版本,是6.1GA2?在* deploy * webapps中檢查你的'web.xml'(新的LR版本弄亂'ContextLoaderListeners')。檢查此線程:http://stackoverflow.com/questions/13739905/liferay-spring-spring-web-mvc-autowired-dont-work – rlegendi

+0

謝謝,我使用Liferay 6.2.0GA1。 –

回答

3

你需要使用Spring MVC與Liferay的6.2時設置<requires-namespaced-parameters>false</requires-namespaced-parameters>在你的Liferay-portlet.xml中。在這個page的末尾有關於Liferay 6.2文檔的解釋。

+0

我從頭創建了一個基於maven的新portlet,並添加了提到的標籤,問題得到解決,感謝您的幫助,我將推送工作版本到Github並更新問題。 –

+0

以下是工作版本:https://github.com/jzinedine/FirstPortlet –

相關問題