论坛

主页 » Liferay Portal » English » 3. Development

组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
toggle
Erik Nielsen
Generating Liferay URL in Velocity template for Web Content Display
2012年6月25日 上午11:01
答复

Erik Nielsen

等级: New Member

帖子: 3

加入日期: 2012年6月25日

最近的帖子

I would like to be able to use portletURLFactory to create a URL in a velocity template for the Web Content Display portlet. Unfortunately, according to [url=http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/CMS+Template+(Velocity)]these links, we don't have access to a real HttpServletRequest object here (and it's odd that we have access to portletURLFactory in this case).

Is there any way to get around this without using friendly URLs for any portlets to which you want to link? What I'd like to do (and what doesn't work) is something like:
1
2#set($plid = $getterUtil.getLong($portalUtil.getPlidFromPortletId($getterUtil.getLong($groupId), "portletName")))
3#set($url = $portletURLFactory.create($request, "portletName", $plid, "RENDER_PHASE"))
4## set some other parameters on the url
5## include the link


However, $url will not be populated because the call to create will not work, as far as I understand, because $request is not the real HttpServeletRequest.

Thanks,
Erik
Jelmer Kuperus
RE: Generating Liferay URL in Velocity template for Web Content Display
2012年6月25日 上午11:15
答复

Jelmer Kuperus

等级: Liferay Legend

帖子: 1192

加入日期: 2010年3月10日

最近的帖子

You could use javascript : http://www.liferay.com/web/eduardo.lundgren/blog/-/blogs/liferay-portleturl-in-javascript
Erik Nielsen
RE: Generating Liferay URL in Velocity template for Web Content Display
2012年6月25日 下午12:21
答复

Erik Nielsen

等级: New Member

帖子: 3

加入日期: 2012年6月25日

最近的帖子

Jelmer,

Is there a way to ensure that the portlet_url.js file gets included on a page? I know I can configure portlets to include specific JS files, but this isn't included in the page I'm building on which I'm putting the Web Content Display. Otherwise, that looks like a great solution.

Thanks,
Erik
Jelmer Kuperus
RE: Generating Liferay URL in Velocity template for Web Content Display
2012年6月26日 上午1:41
答复

Jelmer Kuperus

等级: Liferay Legend

帖子: 1192

加入日期: 2010年3月10日

最近的帖子

You include the module something like this :

1AUI().ready('liferay-portlet-url', function(A) {
2
3... code goes here
4});
Sachin Mane
RE: Generating Liferay URL in Velocity template for Web Content Display
2012年6月26日 上午4:52
答复

Sachin Mane

等级: Junior Member

帖子: 76

加入日期: 2012年4月9日

最近的帖子

i believe you will have access to PortletRequest (RenderRequesT) in the template.
You can use PortalUtil.getHttpServletRequest (PortletRequest portletRequest) to get the http request and then use PortletUrlFactory.
Erik Nielsen
RE: Generating Liferay URL in Velocity template for Web Content Display
2012年6月26日 上午7:24
答复

Erik Nielsen

等级: New Member

帖子: 3

加入日期: 2012年6月25日

最近的帖子

Thanks, that's exactly what I needed.

Erik
Michel Wicky
RE: Generating Liferay URL in Velocity template for Web Content Display
2013年1月14日 下午12:49
答复

Michel Wicky

等级: Regular Member

帖子: 130

加入日期: 2010年7月2日

最近的帖子

Hello Erik,

Did you got it ?

I cannot achiveve the class initialization, i don't why, may be you will find the reason or let us know about your code so i can compare.

Here is an abstract from the velocity web content template :

#foreach ($userOrganization in $userOrganizations)
#if ($userOrganization.getParentOrganization().getGroupId() == 10698)
#set ($httpRequest = $portalUtil.getHttpServletRequest())
#set ($myPlaceURL = $portletFactoryUtil.create($httpRequest, "49", $userOrganization.getGroup().getDefaultPublicPlid(), "ACTION_PHASE"))
#set ($myPlaceURL2 = $portletFactoryUtil.create($request, "49", $userOrganization.getGroup().getDefaultPublicPlid(), "ACTION_PHASE"))
$userOrganization.getGroup().getDefaultPublicPlid()
$myPlaceURL.toString()
$myPlaceURL2.toString()
## $myPlaceURL.setWindowState("normal")
## $myPlaceURL.setPortletMode("view")
## $myPlaceURL.setParameter("struts_action", "/my_places/view")
## $myPlaceURL.setParameter("groupId", $userOrganization.getGroupId().toString())
## $myPlaceURL.setParameter("privateLayout", "false")

## $myPlaceURL.toString()

<li><a href="${myPlaceURL.toString()}">$userOrganization.Name</a></li>

#set ($matched = $matched + 1)
#end
#end

Thank you
Tejas Kanani
RE: Generating Liferay URL in Velocity template for Web Content Display
2013年5月2日 上午5:19
答复

Tejas Kanani

等级: Liferay Master

帖子: 655

加入日期: 2009年1月6日

最近的帖子

Hi Michel,
Did you find any solution for this ? I am also not able to get HttpRequest in WCM template.

Thanks,
Tejas
Mazhar Alam
RE: Generating Liferay URL in Velocity template for Web Content Display
2013年11月25日 下午10:58
答复

Mazhar Alam

等级: Regular Member

帖子: 201

加入日期: 2011年11月25日

最近的帖子

I am also trying to create a sign in url into the webcontent. Still am trying to achieve this by templates and methods posted here.

If anyone have tried this, then do let me know.
Thanks
Aritz Galdos
RE: Generating Liferay URL in Velocity template for Web Content Display
2015年4月8日 上午2:33
答复

Aritz Galdos

等级: Expert

帖子: 405

加入日期: 2007年5月15日

最近的帖子

Hi Mazhar Alam

I had the same problem creating a portletURL object from velocity

This is the signature

PortletURLFactory.create(PortletRequest portletRequest, String portletId, long plid, String lifecycle)

Notice that plid requires a long type whereas the class of the $plid object available in velocity is String.

For me, this did the trick
1
2set($tmp = 0)
3#set ($plidLong = $tmp.parseInt($plid))


And then use $plidLong as param for PortletURLFactory.create

Hope that helps.

Regards
Balázs Csönge
RE: Generating Liferay URL in Velocity template for Web Content Display
2015年11月16日 上午5:56
答复

Balázs Csönge

等级: Regular Member

帖子: 107

加入日期: 2014年11月9日

最近的帖子

Hi All,

There is no working solution in this tread.

The problem with th PortletURLFactory.create(PortletRequest portletRequest, String portletId, long plid, String lifecycle) method, not really the plid. Yes of course, you must cast it to long with $getterUtil.getLong(), but the real pain the portletRequest input parameter.

Can anybody show a WORKING soluton on liferay 6.2?!

$request is a hashMap, the theme-display in it a hashMap too
$xmlRequest is a string which made from PortletRequest with toXml(method), but I did not find any method to convert it back.

Is any way to get the request in velocity as httpServletRequest or PortletRequest object?!?

I found the following, which is NOT working:
1#set ($serviceContext = $portal.getClass().forName("com.liferay.portal.service.ServiceContextThreadLocal").getServiceContext())
2#set ($httpServletRequest = $serviceContext.getRequest())


Something else?