Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
German Tugores
Unable to use custom class in hook
April 14, 2012 7:55 AM
Answer

German Tugores

Rank: Junior Member

Posts: 33

Join Date: March 1, 2012

Recent Posts

Hi everyone,

I'm customizing a hook and need to access a java class I created to call its methods on custom_jsps files.

I´ve followed instructions from LR user's guide and from other posts but havent been able to make it work.

What I did:
1.create Interface "NewsUtil"
2. create a class that implements it "NewsUtilImpl"
3. add applicationContext.xml file on WEB-INF folder and declare the bean there
4. in jsp file call PortletBeanLocatorUtil to instantiate the bean

But it says the class NewsUtilImpl cant be resolved to a type

I'm doing something wrong, but dont know what exactly... Any ideas? Thanks in advance,
Germán
Hitoshi Ozawa
RE: Unable to use custom class in hook
April 14, 2012 8:17 AM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

Are you trying to override the News Portlet? Which version of Liferay are you using?
German Tugores
RE: Unable to use custom class in hook
April 14, 2012 9:34 AM
Answer

German Tugores

Rank: Junior Member

Posts: 33

Join Date: March 1, 2012

Recent Posts

Hi Hitoshi,

I'm trying to create a hook for announcements portlet, using Liferay 6.1
Jelmer Kuperus
RE: Unable to use custom class in hook
April 14, 2012 12:13 PM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

So you created a hook plugin which contains jsp hooks and a java class, and you want to call this java class from the jsp hook? Is that correct?

If that's the case it won't work. jsp files in jsp hooks are copied from the hook to the ROOT servlet context while the java classes remain in the hook servlet context, as such they are not on the classpath of the jsp because every servlet context can only see it's own classes and those of the parent classloaders. In order for it to work you should probably either move all your code to an ext plugin, or move the interface of your util to the common classpath, again via an ext plugin, so it ends up in tomcat/lib/ext and then get the class by it's interface via PortletBeanLocatorUtil
Hitoshi Ozawa
RE: Unable to use custom class in hook
April 14, 2012 7:00 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

Agree with jelmer on this. You should be creating an ext plugin instead of a hook. That was the point of my question.