留言板

Include my own class in a JSP hook?

thumbnail
Cameron McBride,修改在12 年前。

Include my own class in a JSP hook?

Expert 帖子: 269 加入日期: 11-2-8 最近的帖子
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,修改在12 年前。

RE: Include my own class in a JSP hook?

Regular Member 帖子: 131 加入日期: 11-6-13 最近的帖子
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,修改在12 年前。

RE: Include my own class in a JSP hook?

Expert 帖子: 329 加入日期: 11-2-10 最近的帖子
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.