Include my own class in a JSP hook?

thumbnail
Cameron McBride, modified 14 Years ago. Expert Posts: 269 Join Date: 2/8/11 Recent Posts
Creating a hook and replacing a jsp with my own copy is pretty simple. In my jsp I would like to call my own method from my own class, is this possible?

/META-INF/custom_jsps/some/path/view.jsp
/WEB-INF/src/my/package/custom.java

In my view.jsp I import and try to use my class but it just gets a class no found error. What is the proper way to include my own classes?
thumbnail
MANOVINAYAK AYYAPPAN, modified 14 Years ago. Regular Member Posts: 131 Join Date: 6/13/11 Recent Posts
Hi Cameron,

Two Months back I experienced the same problem, when I was developing a Hook for the Blog Portlet and I got the same Class Not Found exception when I tried to call a util method from my custom Util Class.

I believe to do this we need to resort to EXT and not a Hook.

Back then I had less time and so I resorted to bad code practice, by defining my method in the JSP and calling the same inside the JSP.

Someone can explain this better as of why we get this error.

I did not get this error when I created other kinds of Hooks like event listener Hook, etc .

I believe Liferay Looks for your custom Class inside the standard package of the portlet for which you have created the Hook and NOT inside your custom package inside your Hook, as Hook are NOT for overriding Action classes.

Some one can throw more light on this.

Regards,
Mano
thumbnail
Prakash Khanchandani, modified 14 Years ago. Expert Posts: 329 Join Date: 2/10/11 Recent Posts
One way to include classes that can be accessed within a jsp inside a hook is to have a Custom Portlet developed.
Build the service and place the <pseudo-entity>service.jar inside [TOMCAT]/lib/ext/.

One reason I can think why your classes inside the hook are not referenced by the jsp is because the class-loader is different for plugins (hooks, portlet) [Plugins class-loader] and for loading liferay's inbuilt jars [Portal Class-loader]. And as the Jsp originally belongs to Liferay's core, your class in not loaded by Portal class-loader and hence is not visible to the jsp.

This blog-post may be of some help.