Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Maxim Kovalev
Only a type can be imported
February 28, 2012 12:44 AM
Answer

Maxim Kovalev

Rank: New Member

Posts: 23

Join Date: February 14, 2012

Recent Posts

Hi, All
I created liferay project portlet. It added the liferay hook, which overrides user_action.jsp
In the jsp I need to access your class Test.java which I added in src portlet. But when you call I get an error:

An error occurred at line: 15 in the generated java file
Only a type can be imported. test.Test resolves to a package


I really need your help
Jitendra Rajput
RE: Only a type can be imported
February 28, 2012 1:01 AM
Answer

Jitendra Rajput

Rank: Liferay Master

Posts: 858

Join Date: January 7, 2011

Recent Posts

I think this Test.java is not present in your class path.
Jitendra Rajput
RE: Only a type can be imported
February 28, 2012 1:05 AM
Answer

Jitendra Rajput

Rank: Liferay Master

Posts: 858

Join Date: January 7, 2011

Recent Posts

look at this link for more information abt this errror.

http://stackoverflow.com/questions/1858463/java-error-only-a-type-can-be-imported-xyz-resolves-to-a-package
Maxim Kovalev
RE: Only a type can be imported
February 28, 2012 1:32 AM
Answer

Maxim Kovalev

Rank: New Member

Posts: 23

Join Date: February 14, 2012

Recent Posts

My problem is probably not the case.
custom_jsps \ html \ portlet \ users_admin \ edit_user.jsp I override the deploy when copied to the tomcat\webapps\ROOT\html\portlet \ users_admin, and the classes it needs are in the portlet. How do I make them visible?
Maxim Kovalev
RE: Only a type can be imported
February 28, 2012 1:49 AM
Answer

Maxim Kovalev

Rank: New Member

Posts: 23

Join Date: February 14, 2012

Recent Posts

I saw on the forum that this problem can be solved by renderURL
in custom_jsps \ html \ portlet \ users_admin \ edit_user.jsp I added:
1<liferay-portlet:renderURL plid="10163" portletName="user-reg_WAR_user-reg-portlet" var="userRegisterPortlet">
2</ liferay-portlet: renderURL>

That is, when you call the portlet should work its ClassLoader, but the problem persists

maybe I'm wrong?
Maxim Kovalev
RE: Only a type can be imported
February 28, 2012 3:18 AM
Answer

Maxim Kovalev

Rank: New Member

Posts: 23

Join Date: February 14, 2012

Recent Posts

Please, help me!
Natalie D
RE: Only a type can be imported
May 14, 2012 11:28 PM
Answer

Natalie D

Rank: Junior Member

Posts: 55

Join Date: February 6, 2012

Recent Posts

Maxim Kovalev:
Please, help me!


I know that almost three months have passed, but for other folks who will find this question in the future:
It is not possible to access classes from one portlet inside other portlets, due to different ClassLoaders. Think of it as every portlet/hook is inside its own sandbox.
When you want to access classes from other portlets it is just poor design. So change your strategy.

FYI: to access classes defined by yourself from any other portlet the only thing you can do (as far as I know) is prepare EXT plugin and add new classes to it.

Regards
Natalie
Thomas C
RE: Only a type can be imported
June 18, 2012 9:39 AM
Answer

Thomas C

Rank: New Member

Posts: 11

Join Date: January 25, 2012

Recent Posts

Hi, even if your statement is true, I got the error :

Only a type can be imported. x.y.service.XServiceUtil resolves to a package

When accessing to my service in my override jsp.

As Maxim Kovalev, I created Iiferay hook to override some struts action : /blogs/edit-entry
(I follow this page : http://www.liferay.com/web/mika.koivisto/blog/-/blogs/7132115 )

My liferay-hook.xml :
1<hook>
2    <custom-jsp-dir>/META-INF/custom_jsps</custom-jsp-dir>
3    <struts-action>
4        <struts-action-path>/blogs/edit_entry</struts-action-path>
5        <struts-action-impl>x.y.EditBlogEntryAction</struts-action-impl>
6    </struts-action>
7</hook>


I override /html/portlet/blogs/edit_entry.jsp and added the import :
1
2<%@ include file="x.y.service.XServiceUtil" %>


Natalie D:

It is not possible to access classes from one portlet inside other portlets, due to different ClassLoaders. Think of it as every portlet/hook is inside its own sandbox.
When you want to access classes from other portlets it is just poor design.

There is a single portlet;
Any suggestions?

Regards
Tom
Sandeep Nair
RE: Only a type can be imported
June 18, 2012 9:40 PM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1721

Join Date: November 5, 2008

Recent Posts

Hi Tom,

You are overriding portal's jsp, which will run in portal's classloader. So it cannot access the services in hook(hook's classloader is different). You have to move your custom-service.jar in global classpath for the issue to get resolved.

Regards,
Sandeep
Thomas C
RE: Only a type can be imported
June 20, 2012 12:31 AM
Answer

Thomas C

Rank: New Member

Posts: 11

Join Date: January 25, 2012

Recent Posts

Hi Sandeep,

Thanks for the precision.
Indeed, I move my custom-service.jar in tomcat's ext lib and it works.

Regards,
Tom