0

I want to submit form with values and read them by action method in a portlet but the returned values are always null. Here is my code, but I don't see anything wrong here.

<portlet:actionURL name="calculate" var="calculateAction" />
    <form name="<portlet:namespace/>calculatorForm" action="${calculateAction}" method="post" enctype="application/x-www-form-urlencoded">
         <table>
              <tr>
                 <td><label for="<portlet:namespace/>date">Date</label></td>
                 <td><input type="text" name="<portlet:namespace/>date" id="<portlet:namespace/>date" /></td>
              </tr>
              <tr>
                  <td><label for="<portlet:namespace/>amount">Amount</label></td>
                  <td><input type="text" name="<portlet:namespace/>amount" id="<portlet:namespace/>amount" /></td>
              </tr>
              <tr>
                  <td colspan="2"><input type="submit" value="Calculate" /></td>
              </tr>
        </table>
    </form>

and my method looks like this

@ProcessAction(name = "calculate")
public void calculate(ActionRequest request, ActionResponse response) {
    String stringDate = request.getParameter("date");
    String stringAmount = request.getParameter("amount");
    System.out.println("Amount: " + stringAmount);
    System.out.println("Date: " + stringDate);
}

Method is correctly called but both variables are always null.

4

1 回答 1

1

由于您已经为每个表单输入添加了 portlet 名称空间,因此您还需要getParameter使用名称空间进行调用。尝试使用

request.getParameter(response.getNamespace()+"data");
request.getParameter(response.getNamespace()+"amount");
于 2013-05-13T14:04:24.240 回答