Forums

angle-left Back

RE: javax.portlet.PortletException: Path /view.jsp is not accessible by thi

PC
Pascal Collberg, modified 6 Months ago.

javax.portlet.PortletException: Path /view.jsp is not accessible by this po

New Member Posts: 2 Join Date: 5/26/15 Recent Posts
Hi!

I am trying to set up friendly urls. To start with I have followed this tutorial: http://liferayiseasy.blogspot.se/2016/11/friendly-url-in-liferay.html

Even though the tutorial is written for Liferay 6 I am trying to set this up in Liferay 7.

I have created a Liferay Workspace Project containing a module called friendly-web. This module is an mvc-portlet project. The portlet class looks like this (mostly copied from the tutorial):

@Component(immediate = true, property = { "com.liferay.portlet.display-category=category.sample",
"com.liferay.portlet.instanceable=true", "javax.portlet.display-name=friendly-web Portlet",
"javax.portlet.init-param.template-path=/", "javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.name=" + FriendlyWebPortletKeys.FriendlyWeb, "javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=power-user,user" }, service = Portlet.class)
public class FriendlyWebPortlet extends MVCPortlet {
public void addEmployee(ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException {
System.out.println("Add Method");
}
public void deleteEmployee(ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException {
System.out.println("Delete Method=>" + ParamUtil.getInteger(actionRequest, "userId"));
}
}


In src/main/resources/META-INF/resources there are three files:

  • init.jsp that I have not touched so it is like it was generated by the SDK.
  • display.jsp - a simple jsp printing a message
  • view.jsp (mostly copied from the tutorial):

<%@ include file="/init.jsp" %>

<!-- Action URL -->
<portlet:actionURL var="addEmployeeURL" name="addEmployee">
</portlet:actionURL>

<!-- Delete URL -->
<portlet:actionURL var="deleteEmployeeURL" name="deleteEmployee">
<portlet:param name="userId" value="1"/>
</portlet:actionURL>

<!-- Render URLs -->
<portlet:renderURL var="viewRenderURL">
<portlet:param name="mvcPath" value="/view.jsp"/>
</portlet:renderURL>

<portlet:renderURL var="displayRenderURL">
<portlet:param name="mvcPath" value="/display.jsp"/>
</portlet:renderURL>

<a href="<%= addEmployeeURL%>">Add URL</a><br>
<a href="<%= deleteEmployeeURL%>">Delete URL</a><br>
<a href="<%= viewRenderURL%>">Go to View </a><br>
<a href="<%= displayRenderURL%>">Go to Display</a><br>


Then I add a friendly url mapper that looks like this:

@Component(
immediate = true,
property = {
"javax.portlet.name=" + FriendlyWebPortletKeys.FriendlyWeb,
"com.liferay.portlet.friendly-url-routes=META-INF/friendly-url-routes/friendlywebfriendlyurlmapper/routes.xml"
},
service = FriendlyURLMapper.class
)
public class FriendlyWebFriendlyUrlMapper extends DefaultFriendlyURLMapper {
@Override
public String getMapping() {
return _MAPPING;
}
private static final String _MAPPING = "FriendlyWeb";
}


and routes.xml:

<?xml version="1.0"?>
<!DOCTYPE routes PUBLIC "-//Liferay//DTD Friendly URL Routes 7.0.0//EN" "http://www.liferay.com/dtd/liferay-friendly-url-routes_7_0_0.dtd">

<routes>
<route>
<pattern>/forView/{placeHolder}</pattern>
<generated-parameter name="mvcPath">/{placeHolder}.jsp</generated-parameter>
<ignored-parameter name="p_p_id" />
<implicit-parameter name="p_p_mode">view</implicit-parameter>
</route>

<!-- For Delete -->
<route>
<pattern>/forDelete/{placeHolder1}/{placeHolder2}</pattern>
<generated-parameter name="javax.portlet.action">{placeHolder1}</generated-parameter>
<generated-parameter name="userId">{placeHolder2}</generated-parameter>
<implicit-parameter name="p_p_lifecycle">1</implicit-parameter>
</route>

<!-- For ADD -->
<route>
<pattern>/forAdd/{placeHolder}</pattern>
<generated-parameter name="javax.portlet.action">{placeHolder}</generated-parameter>
<implicit-parameter name="p_p_lifecycle">1</implicit-parameter>
</route>
</routes>


I had to change some paths from the tutorial to make everything work but I still run into one issue. If I add the portlet to a page and then press either one of the "Add URL" or "Delete URL" links I get an error that says:

javax.portlet.PortletException: Path /view.jsp is not accessible by this portlet
at com.liferay.portal.kernel.portlet.LiferayPortlet.checkPath(LiferayPortlet.java:262)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.include(MVCPortlet.java:592)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.include(MVCPortlet.java:610)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.doDispatch(MVCPortlet.java:494)
at com.liferay.product.navigation.product.menu.web.internal.portlet.ProductNavigationProductMenuPortlet.doDispatch(ProductNavigationProductMenuPortlet.java:81)
at javax.portlet.GenericPortlet.render(GenericPortlet.java:262)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.render(MVCPortlet.java:317)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:103)
at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:57)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:153)
at org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:62)
at org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(DispatchTargets.java:117)
at org.eclipse.equinox.http.servlet.internal.servlet.RequestDispatcherAdaptor.include(RequestDispatcherAdaptor.java:48)
at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:530)
at com.liferay.portlet.InvokerPortletImpl.invokeRender(InvokerPortletImpl.java:605)
at com.liferay.portlet.InvokerPortletImpl.render(InvokerPortletImpl.java:391)


I am fairly new to Liferay development so I have a hard time understanding why the portlet should not have access to this path. The view.jsp should be on that specific path.

Can someone shed some light on this? What is preventing the portlet from accessing this jsp? The tutorial is made for Liferay 6 I think. Is something new introduced in Liferay 7 that I have not taken into account?

Thanks!
/Pascal
Tomas Polesovsky, modified 5 Months ago.

RE: javax.portlet.PortletException: Path /view.jsp is not accessible by thi

LIFERAY STAFF Liferay Master Posts: 654 Join Date: 2/13/09 Recent Posts
Hi Pascal,

this happens when the JSPs cannot be found in expected locations.

Please see:
https://github.com/liferay/liferay-portal/blob/7.0.4-ga5/portal-kernel/src/com/liferay/portal/kernel/portlet/LiferayPortlet.java#L488-L491

Please make sure the JSPs are stored inside your JAR in correct location, i.e. directly in root folder or /META-INF/resources folder.

HTH.
PC
Pascal Collberg, modified 5 Months ago.

RE: javax.portlet.PortletException: Path /view.jsp is not accessible by thi

New Member Posts: 2 Join Date: 5/26/15 Recent Posts
Thanks Tomas!

I'll try it out.

BR
/Pascal