I have a portlet with several jsp pages, each of which contains a form with a submit button. When the user submits the form on the first jsp, I save the data in db and call actionResponse.sendRedirect()to redirect the user to the next jsp page. I should use redirects to prevent the user from accidentally re-sending data on the next page by pressing F5. Everything works fine, except that after redirecting to the second page, the method doView()does not execute, and I need to load some data there before displaying the page. Is this normal behavior, or am I doing something wrong? Where can I load this data before displaying the second jsp?
First jsp
<%-- ... --%>
<portlet:actionURL name="createNewMyCustomObj" var="createNewMyCustomObjURL" />
<aui:form action="<%= createNewMyCustomObjURL.toString() %> method="post">
<%-- form fields --%>
<aui:button type="submit" value="Create" />
</aui:form>
Second jsp
<%
MyCustomObj obj = (MyCustomObj) renderRequest.getAttribute("myCustomObj");
%>
<portlet:actionURL name="updateMyCustomObj" var="updateMyCustomObjURL" />
<aui:form action="<%= updateMyCustomObjURL.toString() %> method="post">
<%-- fields with values from myCustomObj --%>
<aui:button type="submit" value="Update" />
</aui:form>
MyMVCPortlet.java
public class MyMVCPortlet extends MVCPortlet {
public createNewMyCustomObj(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortlalException, SystemException {
PortletURL redirectURL = null;
try {
redirectURL = createRedirectURL(actionRequest, "second.jsp");
} catch(Exception e) {
SessionErrors.add(actionRequest, "error-key")
redirectURL = createRedirectURL(actionRequest, "first.jsp");
}
actionResponse.sendRedirect(redirectURL.toString());
}
private PortletURL createRedirectURL(ActionRequest actionRequest, String jspPage) {
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
String portletName = (String) actionRequest.getAttribute(WebKeys.PORTLET_ID);
PortletURL redirectURL = PortletURLFactoryUtil.create(
actionRequest, portletName, themeDisplay.getLayout().getPlid(), PortletRequest.RENDER_PHASE);
redirectURL.setParameter("jspPage", jspPage);
return redirectURL;
}
@Override
public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
throws IOException, PortletException {
if() {
renderRequest.setAttribute("myCustomObj", myCustomObj);
}
super.doView(renderRequest, renderResponse);
}
}