留言板

How to deploy StrutsAction hook properly?

thumbnail
Dmytro Plekhotkin,修改在8 年前。

How to deploy StrutsAction hook properly?

New Member 帖子: 16 加入日期: 15-10-12 最近的帖子
Hello, dear colleagues.

I created Liferay hook as a StrutsAction:
public class HtmlToPdfStrutsAction extends BaseStrutsAction {...}

with liferay-hook.xml:
<hook>
    <struts-action>
        <struts-action-path>/htmltopdf/process</struts-action-path>
        <struts-action-impl>com.fiti.frtl.pdf.HtmlToPdfStrutsAction</struts-action-impl>
    </struts-action>
</hook>


Then I wrote in CMD(In this moment Liferay instance was up and running):
mvn package
mvn liferay:deploy


And after successful deploy I went to localhost:8080/c/htmltopdf/process and got an Exception:

12:58:58,113 ERROR [http-bio-8080-exec-9][PortletLocalServiceImpl:973] Struts path htmltopdf is not mapped to a portlet in l
iferay-portlet.xml
12:58:58,115 ERROR [http-bio-8080-exec-9][RequestProcessor:206] Invalid path was requested /common/error
12:58:58,116 ERROR [http-bio-8080-exec-9][PortalRequestProcessor:539] User ID 20198
12:58:58,116 ERROR [http-bio-8080-exec-9][PortalRequestProcessor:540] Current URL /c/htmltopdf/process
12:58:58,116 ERROR [http-bio-8080-exec-9][PortalRequestProcessor:541] Referer null
12:58:58,117 ERROR [http-bio-8080-exec-9][PortalRequestProcessor:542] Remote address 127.0.0.1
12:58:58,117 ERROR [http-bio-8080-exec-9][PortalRequestProcessor:544] Invalid path was requested /common/error
12:58:58,118 WARN  [http-bio-8080-exec-9][code_jsp:?] {code="404", msg="Invalid path was requested", uri=/c/htmltopdf/proces
s}
java.lang.NullPointerException
        at com.liferay.portal.model.PortletConstants.getRootPortletId(PortletConstants.java:166)
        at com.liferay.portal.service.impl.PortletLocalServiceImpl.getPortletById(PortletLocalServiceImpl.java:471)


What I am doing wrong or how to fix the issue?
Matthew K.,修改在8 年前。

RE: How to deploy StrutsAction hook properly?

Junior Member 帖子: 74 加入日期: 15-8-31 最近的帖子
Use a path which already exists. For example 'portal'. Your complete path should look like this then:
<struts-action-path>/portal/process</struts-action-path>
thumbnail
Punam Shah,修改在8 年前。

RE: How to deploy StrutsAction hook properly?

Regular Member 帖子: 117 加入日期: 12-1-20 最近的帖子
Have you define the new path in "struts-config.xml"

Please refer : https://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/lp-6-1-dgen06-overriding-and-adding-struts-actions-0

Hope this will help you !!!

Thanks !!!
thumbnail
Dmytro Plekhotkin,修改在8 年前。

RE: How to deploy StrutsAction hook properly?

New Member 帖子: 16 加入日期: 15-10-12 最近的帖子
It works. Thank you!

However, I do not understand why I must define path that starts with existing path.
thumbnail
Juan Gonzalez,修改在8 年前。

RE: How to deploy StrutsAction hook properly?

Liferay Legend 帖子: 3089 加入日期: 08-10-28 最近的帖子
Dmytro Plekhotkin:
It works. Thank you!

However, I do not understand why I must define path that starts with existing path.


The only purpose of making a hook is to override an existing portal behavior, so it doesn't make sense to override a struts path if not defining an existing Liferay's struts action path.
thumbnail
Dmytro Plekhotkin,修改在8 年前。

RE: How to deploy StrutsAction hook properly?

New Member 帖子: 16 加入日期: 15-10-12 最近的帖子
Thank you for the answer.

What should I do if I need to add a new portal behavior?
thumbnail
Juan Gonzalez,修改在8 年前。

RE: How to deploy StrutsAction hook properly?

Liferay Legend 帖子: 3089 加入日期: 08-10-28 最近的帖子
Dmytro Plekhotkin:
Thank you for the answer.

What should I do if I need to add a new portal behavior?


Hmm can you explain the feature you want to add so we can think about the best approach?

Thanks.
thumbnail
Dmytro Plekhotkin,修改在8 年前。

RE: How to deploy StrutsAction hook properly?

New Member 帖子: 16 加入日期: 15-10-12 最近的帖子
Currently we develop Web Challenge portal that contains idea submission wizard.
User fills data using the wizard and sends it for saving. The data should be saved in a database and PDF should be generated from the data.
So I decided to create completely new Struts action that adds PDF generating behavior to the portal.
thumbnail
Juan Gonzalez,修改在8 年前。

RE: How to deploy StrutsAction hook properly?

Liferay Legend 帖子: 3089 加入日期: 08-10-28 最近的帖子
Dmytro Plekhotkin:
Currently we develop Web Challenge portal that contains idea submission wizard.
User fills data using the wizard and sends it for saving. The data should be saved in a database and PDF should be generated from the data.
So I decided to create completely new Struts action that adds PDF generating behavior to the portal.


Ok and one "stupid" question: why do you need this struts action to reside in portal? Can't be a resource request from a custom MVC portlet?
thumbnail
Dmytro Plekhotkin,修改在8 年前。

RE: How to deploy StrutsAction hook properly?

New Member 帖子: 16 加入日期: 15-10-12 最近的帖子
I think I do like that because our team do not know how to set up a development process using MVC portlets. Currently, our UI team uses Angular JS inside a portlet without any back-end code and they do not want to work with any JSP/JSF code to call resources.

So I decided to provide straight URLs with some actions. I thought it would simplify the collaboration between frond-end and back-end teams, because we have no fullstack developers.

Could you please suggest how to set up collaboration between front-end and back-end programmers to avoid forcing UI guys to work with JSP code?
thumbnail
Juan Gonzalez,修改在8 年前。

RE: How to deploy StrutsAction hook properly?

Liferay Legend 帖子: 3089 加入日期: 08-10-28 最近的帖子
Dmytro Plekhotkin:
I think I do like that because our team do not know how to set up a development process using MVC portlets. Currently, our UI team uses Angular JS inside a portlet without any back-end code and they do not want to work with any JSP/JSF code to call resources.

So I decided to provide straight URLs with some actions. I thought it would simplify the collaboration between frond-end and back-end teams, because we have no fullstack developers.

Could you please suggest how to set up collaboration between front-end and back-end programmers to avoid forcing UI guys to work with JSP code?


They can use javascript to create resource URL:

https://www.liferay.com/web/eduardo.lundgren/blog/-/blogs/liferay-portleturl-in-javascript.

Then you just simply have to create the MVCPortlet with serveResource method to provide that PDF download from backend.
thumbnail
Dmytro Plekhotkin,修改在8 年前。

RE: How to deploy StrutsAction hook properly?

New Member 帖子: 16 加入日期: 15-10-12 最近的帖子
Thank you for the answer.

In our previous projects UI team always had separate directory for creating "front-end stuff". It looks like if I create MVC portlet I should explain them how to run it using Maven, Tomcat, etc. They should not bother about Portlets, war-files and Maven at all.
Is it possible to set up such collaboration?
thumbnail
Juan Gonzalez,修改在8 年前。

RE: How to deploy StrutsAction hook properly?

Liferay Legend 帖子: 3089 加入日期: 08-10-28 最近的帖子
Dmytro Plekhotkin:
Thank you for the answer.

In our previous projects UI team always had separate directory for creating "front-end stuff". It looks like if I create MVC portlet I should explain them how to run it using Maven, Tomcat, etc. They should not bother about Portlets, war-files and Maven at all.
Is it possible to set up such collaboration?


Ok I understand. Then you could try to create a portlet with remote services, so they can just invoke those services using JSON web services through javascript. In those services you can return everything they need (resource URL, or whatever).

Other option could be creating a servlet for this purpose...
thumbnail
Dmytro Plekhotkin,修改在8 年前。

RE: How to deploy StrutsAction hook properly?

New Member 帖子: 16 加入日期: 15-10-12 最近的帖子
Thank you very much.
It looks like a nice solution.