Message Boards
Friendly URL from Action Command
Andres Sanz, modified 3 Years ago.
Friendly URL from Action Command
New Member Post: 1 Join Date: 9/14/20 Recent Posts
Hello everyone, I was able to build an example of a friendly url configuration following the instructions of this page https://help.liferay.com/hc/es/articles/360017885992-Making-URLs-Friendlier. Now I need to do some changes because I'm using ActionCommands to open different renders based on some business logic and when I do that the mapper is not working,
This is the action code I have:
@Component(
immediate = true,
property = {
"javax.portlet.name=" + TestFriendlyUrlPortletKeys.TESTFRIENDLYURL,
"mvc.command.name=/test/final/action"
},
service = MVCActionCommand.class
)
public class FinalMVCActionCommand implements MVCActionCommand{
@Override
public boolean processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException {
actionResponse.setRenderParameter("mvcRenderCommandName", "/test/render");
return false;
}
}
This is the render code I have:
@Component(
immediate = true,
property = {
"javax.portlet.name=" + TestFriendlyUrlPortletKeys.TESTFRIENDLYURL,
"mvc.command.name=/test/render"
},
service = MVCRenderCommand.class
)
public class FinalMVCRenderCommand implements MVCRenderCommand {
@Override
public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException {
return "/final.jsp";
}
}
And finally this is the routes.xml file<routes>
<route>
<pattern>/render</pattern>
<implicit-parameter name="mvcRenderCommandName">/test/render</implicit-parameter>
<implicit-parameter name="p_p_lifecycle">0</implicit-parameter>
<implicit-parameter name="p_p_state">normal</implicit-parameter>
</route>
</routes>
Thank you everyone for your time!
This is the action code I have:
@Component(
immediate = true,
property = {
"javax.portlet.name=" + TestFriendlyUrlPortletKeys.TESTFRIENDLYURL,
"mvc.command.name=/test/final/action"
},
service = MVCActionCommand.class
)
public class FinalMVCActionCommand implements MVCActionCommand{
@Override
public boolean processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException {
actionResponse.setRenderParameter("mvcRenderCommandName", "/test/render");
return false;
}
}
This is the render code I have:
@Component(
immediate = true,
property = {
"javax.portlet.name=" + TestFriendlyUrlPortletKeys.TESTFRIENDLYURL,
"mvc.command.name=/test/render"
},
service = MVCRenderCommand.class
)
public class FinalMVCRenderCommand implements MVCRenderCommand {
@Override
public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException {
return "/final.jsp";
}
}
And finally this is the routes.xml file<routes>
<route>
<pattern>/render</pattern>
<implicit-parameter name="mvcRenderCommandName">/test/render</implicit-parameter>
<implicit-parameter name="p_p_lifecycle">0</implicit-parameter>
<implicit-parameter name="p_p_state">normal</implicit-parameter>
</route>
</routes>
Thank you everyone for your time!