Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Cameron McBride
Include my own class in a JSP hook?
November 17, 2011 10:49 AM
Answer

Cameron McBride

Rank: Expert

Posts: 273

Join Date: February 8, 2011

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?
MANOVINAYAK AYYAPPAN
RE: Include my own class in a JSP hook?
November 17, 2011 6:05 PM
Answer

MANOVINAYAK AYYAPPAN

Rank: Regular Member

Posts: 132

Join Date: June 13, 2011

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
Prakash Khanchandani
RE: Include my own class in a JSP hook?
November 18, 2011 12:14 AM
Answer

Prakash Khanchandani

Rank: Expert

Posts: 329

Join Date: February 10, 2011

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 /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.