Foren

BeanLocator is null for servlet context mor-portlet

vaibhav gawali, geändert vor 7 Jahren.

BeanLocator is null for servlet context mor-portlet

Junior Member Beiträge: 25 Beitrittsdatum: 29.11.16 Neueste Beiträge
Hi everyone
i have created a theme for my mor-portlet
after i run a theme i got this ERROR

note: I removed the portlet and deploy it again many times Still i got this error
how to solve this
BeanLocator is null for servlet context mor-portlet

thanks in advance
thumbnail
Andrew Jardine, geändert vor 7 Jahren.

RE: BeanLocator is null for servlet context mor-portlet

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
You created a theme for your portlet? Do you mean that you added a theme plugin configuration to your portlet? (I hope not... you should NOT do that even if it lets you).

Can you please provide the entire stacktrace with your error?

Usually when I get this error it is because I have changed the name of my portlet and have to delete all the portlet-service/src/java code and re-run service builder. The Class Loader Proxy classes have a string with the servlet context name and if it is pointing to the OLD portlet name, rather than the new one, then Liferay can't find the right set of beans to work with.
thumbnail
Amos Fong, geändert vor 7 Jahren.

RE: BeanLocator is null for servlet context mor-portlet

Liferay Legend Beiträge: 2047 Beitrittsdatum: 07.10.08 Neueste Beiträge
Also, include the startup logs. It could be possible your portlet didn't deploy correctly.
vaibhav gawali, geändert vor 7 Jahren.

RE: BeanLocator is null for servlet context mor-portlet

Junior Member Beiträge: 25 Beitrittsdatum: 29.11.16 Neueste Beiträge
Andrew Jardine:
You created a theme for your portlet? Do you mean that you added a theme plugin configuration to your portlet? (I hope not... you should NOT do that even if it lets you).

Can you please provide the entire stacktrace with your error?

Usually when I get this error it is because I have changed the name of my portlet and have to delete all the portlet-service/src/java code and re-run service builder. The Class Loader Proxy classes have a string with the servlet context name and if it is pointing to the OLD portlet name, rather than the new one, then Liferay can't find the right set of beans to work with.



no
i mean i created a theme i just wanna show my tables from MOR-portlet
ok i am giving steps

1)i have created one MOR-portlet in that i have created service.xml
here is my "service.xml" for VendorList


<!--?xml version="1.0" encoding="UTF-8"?-->
 
 <service-builder package-path="com.mor">
 <author>vaibhav</author>
 <namespace>MOR</namespace>
 <entity name="VendorList" local-service="true" remote-service="true">
 <column name="vendorid" type="long" primary="true" />
 <column name="VendorIdentity" type="String" />
<column name="VendorName" type="String" />
<column name="mobileNo" type="String" />
<column name="Address" type="String" />
<column name="City" type="String" />
<column name="EmailId" type="String" />
<column name="Zipcode" type="String" />
<column name="State" type="String" />
<column name="Country" type="String" />
<column name="AppVersion" type="String" />
<column name="LocationId" type="String" />
<column name="Orgid" type="long" />
<column name="LocId" type="long" />
<order by="asc">
<order-column name="VendorName" case-sensitive="false" />
</order>
<finder return-type="Collection" name="LocationId">
<finder-column name="LocationId" />
<finder-column name="Orgid" />
</finder>
<finder return-type="Collection" name="LocId">
<finder-column name="LocId" />
<finder-column name="Orgid" />
</finder>
</entity>
</service-builder>



2)i bulided service and filled data in database because i wanna show vendor name ,address etc in theme

3)i created a velocity theme.In portal_normal.vm i did below
#set ($morLocalService = $serviceLocator.findService("mor-portlet", "com.liferay.mor.service.MorLocalService"))
#set ($vendorName= $vendorList.getVendorName())
<span class="VendorList">$vendorName()</span><br>

is this right???
note:my project name is MOR-portlet and in that service.xml i have many tables like vendor,retailer,distributor etc..but i want to show vendor name,address ,email etc..

4)In portal-ext.properties file i did changes below
velocity.engine.restricted.variables=

5)after i run the project
it shows only $vendorName()
but not getting vendor actual name
and console i got error:--------> BeanLocator is null for servlet context mor-portlet

should i deploy separate theme or deploy both i mean mor-portlet+ theme ?
thumbnail
Andrew Jardine, geändert vor 7 Jahren.

RE: BeanLocator is null for servlet context mor-portlet

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
You will need both the theme and the portlet deployed. A few questions.

1. What dev tooling are you using? (ANT? Maven?)

2. This was for Liferay 6.2 -- right?

3. Can you provide the lines of code from your theme where you use the serviceLocator to get the service? as well as the lines you use to set the vendor attributes?
vaibhav gawali, geändert vor 7 Jahren.

RE: BeanLocator is null for servlet context mor-portlet

Junior Member Beiträge: 25 Beitrittsdatum: 29.11.16 Neueste Beiträge
Andrew Jardine:
You will need both the theme and the portlet deployed. A few questions.

1. What dev tooling are you using? (ANT? Maven?)

2. This was for Liferay 6.2 -- right?

3. Can you provide the lines of code from your theme where you use the serviceLocator to get the service? as well as the lines you use to set the vendor attributes?



thanks for the reply

answers
1) yes i am using ANT
2) yes liferay 6.2 cega4


and here is my portal_normal.vm file
#set ($morLocalService = $serviceLocator.findService("mor-portlet", "com.liferay.mor.service.MorLocalService"))
#set ($vendorName= $vendorList.getVendorName())
<span class="VendorList">$vendorName()</span><br>



i.e full code of portal_normal.vm file in velocity theme



#parse ($init)




	<title>$the_title - $company_name</title>

	<meta content="initial-scale=1.0, width=device-width" name="viewport">

	$theme.include($top_head_include)




<a href="#main-content" id="skip-to-content">#language ("skip-to-content")</a>

$theme.include($body_top_include)

#dockbar()

<div class="container-fluid" id="wrapper">
	<header id="banner" role="banner">
		<div id="heading">
			<h1 class="site-title">
				<a class="$logo_css_class" href="$site_default_url" title="#language_format (" go-to-x", [$site_name])">
					<img alt="$logo_description" height="$site_logo_height" src="$site_logo" width="$site_logo_width">

					#if ($show_site_name)
						<span class="site-name" title="#language_format (" go-to-x", [$site_name])">
							$site_name
						</span>
					#end
				</a>

			</h1>

			<h2 class="page-title">
				<span>$the_title</span>
			</h2>
		</div>

		#if ($has_navigation || $is_signed_in)
			#parse ("$full_templates_path/navigation.vm")
		#end
	</header>

	<div id="content">
		<nav id="breadcrumbs">#breadcrumbs()</nav>
		</div>
		
      #set ($morLocalService = $serviceLocator.findService("mor-portlet", "com.liferay.mor.service.MorLocalService"))
      #set ($vendorName= $vendorList.getVendorName())
     <span class="VendorList">$vendorName()</span><br>

		#if ($selectable)
			$theme.include($content_include)
		#else
			$portletDisplay.recycle()

			$portletDisplay.setTitle($the_title)

			$theme.wrapPortlet("portlet.vm", $content_include)
		#end
	

	<footer id="footer" role="contentinfo">
		<p class="powered-by">
			#language ("powered-by") <a href="http://www.liferay.com" rel="external">Liferay</a>
		</p>
	</footer>
</div>

$theme.include($body_bottom_include)

$theme.include($bottom_include)



thumbnail
Andrew Jardine, geändert vor 7 Jahren.

RE: BeanLocator is null for servlet context mor-portlet

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
I don't see where you are setting $vendorList.

 #set ($morLocalService = $serviceLocator.findService("mor-portlet", "com.liferay.mor.service.MorLocalService"))
#set ($vendorName= $vendorList.getVendorName())


It looks like you are missing a

#set ($vendorList = $morLocalService.get...)


statement to set the value. In Freemarker you would get an actual error explosion. Velocity just dies silently.
thumbnail
Amos Fong, geändert vor 7 Jahren.

RE: BeanLocator is null for servlet context mor-portlet

Liferay Legend Beiträge: 2047 Beitrittsdatum: 07.10.08 Neueste Beiträge
Does "com.liferay.mor.service.MorLocalService" actually exist in your portlet?

It looks like from your service.xml your class would actually be something like "com.mor.service.VenderListLocalService".
vaibhav gawali, geändert vor 7 Jahren.

RE: BeanLocator is null for servlet context mor-portlet

Junior Member Beiträge: 25 Beitrittsdatum: 29.11.16 Neueste Beiträge
Amos Fong:
Does "com.liferay.mor.service.MorLocalService" actually exist in your portlet?

It looks like from your service.xml your class would actually be something like "com.mor.service.VenderListLocalService".



thanks alot Amos
yes you are right "com.liferay.mor.service.MorLocalService " that does not exist..

i replaced "com.mor.service.VenderListLocalService"
it works correctly

thanks alot Amos emoticon
Deepak pal, geändert vor 6 Jahren.

RE: BeanLocator is null for servlet context mor-portlet

New Member Beiträge: 15 Beitrittsdatum: 09.03.16 Neueste Beiträge
Hi Vaibhav I am using Lieferay 6.1 with ANT and trying to get custom table i.e "psft_v_temp" column value in portal_normal.vm file to display
as solId: But not able to do that. Following are code i am using , I created One BDR-portlet for service and try to call service in theme file.
Is there any wrong syntax in vm file ?

<entity name="psft_v_temp" local-service="true" remote-service="true">

<!-- PK fields -->
<column name="empId" type="String" primary="true"/>
<!-- Audit fields -->
<column name="name" type="String" />
<column name="email_addr" type="String" />
<column name="location" type="String" />

<!-- Order -->
<order by="asc">
<order-column name="name" />
</order>

<!-- Finder methods -->
<finder name="userrole" return-type="Collection">
<finder-column name="userrole" />
</finder>

<finder name="emp_id" return-type="psft_v_temp">
<finder-column name="empId" />
</finder>
<finder name="location" return-type="Collection">
<finder-column name="location" />
</finder>
</entity>


**********portal-normal.vm .*******************
#set($psftlocalService = $serviceLocator.findService("BDR-portlet","com.liferay.bdr.service.service.psft_v_tempLocalService"))
#set ($solId = $psftlocalService.getLocation())
Sol Id : $solId

trying to print location as solId But Not success.

Thanks
Deepak
thumbnail
Andrew Jardine, geändert vor 6 Jahren.

RE: BeanLocator is null for servlet context mor-portlet

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
I'm going from memory here, which is not great to be honest emoticon, but I think the first parameter in the findService is supposed to be a servlet context isn't it?

#set($psftlocalService = $serviceLocator.findService("BDR-portlet","com.liferay.bdr.service.service.psft_v_tempLocalService"))


If my memory is correct, then it should be: [portlet-id]_WAR_[pluginname]

Velocity sucks like this because you are probably getting a null for your service. Velocity tries to be nice and hides the fact that something really bad has happened (missing reference). Freemarker would blow up in your face and make it way more obvious.
thumbnail
Amos Fong, geändert vor 6 Jahren.

RE: BeanLocator is null for servlet context mor-portlet

Liferay Legend Beiträge: 2047 Beitrittsdatum: 07.10.08 Neueste Beiträge
If my memory is correct, then it should be: [portlet-id]_WAR_

"BDR-portlet" should be the servlet context. The _WAR_ would be the portletId.

I agree with Andrew about velocity not throwing errors properly. One way to debug is print out each line as it executes, including variables. So something like this would help pinpoint the issue:

$serviceLocator

<br>

#set($psftlocalService = $serviceLocator.findService("BDR-portlet","com.liferay.bdr.service.service.psft_v_tempLocalService"))

$psftlocalService 

<br>

#set ($solId = $psftlocalService.getLocation())

Sol Id : $solId