简体   繁体   English

为Liferay CMS / Portal编写Portlet

[英]Writing Portlets for Liferay CMS/Portal

I am new to portlets and have a question about how they work in CMS portals ( we are evaluating Liferay as a CMS ). 我是portlets的新手,对于它们如何在CMS门户中工作有疑问(我们正在评估Liferay作为CMS)。

Let's say, for example, I would like to create a portlet to display all the books required for a particular course. 比方说,我想创建一个portlet来显示特定课程所需的所有书籍。 You don't have to be logged in to see this, it will appear on public website. 您无需登录即可查看此内容,它将显示在公共网站上。

In the CMS, I will create two pages for ENGL-100 and HIST-300. 在CMS中,我将为ENGL-100和HIST-300创建两个页面。

I want to add the same portlet on each page. 我想在每个页面上添加相同的portlet。 I expect to deploy the portlet as a war file. 我希望将portlet部署为war文件。

How will I tell the portlet on each page which course to look up? 我如何告诉每个页面上的portlet要查找哪个课程? Don't tell me I have to change the portlet.xml file for each subject. 不要告诉我必须为每个主题更改portlet.xml文件。 Does a portlet have any access to URL parameters? portlet是否可以访问URL参数?

Portlets should not rely on URL parameters directly - for this exact reason - you might have multiple instances on the same page, and don't want them to collide (since they'll all see the params during Render, though only one will get Action) Portlet 不应该直接依赖URL参数 - 出于这个原因 - 您可能在同一页面上有多个实例,并且不希望它们发生碰撞(因为它们在Render期间都会看到params,但只有一个会获得Action )

In Liferay, you can just drop 2 portlets, and if you use Preferences through an EDIT or Liferay Config view, the prefs will be scoped separately to render initial state. 在Liferay中,您可以删除2个portlet,如果通过EDIT或Liferay Config视图使用Preferences,则prefs将分别作用于呈现初始状态。 The container will handle keeping the 2 portlets straight. 容器将处理保持2个portlet笔直。

Yes, portlets can process URL parameters. 是的,portlet可以处理URL参数。 That's the way you'd go to implement what you want. 这就是你实现你想要的方式。 Depending on the page you are visiting, you just pass the course subject as a URL parameter and let the portlet process it for you. 根据您访问的页面,您只需将课程主题作为URL参数传递,然后让portlet为您处理。 Of course you have to go to the database to look for the right course, etc to return the proper data. 当然,你必须去数据库寻找正确的课程等,以返回正确的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM