10.3.4 Creating URLs
JSR 168 Portlets define two types of PortletURLs. An ActionURL used to generate an action request and a RenderURL used to generate a render request. An action request will cause the processAction method to be invoked. As discussed in actionPerformed, you should update the name of the submit buttons for your forms. The action value for forms should be an ActionURL. You can either use the JSP or the RenderResponse object to create the URL. RenderURLs will invoke a render request and cause the render method of the portlet to be called. The render method invoke the doDispatch which in turn calls one of the doXXX methods. Through the PortletURLs, you can also change the portlet mode, window state, and add parameters. Example 10-15 demonstrates creating an ActionURL in a form.
Example 10-15 ActionURL in a form
Creating an ActionURL using the JSP tag: <FORM method="POST" action="<portlet:actionURL />" > <LABEL class="wpsLabelText" for="<portlet:namespace /><%=MyPortletPortlet.TEXT%>">Enter order id:</LABEL><BR> <INPUT class="wpsEditField" name="<portlet:namespace /><%=MyPortletPortlet.TEXT%>" type="text"/> <INPUT class="wpsButtonText" name="<portlet:namespace /><%=MyPortletPortlet.FORM_SUBMIT%>" value="Submit" type="submit"/> </FORM>
Creating an ActionURL using the RenderResponse object: <FORM method="POST" action="<%= renderResponse.createActionURL() %>" > <LABEL class="wpsLabelText" for="<portlet:namespace /><%=MyPortletPortlet.TEXT%>">Enter order id:</LABEL><BR> <INPUT class="wpsEditField" name="<portlet:namespace /><%=MyPortletPortlet.TEXT%>" type="text"/> <INPUT class="wpsButtonText" name="<portlet:namespace /><%=MyPortletPortlet.FORM_SUBMIT%>" value="Submit" type="submit"/> </FORM>
In Example 10-16 we will create a RenderURL, setting the portlet mode to Edit and the window state to maximized. We will also set some render parameters.
Example 10-16 RenderURL
Creating a RenderURL using the JSP tags: <a href="<portlet:renderURL portletMode="EDIT" windowState="MAXIMIZED"> <portlet:param name="myParam" value="myValue"/> </portlet:renderURL>">My RenderURL</a>
Creating a RenderURL using the RenderResponse object: <% PortletURL myRenderURL = renderResponse.createRenderURL(); myRenderURL.setPortletMode(PortletMode.EDIT); myRenderURL.setWindowState(WindowState.MAXIMIZED); myRenderURL.setParameter("myParam", "myValue"); %> <a href="<%=myRenderURL %>">My RenderURL</a>
ibm.com/redbooks