掲示板

Use HTML page in MVC module rather than jsp LR7CE

7年前 に Peter Helgren によって更新されました。

Use HTML page in MVC module rather than jsp LR7CE

Regular Member 投稿: 124 参加年月日: 13/11/14 最新の投稿
I was attempting to use an HTML page rather than a jsp in my MVC module view. Instead of a view.jsp I was using a view.html just to experiment a bit. In 6.0.6 I would simply change the init parameter for init-jsp to the path to the html file. I don't see that approach in LR7CE. I did find the property setting in the java file and changed it:
"javax.portlet.init-param.view-template=/view.html",

But when I add the application to a page in the portal I see this stack trace error:

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

So, there must be some jiggery-pokery going on in the init.jsp and view.jsp that is missing when you just render an HTML page. If I switch the "javax.portlet.init-param.view-template=/view.html", back to "javax.portlet.init-param.view-template=/view.jsp", All is well.

So, how can I display an HTML page as a "view" parameter in an MVC module?
thumbnail
7年前 に Andy Wu によって更新されました。

RE: Use HTML page in MVC module rather than jsp LR7CE

Regular Member 投稿: 195 参加年月日: 15/05/05 最新の投稿
hey Peter , by default , the portlet only allow jsp extension files, see https://github.com/liferay/liferay-portal/blob/master/portal-kernel/src/com/liferay/portal/kernel/portlet/bridges/mvc/MVCPortlet.java#L222

But you can config
javax.portlet.init-param.valid-paths
to allow other extension files:
e.g.

@Component(
	immediate = true,
	property = {
		"com.liferay.portlet.display-category=category.sample",
		"com.liferay.portlet.instanceable=true",
		"javax.portlet.display-name=test Portlet",
		"javax.portlet.init-param.template-path=/",
		"javax.portlet.init-param.view-template=/view.html",
		"javax.portlet.init-param.valid-paths=/view.html",
		"javax.portlet.resource-bundle=content.Language",
		"javax.portlet.security-role-ref=power-user,user"
	},
	service = Portlet.class
)
public class TestPortlet extends MVCPortlet {
       
}


For your information :
as liferay is an open source project , if you meet some issue , you can clone the source code in here https://github.com/liferay/liferay-portal and try to find a solution.
7年前 に Peter Helgren によって更新されました。

RE: Use HTML page in MVC module rather than jsp LR7CE

Regular Member 投稿: 124 参加年月日: 13/11/14 最新の投稿
Thanks Andy. Yes, I know that LR is an Open Source project...been using 6.0.6 for 5 years. Just trying to readjust to 7.0 The learning curve is steep, but fun! I could have searched tens of thousands of lines of source code to find the answer, but sometimes asking a question is a little more focused!

As I mentioned, the standard service builder module had this:
property = {
"com.liferay.portlet.display-category=BSFapps",
"com.liferay.portlet.instanceable=true",
"javax.portlet.display-name=FindClass Portlet",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/view.html",
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=power-user,user"
},

So you are saying all I needed was one more property? Just need "javax.portlet.init-param.valid-paths=/view.html", ? Nice!

So, a follow up. I am also interested in using Freemarker templates as well (I'll do anything to avoid jsp's...) But Freemarker templates need to be processed before they are rendered. So what is the recommended way to use a Freemarker template in something like a mvc module view? If I did something like:

property = {
"com.liferay.portlet.display-category=category.sample",
"com.liferay.portlet.instanceable=true",
"javax.portlet.display-name=test Portlet",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/view.ftl",
"javax.portlet.init-param.valid-paths=/view.ftl",
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=power-user,user"
},

I'll try it, but if you have some wisdom here as well, I'd appreciate it. I was never able to get FM templates to render automatically in 6.0.6.
thumbnail
6年前 に Andy Wu によって更新されました。

RE: Use HTML page in MVC module rather than jsp LR7CE (回答)

Regular Member 投稿: 195 参加年月日: 15/05/05 最新の投稿
yes you can do freemarker in 7.x portal , see this example https://github.com/liferay/liferay-blade-samples/tree/master/liferay-workspace/modules/blade.portlet.freemarker

And also , this repo includes many examples , and you can try it.
6年前 に Peter Helgren によって更新されました。

RE: Use HTML page in MVC module rather than jsp LR7CE

Regular Member 投稿: 124 参加年月日: 13/11/14 最新の投稿
Nice! I'll start playing!