Last active
October 17, 2018 11:21
-
-
Save kubadlo/b9ef010b0f218c53b60e8775ca62fa69 to your computer and use it in GitHub Desktop.
Simple util class to create various URLs in Spring MVC controllers used in Liferay portlets.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sk.o2.assistant.portlet.common.util; | |
import javax.portlet.PortletURL; | |
import javax.portlet.RenderResponse; | |
import javax.portlet.ResourceURL; | |
public final class PortletUtils { | |
private static final String PORTLET_ACTION_NAME = "javax.portlet.action"; | |
/** | |
* Creates an URL for @ActionMapping | |
* | |
* @param action value from @ActionMapping annotation | |
* @param response portlet render response | |
* @return an URL with portlet action | |
*/ | |
public static String getPortletActionUrl(String action, RenderResponse response) { | |
PortletURL actionURL = response.createActionURL(); | |
actionURL.setParameter(PORTLET_ACTION_NAME, action); | |
return actionURL.toString(); | |
} | |
/** | |
* Creates an URL for @ResourceMapping | |
* | |
* @param resource value from @ResourceMapping annotation | |
* @param response portlet render response | |
* @return an URL with portlet resource | |
*/ | |
public static String getPortletResourceUrl(String resource, RenderResponse response) { | |
ResourceURL resourceURL = response.createResourceURL(); | |
resourceURL.setResourceID(resource); | |
return resourceURL.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment