我正在做这个教程: http://proliferay.com/form-submit-in-spring-mvc-portlet/
一切正常,除了最后一部分。 在我的电脑上,客户表单正确显示。但是,如果我将客户的详细信息设置到表单中,当我验证表单时,客户不会被保存。 因此,下一个 jsp (success.jsp) 找不到已保存的 Customer 客户,因此显示一个带有空数据的新客户。
我的版本和教程之间的唯一区别是我必须从 Maven 构建项目,但这不应该改变任何东西?
监控确认 form.jsp 中的数据正确,因为我可以通过以下方式获得正确答案: System.out.println("\n客户: "+ request.getAttribute("客户") + "\n");
这里是class.jsp:
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%System.out.println("\ncustomer : " + request.getAttribute("customer") + "\n"); %>
<portlet:actionURL var="submitFormURL" name="handleCustomer"/>
<form:form name="customer" method="post" modelAttribute="customer" action="<%=submitFormURL.toString() %>"> <%-- onSubmit="displayParams"> --%>
<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>
以及相应的 Controller 方法:
@ActionMapping(value = "handleCustomer")
public void getCustomerData(
@ModelAttribute("customer") Customer customer,
ActionRequest actionRequest, ActionResponse actionResponse,
Model model) {
log.info("#############Calling getCustomerData : post form validation##########");
System.out.println("\nModel : " + model);
//displays : "Model : {customer=null null,............."
System.out.println(customer.getFirstName());
System.out.println(customer.getLastName());
System.out.println(customer.getAddress());
actionResponse.setRenderParameter("action", "success");
model.addAttribute("successModel", customer);
}
知道什么会阻止它工作吗? 提前谢谢
最佳答案
您可能正在使用 Liferay 6.2+,如果是这样,那么您应该设置(Spring 没有命名空间参数 - 请参阅 SPR-11176 )
<requires-namespaced-parameters>false</requires-namespaced-parameters>
到liferay-portlet.xml
Element : requires-namespaced-parameters
Set the requires-namespaced-parameters value to true if the
portlet will only process namespaced parameters. The default
value is true.
描述取自http://www.liferay.com/dtd/liferay-portlet-app_6_2_0.dtd
关于java - Spring MVC Portlet : form not saving data correctly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32784701/