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.
Since you have prepended the portlet namespace to each of your form inputs, you will need to call getParameter
with the namespace as well. Try using
request.getParameter(response.getNamespace()+"data");
request.getParameter(response.getNamespace()+"amount");