2016-09-22 84 views
0

我遇到問題。表單提交是空的。liferay portlet spring mvc表單爲空

public class Customer implements Serializable{ 

    private static final long serialVersionUID = 1L; 
    private String firstName; 
    private String middleName; 
    private String lastName; 
    private int age; 
    private String address; 

    public String getFirstName() { 
     return firstName; 
    } 

    public void setFirstName(String firstName) { 
     this.firstName = firstName; 
    } 

    public String getMiddleName() { 
     return middleName; 
    } 

    public void setMiddleName(String middleName) { 
     this.middleName = middleName; 
    } 

    public String getLastName() { 
     return lastName; 
    } 

    public void setLastName(String lastName) { 
     this.lastName = lastName; 
    } 

    public int getAge() { 
     return age; 
    } 

    public void setAge(int age) { 
     this.age = age; 
    } 

    public String getAddress() { 
     return address; 
    } 

    public void setAddress(String address) { 
     this.address = address; 
    } 
} 

PortletViewController

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


    @RenderMapping 
    public String viewHomePage(RenderRequest request, RenderResponse response) { 

     return "test/view"; 
    } 

    @RenderMapping(params = "action=showForm") 
    public String viewByParameter(Map<String, Object> map) { 

     Customer customer = new Customer(); 
     map.put("customer", customer); 
     return "test/form"; 
    } 

    @RenderMapping(params = "action=success") 
    public String viewSuccess() { 
     return "test/success"; 
    } 

    @ActionMapping(value = "handleCustomer") 
    public void getCustomerData(@ModelAttribute("customer") Customer customer, 
      ActionRequest actionRequest, ActionResponse actionResponse, 
      Model model) { 

     actionResponse.setRenderParameter("action", "success"); 

     model.addAttribute("successModel", customer); 
    } 
} 

form.jsp

<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%> 
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> 
<portlet:defineObjects /> 
<portlet:actionURL var="submitFormURL" name="handleCustomer"/> 
<form:form name="customer" method="post" modelAttribute="customer" action=" <%=submitFormURL.toString() %>"> 
<br/> 
<table style="margin-left:80px"> 
    <tbody> 
     <tr> 
      <td><form:label path="firstName">First Name</form:label></td> 
      <td><form:input path="firstName"></form:input></td> 
     </tr> 
     <tr> 
      <td><form:label path="middleName">Middle Name</form:label></td> 
      <td><form:input path="middleName"></form:input></td> 
     </tr> 
     <tr> 
      <td><form:label path="lastName">Last Name</form:label></td> 
      <td><form:input path="lastName"></form:input></td> 
     </tr> 
     <tr> 
      <td><form:label path="age">Age</form:label></td> 
      <td><form:input path="age"></form:input></td> 
     </tr> 
     <tr> 
      <td><form:label path="address">Address</form:label></td> 
      <td><form:input path="address"></form:input></td> 
     </tr> 

     <tr> 
      <td colspan="2"><input type="submit" value="Submit Form"> 
      </td> 
     </tr> 
    </tbody> 
</table> 
</form:form> 

的success.jsp

<div> 
<h3>Form submitted successfully</h3> 
</div> 

<div> 
First Name: 
${successModel.firstName} 
</div> 

<div> 
Middle Name: 
${successModel.middleName} 
</div> 

<div> 
Last Name: 
${successModel.lastName} 
</div> 

<div> 
Age: 
${successModel.age} 
</div> 

<div> 
Address: 
${successModel.address} 
</div> 

view.jsp的

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> 

<portlet:defineObjects /> 

<portlet:renderURL var="renderURL"> 
    <portlet:param name="action" value="showForm"/> 
</portlet:renderURL> 

<h3> Spring Form Submission Demo</h3> 

<br/><br/> 

<a href="<%=renderURL.toString()%>">Go to Form Page</a> 

的web.xml

<?xml version="1.0"?> 

<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" 
> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring-context/portlet-application-context.xml</param-value> 
    </context-param> 
    <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> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 
</web-app> 

的portlet.xml

<?xml version="1.0"?> 

<portlet-app 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" version="2.0"> 
    <portlet> 
     <portlet-name>test</portlet-name> 
     <display-name>test</display-name> 
     <portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class> 
     <init-param> 
      <name>contextConfigLocation</name> 
      <value>/WEB-INF/spring-context/portlet/test-portlet.xml</value> 
     </init-param> 
     <expiration-cache>0</expiration-cache> 
     <supports> 
      <mime-type>text/html</mime-type> 
     </supports> 
     <portlet-info> 
      <title>test</title> 
      <short-title>test</short-title> 
      <keywords>test</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> 

portlet的應用程序的context.xml

<?xml version="1.0"?> 

<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/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd" 
> 
    <context:annotation-config/> 


    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="contentType" value="text/html;charset=UTF-8"/> 
     <property name="prefix" value="/WEB-INF/jsp/"/> 
     <property name="suffix" value=".jsp"/> 
     <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> 
    </bean> 
</beans> 

測試的portlet.xml

<?xml version="1.0"?> 

<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/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" 
> 
    <context:component-scan base-package="test.**" /> 
</beans> 

有人可以幫助我嗎?

爲什麼客戶提交空白?

回答

0

我發現了錯誤。在liferay-portlet.xml中必須添加以下內容。

<requires-namespaced-parameters>false</requires-namespaced-parameters>