Fórum

how to show database table users like firstname ,lastname ,role in theme

vaibhav gawali, modificado 7 Anos atrás.

how to show database table users like firstname ,lastname ,role in theme

Junior Member Postagens: 25 Data de Entrada: 29/11/16 Postagens Recentes
hi everyone
I'm new in liferay.....please help

thanks in advance

i have created one theme and i have created table in service.xml
but i want to show different users from my database like firstname ,lastname ,role in theme

1.i have created one MOR_portlet .in that i created service.xml(note:-i have created 1 table "Retailer " i want to show that Retailer firstname ,lastname)
2)i builded service and copied my MOR-portlet-service.jar file in tomcat-7.0.27\lib\ext .i.e G:\liferay1\liferay-portal-6.2-ce-ga4\tomcat-7.0.42\lib\ext folder

3) also deployed theme but how can i show the my database user information after user login
i refer this link http://www.liferaysavvy.com/2013/12/access-liferay-database-services-in.html

but unable to show user information please help
thumbnail
Andrew Jardine, modificado 7 Anos atrás.

RE: how to show database table users like firstname ,lastname ,role in them

Liferay Legend Postagens: 2416 Data de Entrada: 22/12/10 Postagens Recentes
What you are looking for is the "service locator". There are lots of examples out there for it so try googling

"Liferay service locator example"

... Most of them reference services from the liferay core,. But the find() method call also supports a servlet context. You should be able to load your services from your custom portlet by specifying the service name, and your plugins servlet context.
vaibhav gawali, modificado 7 Anos atrás.

RE: how to show database table users like firstname ,lastname ,role in them

Junior Member Postagens: 25 Data de Entrada: 29/11/16 Postagens Recentes
thanks alot for reply Andrew Jardine

1)here is my "service.xml" for VendorList
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.2.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_2_0.dtd">
<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 have set a path in portal-ext.properties file
velocity.engine.restricted.variables=
3)i builded service and copied my MOR-portlet-service.jar file in tomcat-7.0.27\lib\ext .i.e G:\liferay1\liferay-portal-6.2-ce-ga4\tomcat-7.0.42\lib\ext folder

4) in my theme project
i want to show vendor name in theme after user login in .so i have modified portal_normal.vm file
#set ($vendorListService = $serviceLocator.findService("MOR-portlet", "com.mor.service.VendorListLocalService"))
#set ($vendorList =$vendorListLocalService.getVendorList())
#set ($vendorName= $vendorList.getVendorName())
<span class="VendorList">$vendorName()</span><br>


full code of portal_normal.vm file
<!DOCTYPE html>

#parse ($init)

<html class="$root_css_class" dir="#language ("lang.dir")" lang="$w3c_language_id">

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

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

$theme.include($top_head_include)
</head>

<body class="$css_class">

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

#set($userLocalService = $serviceLocator.findExceptionSafeService("com.liferay.portal.service.UserLocalService"))
#set( $user = $permissionChecker.getUser() )
<div class="user-welcome">
#if($user.isMale())
<span class="welcome-msg"><h1>Welcome user</h1></span><br>
#else
<span class="welcome-msg">NotLogged</span><br>
#end
<span class="username">$user.getFullName() $user.getLastName() $user.getFirstName()</span>


#set ($vendorListService = $serviceLocator.findService("MOR-portlet", "com.mor.service.VendorListLocalService"))
#set ($vendorList =$vendorListLocalService.getVendorList())
#set ($vendorName= $vendorList.getVendorName())
<span class="VendorList">$vendorName()</span><br>

</div>

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

$portletDisplay.setTitle($the_title)

$theme.wrapPortlet("portlet.vm", $content_include)
#end
</div>

<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)

</body>

</html>
please tell if im doing wrong
vaibhav gawali, modificado 7 Anos atrás.

RE: how to show database table users like firstname ,lastname ,role in them

Junior Member Postagens: 25 Data de Entrada: 29/11/16 Postagens Recentes
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
vaibhav gawali, modificado 7 Anos atrás.

RE: how to show database table users like firstname ,lastname ,role in them

Junior Member Postagens: 25 Data de Entrada: 29/11/16 Postagens Recentes
Andrew Jardine:
What you are looking for is the "service locator". There are lots of examples out there for it so try googling

"Liferay service locator example"

... Most of them reference services from the liferay core,. But the find() method call also supports a servlet context. You should be able to load your services from your custom portlet by specifying the service name, and your plugins servlet context.



thanks alot for reply Andrew Jardine

1)here is my "service.xml" for VendorList
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.2.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_2_0.dtd">
<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 have set a path in portal-ext.properties file
velocity.engine.restricted.variables=
3)i builded service and copied my MOR-portlet-service.jar file in tomcat-7.0.27\lib\ext .i.e G:\liferay1\liferay-portal-6.2-ce-ga4\tomcat-7.0.42\lib\ext folder

4) in my theme project
i want to show vendor name in theme after user login in .so i have modified portal_normal.vm file
#set ($vendorListService = $serviceLocator.findService("MOR-portlet", "com.mor.service.VendorListLocalService"))
#set ($vendorList =$vendorListLocalService.getVendorList())
#set ($vendorName= $vendorList.getVendorName())
<span class="VendorList">$vendorName()</span><br>


full code of portal_normal.vm file
<!DOCTYPE html>

#parse ($init)

<html class="$root_css_class" dir="#language ("lang.dir")" lang="$w3c_language_id">

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

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

$theme.include($top_head_include)
</head>

<body class="$css_class">

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

#set($userLocalService = $serviceLocator.findExceptionSafeService("com.liferay.portal.service.UserLocalService"))
#set( $user = $permissionChecker.getUser() )
<div class="user-welcome">
#if($user.isMale())
<span class="welcome-msg"><h1>Welcome user</h1></span><br>
#else
<span class="welcome-msg">NotLogged</span><br>
#end
<span class="username">$user.getFullName() $user.getLastName() $user.getFirstName()</span>


#set ($vendorListService = $serviceLocator.findService("MOR-portlet", "com.mor.service.VendorListLocalService"))
#set ($vendorList =$vendorListLocalService.getVendorList())
#set ($vendorName= $vendorList.getVendorName())
<span class="VendorList">$vendorName()</span><br>

</div>

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

$portletDisplay.setTitle($the_title)

$theme.wrapPortlet("portlet.vm", $content_include)
#end
</div>

<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)

</body>

</html>

please tell if im doing wrong

after i run the project
it shows only $vendorName()
but not getting vendor actual name
thumbnail
Andrew Jardine, modificado 7 Anos atrás.

RE: how to show database table users like firstname ,lastname ,role in them

Liferay Legend Postagens: 2416 Data de Entrada: 22/12/10 Postagens Recentes
Hi Vaibhav,

Couple of things. When you are posting in the forums, can you please try to remember to use the <> icon in the header of this window to wrap your code, rather than just dumping it in the message. It makes it much easier to read for others.

First, when you are referencing the servlet context that you are trying to load the service from, you don't need to put the jar in the lib/ext. You should avoid doing this, and Liferay gives you the tools to do that, so that you don't expose the library to everything on the server unnecessarily. Using this approach can introduce security holes so you should avoid it unless it is really necessary.

Second, the new defacto standard (though unofficial) for templating is to use Freemarker. There aren't as many examples out there (though there are more and more with each passing day) but the documentation for freemarker is excellent. One of the reasons I think there has been a shift to FTL is because, unlike Velocity, it doesn't just quietly fail -- it explodes with a stacktrace giving you some indication of what went wrong.

Your changes are pretty small -- can you switch to FTL and see if an actual error is generated for you? NOTE: there is a separate property in the portal-ext to allow that serviceLocator for freemarker -- so make sure you enable that one, and then disable it again for velocity.

Once you are done that, can you report back your results?