从jsp

时间:2019-06-11 14:04:29

标签: spring-mvc liferay jsp-tags spring-form spring-portlet-mvc

我有一个带输入框的jsp表单,一个带有get / set方法的域对象和一个控制器。当我提交表单时,我在控制器中得到空值。当我提交表单时,从未在域对象中调用“ set”方法,而是在调用对象本身。

Order.jsp

<portlet:defineObjects />

<portlet:actionURL portletMode="view" var="createNewOrderURL">
<portlet:param name="action" value="createNewOrder" />
</portlet:actionURL>

<div>
<form:form name="form" method="post" commandName="refOrder" action="${createNewOrderURL}" id="createOrder">
    TestName : ${refOrder.name}<br/> <!-- here I get the correct value to display -->

    <form:input  path="referenceNum" />

    <input type="submit" value="Submit" />

</form:form>
</div>

Order.java

public class Order {
private String name = "Name1";
private String referenceNum;

public Order(){
    System.out.println("Inside Order.java");
    System.out.println(getReferenceNum());
}



 public Order(String name, String referenceNum) {
    this.name = name;
    this.referenceNum = referenceNum;
}


public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getReferenceNum() {
    return referenceNum;
}

public void setReferenceNum(String referenceNum) {
    this.referenceNum = referenceNum;
}

SalesOrderController.java

@RenderMapping 
public String defaultRender(RenderRequest request, RenderResponse response, Model model) throws SQLException, NamingException{

    model.addAttribute("refOrder",new Order());
    return "SalesOrderEntry";
}


@ActionMapping(params={"action=createNewOrder"})
public void addNewOrder(ActionRequest request, ActionResponse response, @ModelAttribute("refOrder") Order order)throws NamingException, SQLException{
    System.out.println("Inside addNewOrder method");
    System.out.println("New Order is --> "+order.toString());
    System.out.println("RefNum - "+order.getReferenceNum());
    System.out.println("request.getParameter is "+request.getParameter("referenceNum"));
}

对于控制器中的所有打印语句,我都为空。已经尝试解决此问题两天了,但我找不到问题所在。如果有人能帮助我使它正常工作,我将不胜感激。

1 个答案:

答案 0 :(得分:2)

src / main / webapp / WEB-INF / liferay-portlet.xml描述符中是否包含以下内容?

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

此外,您可能想看看PortletMVC4Spring项目,它是Spring Portlet MVC的后继项目。 GitHub项目包含可在Apache Pluto和Liferay Portal中使用的原型。 requires-namespaced-parameters的配置选项是conveniently set in the archetypes