JSF Showcase

portlet:actionURL

ActionURL is a UIComponent that provides the ability to get a PortletURL that invokes the ACTION_PHASE of the portlet lifecycle targeting the current portlet.

General Usage

Specify portlet:param as a child tag in order to add portlet action parameters to the URL. The portlet:actionURL component tag is provided for the sake of completeness since it has little purpose in JSF portlets. As shown in the example below, a practical use-case might be to @Override GenericFacesPortlet in order to intercept a non-JSF postback.

Source Code

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:portlet="http://java.sun.com/portlet_2_0"
	xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

	<portlet:actionURL escapeXml="false" var="actionURL">
		<portlet:param name="foo" value="1234" />
		<portlet:param name="Non-Faces-Postback" value="true" />
	</portlet:actionURL>
	<form action="#{actionURL}" method="post">
		<input type="submit" value="#{i18n['submit-non-faces-postback']}" />
	</form>

</ui:composition>
public class ActionURLDemoPortlet extends GenericFacesPortlet {

	@Override
	public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException,
		IOException {

		String viewState = actionRequest.getParameter(ResponseStateManager.VIEW_STATE_PARAM);

		String nonFacesPostback = actionRequest.getParameter("Non-Faces-Postback");

		if ((viewState == null) && ("true".equalsIgnoreCase(nonFacesPostback))) {

			actionResponse.setRenderParameter("Non-Faces-Postback", nonFacesPostback);

			String foo = actionRequest.getParameter("foo");

			if (foo != null) {
				actionResponse.setRenderParameter("foo", foo);
			}
		}
		else {
			super.processAction(actionRequest, actionResponse);
		}
	}

	@Override
	protected void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException,
		IOException {

		String nonFacesPostback = renderRequest.getParameter("Non-Faces-Postback");

		if (nonFacesPostback == null) {
			super.doView(renderRequest, renderResponse);
		}
		else {
			PrintWriter writer = renderResponse.getWriter();
			writer.write("<p>");
			writer.write("Successfully executed ");
			writer.write("<strong>non-JSF postback</strong> in ");
			writer.write(ActionURLDemoPortlet.class.getName());
			writer.write("</p>");

			String foo = renderRequest.getParameter("foo");
			writer.write("<p>");
			writer.write("Action Parameter:<pre>foo=" + foo + "</pre>");
			writer.write("</p>");

			PortletURL renderURL = renderResponse.createRenderURL();
			renderURL.setParameter("componentPrefix", "portlet");
			renderURL.setParameter("componentName", "actionurl");
			renderURL.setParameter("componentUseCase", "general");
			writer.write("<p>");
			writer.write("<a href=\"" + renderURL.toString() + "\">");
			writer.write("Return to portlet:actionURL in the Liferay Faces Showcase");
			writer.write("</a>");
			writer.write("</p>");
		}
	}
}
Liferay Faces Bridge Implementation 4.1.0 + Showcase Common 3.0.1 + Liferay Faces Util 3.1.0 + Mojarra 2.2.14