Liferay 7.2 - use journalarticle class in custom jsp hook

273 Views Asked by At

I have a module PortalHook that contains :

  • my class XCustomJspBag implements CustomJspBag
  • my jsp file terms_of_use (custom_jsps/html/portal/terms_of_use.jsp)

I need to use the JournalArticle class in this jsp file but when I add the following import :

<%@ page import="com.liferay.journal.model.JournalArticle" %>

It always get me an error :

Une erreur s'est produite à la ligne: [245] dans le fichier Java généré: [C:\x\bundles\tomcat-9.0.17\work\Catalina\localhost\ROOT\org\apache\jsp\html\portal\terms_005fof_005fuse_jsp.java] Only a type can be imported. com.liferay.journal.model.JournalArticle resolves to a package

Right now i'm stuck here.

(I've imported com.liferay.journal.pai-4.5.2.jar in the pom.xml)

1

There are 1 best solutions below

0
On

Looking at the CustomJspBag interface, it looks like it's only revealing the name of JSPs contained in a given module. I read this as them being resolved as relatively simple strings, and not processed within your custom module at all.

The problem is that you're injecting JSPs into Liferay's core, and you want the JSP to be dependent on a module. By definition that's something that shouldn't be done statically, but can be created dynamically, through explicit runtime means.

One option that comes to my mind is to try a Dynamic Include (DI) in your custom JSP. While the documentation talks about existing dynamic includes in JSPs, you can totally make up your own, and insert them into your custom JSPs. Then implement a proper DI with the new key that you came up with. As far as I remember, DIs will be resolved and executed within their module's context, so you'd have all of your dependencies there.

My expectation is that you can implement your DI in the same bundle that also holds your custom JSP.

Another alternative is to use any other kind of runtime dispatches, but I think that they're resulting in more work than DIs (provided they work the way I assume they do)