Foren

Liferay 7 Friendly URL issue

Nick Borushko, geändert vor 7 Jahren.

Liferay 7 Friendly URL issue

New Member Beiträge: 5 Beitrittsdatum: 29.07.16 Neueste Beiträge
Hi everyone,
I'm developing in Liferay 7 and am running into issues trying to get Friendly URLs to work correctly in my module. If I have the friendly URL mapping, it always seems to map to the MVCPortlet class instead of the MVCRenderCommand I am trying to use. My code is below, if anyone could give me a pointer I'd appreciate it. I've tried following the documentation here but have had no luck getting this to work: https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/making-urls-friendlier

routes.xml

<routes>
	<route>
		<pattern>/view/</pattern>
		<implicit-parameter name="mvcRenderCommandName">/examples/example/view</implicit-parameter>
		<implicit-parameter name="p_p_lifecycle">0</implicit-parameter>
		<implicit-parameter name="p_p_state">normal</implicit-parameter>
		<implicit-parameter name="p_p_mode">view</implicit-parameter>
		<implicit-parameter name="p_p_col_id">column-1</implicit-parameter>
		<implicit-parameter name="p_p_col_count">1</implicit-parameter>
	</route>
</routes>


ExampleFriendlyUrlMapper

@Component(
	property = {
		"com.liferay.portlet.friendly-url-routes=META-INF/friendly-url-routes/routes.xml",
		"javax.portlet.name=" + ExamplePortletKeys.PORTLET_NAME
	},
	service = FriendlyURLMapper.class
)
public class ExampleFriendlyUrlMapper extends DefaultFriendlyURLMapper {
	
	private static final String MAPPING = "example";
	
	@Override
	public String getMapping() {
		return MAPPING;
	}
	
	
}


ExampleMVCRenderCommand

@Component(immediate = true, property = {"javax.portlet.name=" + ExamplePortletKeys.PORTLET_NAME,
	"mvc.command.name=/examples/example/view"}, service = MVCRenderCommand.class)
public class ExampleMVCRenderCommand implements MVCRenderCommand {
       render code
}


MVCPortlet

@Component(immediate = true, property = {
	"com.liferay.portlet.display-category=Example Portlets",
	"com.liferay.portlet.instanceable=true", 
	"javax.portlet.name=" + ExamplePortletKeys.PORTLET_NAME,
	"javax.portlet.display-name=Example Portlet",
	"javax.portlet.init-param.template-path=/", 
	"javax.portlet.init-param.view-template=/view.jsp",
	"javax.portlet.resource-bundle=content.Language", 
	"javax.portlet.security-role-ref=power-user,user",
	"com.liferay.portlet.add-default-resource=true"}, 
	service = Portlet.class)
public class ExamplePortlet extends MVCPortlet {
           code not relevant
}


and finally, the command in my view.jsp

<portlet:renderurl var="exampleURL">
			<portlet:param name="mvcRenderCommandName" value="/examples/example/view" />
			<portlet:param name="state" value="${state}" />
</portlet:renderurl>


I've tried adding this to the route but when I do that, it doesn't create a friendly URL and goes back to the non-user friendly URL.
<generated-parameter name="state">{state}</generated-parameter>


So I thought maybe I was missing something from the pattern, so I changed it to be /view/{state} but it still refused to create the friendly URL.

Also, when it refuses to map it will go to the correct MVCRenderCommand, so there is no issue with the <portlet:renderURL> tag mapping to it. Just the friendly URL mapping has an issue.

Thank you!
thumbnail
David H Nebinger, geändert vor 7 Jahren.

RE: Liferay 7 Friendly URL issue

Liferay Legend Beiträge: 14916 Beitrittsdatum: 02.09.06 Neueste Beiträge
Instanceable portlets impose additional parameter requirements which it does not appear you've satisfied.

I'd verify that you actually need the instanceable property set for your portlet; it will be much easier to remove instanceable flag than it will be to figure out the right values to use for the friendly url.
Nick Borushko, geändert vor 7 Jahren.

RE: Liferay 7 Friendly URL issue

New Member Beiträge: 5 Beitrittsdatum: 29.07.16 Neueste Beiträge
David, thank you for your help. I had set up this portlet to be like the ones we made in the Liferay developer training course we took which had the instanceable property set to true. It turns out I don't need this portlet to be instanceable. I set that to false and looked through the parameters and added the new p_p_id value to the implicit parameters in the route. However, I am still having the same issue where it is only going to the MVCPortlet's doView method instead of my Render Command's render method. Does anyone have any other ideas?

new implicit parameter
<implicit-parameter name="p_p_id">com_examples_example_portlet</implicit-parameter>
Nick Borushko, geändert vor 6 Jahren.

RE: Liferay 7 Friendly URL issue

New Member Beiträge: 5 Beitrittsdatum: 29.07.16 Neueste Beiträge
For any others with this issue, I finally made a breakthrough. It turns out in the routes.xml, you can't have a trailing "/" in the <pattern> tag and that patterns need to have a "/{p_p_id}/" to ensure it maps it to the correct portlet. Removing that made the URLs map to my RenderCommands properly but they are missing the generated parameters I defined. On to the next challenge I suppose. Once I figure out what's going on with those I will come back and post my findings here.