Search code examples
javahtmlliferay

Passing date from view.jsp to my Java Portlet


I have the following code on my view.jsp:

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

<portlet:defineObjects />
<portlet:actionURL name="filterByDate" var="activitiesPortlet" />

<form action="${activitiesPortlet}" method="post">
    Start: <input type="date" name="start-date"> 
    End: <input type="date" name="end-date">
    <input type="submit" value="Filter"> 
</form>

And the function on my Java Portlet:

public void filterByDate(ActionRequest request, ActionResponse response) {
    Object startDate = ParamUtil.get(request, "start-date", "");
    System.out.println(startDate.toString());
}

The function is called since the System Out prints a blank line. But I can't get the value of the input date. What is the correct way to pass the html input date to my Java Portlet?


Solution

  • Unless you don't have set requires-namespaced-parameters to false for your Portlet, non-namespaced parameters are not handled with ParamUtil.getXX

    You can use <aui:input> fields (they handling namespaces) or prefix the Portlet namespace (such as <portlet:namespace>) to your input field names. Also, you could use ParamUtil.getDate in your Portlet code to handle dates send with a certain DateFormat.