Foren

Custom JSP hooks and class path question

Chad Allen, geändert vor 13 Jahren.

Custom JSP hooks and class path question

New Member Beiträge: 16 Beitrittsdatum: 10.06.10 Neueste Beiträge
I've created a simple jsp hook that extends a Liferay portlet jsp. My goal was to write a class and have my jsp file access the classes via an import statement.

Where is the proper place to put custom code that I want to call from the custom jsp files?

Currently, I've written my own library (external to the hook) and I've placed .jar in the global lib folder of tomcat in order for my custom jsp to load it. I can also get this to work if I copy my external library into the ROOT/WEB-INF/lib.

Is it possible to include the code as part of my hook? Is there a way to make these classes available to the custom jsp which get copied to the webapp/ROOT?

Thanks-
thumbnail
Minhchau Dang, geändert vor 13 Jahren.

RE: Custom JSP hooks and class path question

Liferay Master Beiträge: 598 Beitrittsdatum: 22.10.07 Neueste Beiträge
Chad Allen:
Where is the proper place to put custom code that I want to call from the custom jsp files?

It depends on why you need to call your custom classes and if you need access to any additional libraries as well (particularly if those additional libraries cannot be placed in the global class loader due to conflicts):

  • Manually put it in the global class loader locations. You're already doing this. As long as you never need any other Liferay classes that are inaccessible outside of the global class loader, this is the recommended route.
  • If you want to go down the tried-and-proven route, switch to using an EXT plugin which will achieve the same thing. It will copy all the files in ext-web to the Liferay folder and give those JSPs access to classes in the ext-impl and ext-service folders. This gives you access to libraries in the Liferay class loader.
  • Turn your hook into a portlet (which is allowed to have a liferay-hook.xml) and have your hook JSP generate portlet URLs to your portlet for all the actual work. This is a more difficult route to implement, but it gives you class loader separation which is preferred by some people since this means you can constantly redeploy without restarting the server.
  • If for some reason you want to leave everything as a hook rather than convert to an EXT plugin, then if you're comfortable figuring out your own build process for that custom code, put the JAR file in the WEB-INF/lib folder of your custom-jsps folder (this does not usually exist, you would have to create it). You still need to restart the server and you have to write your own build scripts, so no real benefit over an EXT plugin.
Chad Allen, geändert vor 13 Jahren.

RE: Custom JSP hooks and class path question

New Member Beiträge: 16 Beitrittsdatum: 10.06.10 Neueste Beiträge
Thanks so much for this incredibly detailed post. You've given me a couple great leads here.
thumbnail
Richard Gibson, geändert vor 13 Jahren.

RE: Custom JSP hooks and class path question

Junior Member Beiträge: 30 Beitrittsdatum: 19.02.10 Neueste Beiträge
Minhchau Dang:

  • Turn your hook into a portlet (which is allowed to have a liferay-hook.xml) and have your hook JSP generate portlet URLs to your portlet for all the actual work. This is a more difficult route to implement, but it gives you class loader separation which is preferred by some people since this means you can constantly redeploy without restarting the server.


Could you please provide some more details on this option? I don't understand how I can generate portlet URLs to my portlet from the hook JSP.
Could you provide an example please?
thumbnail
Minhchau Dang, geändert vor 13 Jahren.

RE: Custom JSP hooks and class path question

Liferay Master Beiträge: 598 Beitrittsdatum: 22.10.07 Neueste Beiträge
Richard Gibson:
Could you please provide some more details on this option? I don't understand how I can generate portlet URLs to my portlet from the hook JSP.

If you check the documentation on the renderURL tag library, you can set a portletName which is more or less equivalent to the portlet id that you use elsewhere (includes the portlet id in your portlet.xml and the WAR name). If you use those render URLs in your hook JSP, they will load your portlet.
thumbnail
Richard Gibson, geändert vor 13 Jahren.

RE: Custom JSP hooks and class path question

Junior Member Beiträge: 30 Beitrittsdatum: 19.02.10 Neueste Beiträge
Thanks for that information, that's exactly what I needed.
thumbnail
Alfredo del Castillo, geändert vor 13 Jahren.

RE: Custom JSP hooks and class path question

Junior Member Beiträge: 42 Beitrittsdatum: 18.01.11 Neueste Beiträge
How did you get it work?

Thanks in advance
Maxim Kovalev, geändert vor 12 Jahren.

RE: Custom JSP hooks and class path question

New Member Beiträge: 23 Beitrittsdatum: 15.02.12 Neueste Beiträge
anybody help
Maxim Kovalev, geändert vor 12 Jahren.

RE: Custom JSP hooks and class path question

New Member Beiträge: 23 Beitrittsdatum: 15.02.12 Neueste Beiträge
Hi, All
I created liferay project portlet "user-reg-portlet". It added the liferay hook, which overrides user_action.jsp
That's what I added to the user_action.jsp:
<liferay-portlet:renderurl plid="10163" portletmode="view" portletname="user-reg_WAR_user-reg-portlet" var="userRegisterPortlet">
	<liferay-portlet:param name="jspPage" value="/view.jsp" />
</liferay-portlet:renderurl>

&lt;%
	String printJS = "javascript: callPrint('" + UserPrintHelper.createHTMLpreview(user2, user) + "')";
%&gt;

<liferay-ui:icon image="print" url="<%= printJS %>" />


on view.jsp I imported the classes I needed.

[b]&lt;%@page import="user.reg.util.UserPropsUtil"%&gt;[/b]

&lt;%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %&gt;
<portlet:defineobjects />
This is the <b>UserRegisterPortlet</b> portlet .


but when you open user_action.jsp, I get the following error:
Only a type can be imported. user.reg.util.UserPropsUtil resolves to a package
UserPropsUtil cannot be resolved


how to fix it?
thumbnail
Brian Scott Schupbach, geändert vor 11 Jahren.

RE: Custom JSP hooks and class path question

Expert Beiträge: 329 Beitrittsdatum: 23.10.08 Neueste Beiträge
Hi Maxim,

Did you ever figure out how to correct your error? I'm getting the exact same error.

Thanks,

Brian
Maxim Kovalev, geändert vor 12 Jahren.

RE: Custom JSP hooks and class path question

New Member Beiträge: 23 Beitrittsdatum: 15.02.12 Neueste Beiträge
Richard Gibson:
Thanks for that information, that's exactly what I needed.


How you got it? please explain!

I have created a portlet project. It added the liferay hook custom jsp. What you need to add custom jsp, that I could use your java classes?

sorry for my english!