Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Chad Allen
Custom JSP hooks and class path question
8. Februar 2011 11:18
Antwort

Chad Allen

Rang: New Member

Nachrichten: 16

Eintrittsdatum: 10. Juni 2010

Neue 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-
Minhchau Dang
RE: Custom JSP hooks and class path question
10. Februar 2011 09:12
Antwort

Minhchau Dang

LIFERAY STAFF

Rang: Expert

Nachrichten: 349

Eintrittsdatum: 22. Oktober 2007

Neue 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
RE: Custom JSP hooks and class path question
10. Februar 2011 05:47
Antwort

Chad Allen

Rang: New Member

Nachrichten: 16

Eintrittsdatum: 10. Juni 2010

Neue Beiträge

Thanks so much for this incredibly detailed post. You've given me a couple great leads here.
Richard Gibson
RE: Custom JSP hooks and class path question
18. März 2011 09:43
Antwort

Richard Gibson

Rang: Junior Member

Nachrichten: 30

Eintrittsdatum: 19. Februar 2010

Neue 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?
Minhchau Dang
RE: Custom JSP hooks and class path question
18. März 2011 17:24
Antwort

Minhchau Dang

LIFERAY STAFF

Rang: Expert

Nachrichten: 349

Eintrittsdatum: 22. Oktober 2007

Neue 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.
Richard Gibson
RE: Custom JSP hooks and class path question
21. März 2011 02:18
Antwort

Richard Gibson

Rang: Junior Member

Nachrichten: 30

Eintrittsdatum: 19. Februar 2010

Neue Beiträge

Thanks for that information, that's exactly what I needed.
Alfredo del Castillo
RE: Custom JSP hooks and class path question
20. April 2011 04:04
Antwort

Alfredo del Castillo

Rang: Junior Member

Nachrichten: 41

Eintrittsdatum: 18. Januar 2011

Neue Beiträge

How did you get it work?

Thanks in advance
Maxim Kovalev
RE: Custom JSP hooks and class path question
23. Februar 2012 00:36
Antwort

Maxim Kovalev

Rang: New Member

Nachrichten: 23

Eintrittsdatum: 14. Februar 2012

Neue 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!
Maxim Kovalev
RE: Custom JSP hooks and class path question
23. Februar 2012 03:21
Antwort

Maxim Kovalev

Rang: New Member

Nachrichten: 23

Eintrittsdatum: 14. Februar 2012

Neue Beiträge

anybody help
Maxim Kovalev
RE: Custom JSP hooks and class path question
27. Februar 2012 06:52
Antwort

Maxim Kovalev

Rang: New Member

Nachrichten: 23

Eintrittsdatum: 14. Februar 2012

Neue 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:
 1<liferay-portlet:renderURL plid="10163" portletMode="view" portletName="user-reg_WAR_user-reg-portlet" var="userRegisterPortlet">
 2    <liferay-portlet:param name="jspPage" value="/view.jsp" />
 3</liferay-portlet:renderURL>
 4
 5<%
 6    String printJS = "javascript: callPrint('" + UserPrintHelper.createHTMLpreview(user2, user) + "')";
 7%>
 8
 9<liferay-ui:icon
10    image="print"
11    url='<%= printJS %>'
12/>


on view.jsp I imported the classes I needed.
1
2[b]<%@page import="user.reg.util.UserPropsUtil"%>[/b]
3
4<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
5<portlet:defineObjects />
6This 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?
Brian Scott Schupbach
RE: Custom JSP hooks and class path question
28. Februar 2013 08:28
Antwort

Brian Scott Schupbach

Rang: Expert

Nachrichten: 331

Eintrittsdatum: 23. Oktober 2008

Neue Beiträge

Hi Maxim,

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

Thanks,

Brian