Seeya K
Seeya K

Reputation: 1321

Linking two jsp pages with Submit Button Liferay

I have a form where I allow user to select some data and submit the form and based on that selection data will be displayed in another jsp.

I have used the following code in first jsp:

    <aui:form name="updateDailyAttendance" action = "<%=request.getContextPath()%> /admin/test.jsp"  method="post" >
        <input type = "date" name = "myDate"/>
        <input type = "submit" name = "Submit"/>
    </aui:form>

test.jsp is the second JSP. But the code above isn't working. How should I mention the second jsp name in the "action" above so that the above jsp takes me to second jsp. I am using lIferay

Upvotes: 1

Views: 3019

Answers (1)

yannicuLar
yannicuLar

Reputation: 3133

instead of passing a url as 'action', you should provide an actionUrl with the jsp page as param.

<portlet:actionURL var="actionName" name="yourMVCPortletFunctionName">
    <portlet:param name="jspPage" value="/admin/test.jsp" />  
</portlet:actionURL>

<aui:form name="updateDailyAttendance" action = "<%= actionName %>"  method="post" >
    <input type = "date" name = "myDate"/>
    <input type = "submit" name = "Submit"/>
</aui:form>

then in Your Controller:

public void yourMVCPortletFunctionName(ActionRequest actionRequest, ActionResponse actionResponse){
    throws PortletException, IOException 
    //Do your stuff

    //Redirect
    String redirectUrl = (String)request.getParameter("jspPage");
    actionResponse.setRenderParameter("jspPage", redirectUrl);
}

This way you can have actions that do some standard stuff, like handling that "myDate" param, and have them redirect to other pages each time. So calling them from different points (different jsp page or form), will target ta a new redirect each time

Upvotes: 1

Related Questions