Can Liferay portlets get parameters?

百般思念 提交于 2020-01-23 02:42:29

问题


I am having trouble understanding the concept of portlets in a CMS.

Let's say I write a weather portlet to display current temperature. I build it, package it in a war, deploy the war in Liferay.

Now I created a page, and I want to create 2 instances of the portlet I wrote. I want to display the weather in Seattle and the weather in Miami.

Can I do this? How do I pass the portlet a parameter to tell it which city to display?


回答1:


Portlet has so-called EDIT-mode. You can implement EDIT mode to show the form to choose which city you want to show the temperature for. Save this to portlet preferences. And when you will render the portlet in normal(VIEW) mode, look at the preferences for the city.

  • http://portals.apache.org/pluto/portlet-api/apidocs/javax/portlet/PortletPreferences.html
  • http://onjava.com/pub/a/onjava/2006/02/01/what-is-a-portlet-2.html?page=2



回答2:


Another option is PortletConfig - which is generally configured in portlet.xml and is similar to Servlet init params. Preferences is probably your best bet.

If you're working in Liferay in particular, LR's model-builder infrastructure will get you much of this functionality including editing quick/cheap at the cost of cross-container portability. On the plus side it will integrate well with LR's (limited) RBAC which tends to be important in distributed content authoring environments



来源:https://stackoverflow.com/questions/3120661/can-liferay-portlets-get-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!