论坛

主页 » Liferay Portal » English » 3. Development

组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
toggle
Michel Wicky
how to get HttpServletRequest or PortletRequest from cms template
2013年1月17日 下午12:14
答复

Michel Wicky

等级: Regular Member

帖子: 130

加入日期: 2010年7月2日

最近的帖子

Hi all, did somebody know how to get HttpServletRequest or PortletRequest from a velocity script in a web content template ?
Thx a lot.
Mika Koivisto
RE: how to get HttpServletRequest or PortletRequest from cms template
2013年1月17日 下午4:05
答复

Mika Koivisto

LIFERAY STAFF

等级: Liferay Legend

帖子: 1513

加入日期: 2006年8月7日

最近的帖子

You can't unfortunately get access to either one in web content template because they are rendered in the service backend. You need to find another approach to what you are trying to accomplish.
Jelmer Kuperus
RE: how to get HttpServletRequest or PortletRequest from cms template
2013年1月17日 下午11:00
答复

Jelmer Kuperus

等级: Liferay Legend

帖子: 1192

加入日期: 2010年3月10日

最近的帖子

You have access to an xml representation of the request. This xml document is available in the template as xmlRequest. It is documented on the wiki.

Note however that webcontent is usually cached and you'd have to disable caching in order to make use of this
Michel Wicky
RE: how to get HttpServletRequest or PortletRequest from cms template
2013年1月17日 下午11:01
答复

Michel Wicky

等级: Regular Member

帖子: 130

加入日期: 2010年7月2日

最近的帖子

Ok i understand.

An another way is may be to use friendly URL like below:

#foreach ($userOrganization in $userOrganizations)
#if (!$userOrganization.isRoot() && $userOrganization.getParentOrganization().getGroupId() == 10698)
## debug $request.theme-display
## debug $getterUtil.getBoolean("false")
#set ($organizationFriendlyPath = $userOrganization.getGroup().getPathFriendlyURL($getterUtil.getBoolean("false"), $request.theme-display))
## debug $organizationFriendlyPath
#set ($organizationFriendlyURL = $userOrganization.getGroup().getFriendlyURL())
## debug $organizationFriendlyURL
#set ($OrganizationLink = "$organizationFriendlyPath$organizationFriendlyURL")
$OrganizationLink

<li><a href="${OrganizationLink}">$userOrganization.Name</a></li>

#end

Unfortunately, this statement don't execute correctly :
#set ($organizationFriendlyPath = $userOrganization.getGroup().getPathFriendlyURL($getterUtil.getBoolean("false"), $request.theme-display))

$request.theme-display seem not to be the right Type even I supposed it is RequestVars.getThemeDisplay, but may be it is not !?
Michel Wicky
RE: how to get HttpServletRequest or PortletRequest from cms template
2013年1月17日 下午11:16
答复

Michel Wicky

等级: Regular Member

帖子: 130

加入日期: 2010年7月2日

最近的帖子

Thanks Jelmer, I need HttpServletRequest or PortletRequest to use one of them in $Request in the statement below:
#set ($myPlaceURL = $portletFactoryUtil.create($Request, "49", $userOrganization.getGroup().getDefaultPublicPlid(), "ACTION_PHASE"))

The goal is just to list some organization from a velocity script web content template with a link to each organization.

I already have everything (user, organization, group), i just need this parameter to finish the job. If i can't have it I have to find an another way to achieve this like may the second example i posted.

Thanks for your recommandation ...
Jelmer Kuperus
RE: how to get HttpServletRequest or PortletRequest from cms template
2013年1月18日 上午1:33
答复

Jelmer Kuperus

等级: Liferay Legend

帖子: 1192

加入日期: 2010年3月10日

最近的帖子

You can't create links like that from a cms template because that would require access to the real request

You should pobably use javascript as i describe in this post
Michel Wicky
RE: how to get HttpServletRequest or PortletRequest from cms template
2013年1月18日 上午10:20
答复

Michel Wicky

等级: Regular Member

帖子: 130

加入日期: 2010年7月2日

最近的帖子

Thank you a lot Jelmer, finally an information that will orient me correctly. I understand why javascript is the way to get these informations.
Hope I will able to achieve this.
Thx again.
Balázs Csönge
RE: how to get HttpServletRequest or PortletRequest from cms template
2015年11月16日 上午5:45
答复

Balázs Csönge

等级: Regular Member

帖子: 107

加入日期: 2014年11月9日

最近的帖子

Hi,

Were you able to get the request object?
If yes can you publish the solution CODE?

Regards

Balázs