Liferayは6年連続でGartner Magic Quadrantのリーダーに。 詳細はこちら
The Proposals Wiki has been deprecated in favor of creating Feature Requests in JIRA. If you wish to propose a new idea for a feature, visit the Community Ideas Dashboard and read the Feature Requests Wiki page for more information about submitting your proposal.
« FrontPage に戻る

Rules Based Portlet Rendering

This is "Work in Progress"#

Requirement LPS-2909#

Portlets can be configured to have various permissions, like view, configure etc. , based on a role. But there is no way to control when the portlet will be rendered/displayed based on arbitrary rules using user attributes and date/time. Some examples are shown below:

  1. Display a promotion portlet during first 7 days of every month.
  2. Display a portlet to users who login from IP address that matches 19.168..
  3. Display a voter registration portlet to users who are 18 or older.

Solution#

A basic rules engine is provided, which can be enabled using portal.properties.

##

    1. Portlet Render Rules
  1. Specify comma separated render rules evaluator chain.
  2. The evaluator chain executes in the specified order and returns
  3. false when any one of them returns false.
  4. BasicRenderRulesEvaluator is a built-in evaluator which allows one to
  5. specify render rules based on user attributes, day, date and time.
  6. portlet.render.rules.evaluators=com.liferay.portal.security.permission.BasicRenderRulesEvaluator }}}

When the rules evaluator is enabled by uncommenting the above property, a new tab "Render Rules" shows up for each portlet under configuration.

The UI has a text field where you can enter rules as explained later below. This is a primitive UI which will be fixed soon to make it more intuitive and user friendly. LPS-2910

When a custom rules evaluator is plugged in, another row shows the text field where the rules can be entered for your rules evaluator.
The label for the text field can be localized by adding a key to Language.properties. The key should be of this format,
render.rules.evaluator.com.example.MyRulesEvaluator=My Render Rules

To hide the portlet completely, this property needs to be set.
layout.show.portlet.access.denied=false

To plugin you own rules evaluator, write a class that implements com.liferay.portal.security.permission.RenderRulesEvaluator interface.

public interface RenderRulesEvaluator {
public boolean isRenderable(long userId, long groupId, String renderRule); } }}}

Basic Rules Evaluator#

BasicRenderRulesEvaluator is the built-in evaluator that uses the basic rules engine.

Examples#

Now lets see how the sample requirements can be fulfilled.
1. Display a promotion portlet during first 7 days of every month but only on weekends.
Rule: date>=/1/&&date<=/7/&&(day==1||day==7)

2. Display a portlet to female users who login from IP address that matches 192.168..
Rule: user.attr.loginIP=192.168..&&user.attr.male!=true

3. Display a voter registration portlet to users who are 17 years and 6 months or older.
Rule: user.attr.age>=17.6

1 画像の固定
23826 参照数
平均 (2 投票)
平均評価は4.5星中の5です。
コメント
コメント 作成者 日時
hi. i am using liferay 5.2.3 bundle.I am not... ankit yakkundi 2010/12/29 1:12
Nice feature... It is available from which... Jay Patel 2011/03/17 22:56
I've created an EXT plug-in for Liferay 6 that... Timmy M. 2011/05/06 6:53
Tim - yes, we would be very interested in such... alex winner 2011/05/17 9:08
Hi Tim, Can I use this to render portlet based... Rajender Reddy Nagulapalle 2012/03/26 13:06
This post is really good, but how to get... Saurabh Gupta 2013/03/04 21:53

hi.
i am using liferay 5.2.3 bundle.I am not able to find " Portlet Render Rules" under portal.properties stored under portal-impl.jar under \tomcat-5.5.27\webapps\ROOT\WEB-INF\lib directory.
Can you help from where i can get the above specified code?
投稿日時:10/12/29 1:12
Nice feature...
It is available from which version of Liferay?
投稿日時:11/03/17 22:56
I've created an EXT plug-in for Liferay 6 that enables this rule based portlet rendering. Somebody interested in it?
投稿日時:11/05/06 6:53
Tim - yes, we would be very interested in such a plugin. Have you published or posted it anywhere?
Thanks,
-- Alex
Tim FoXへのコメント。投稿日時:11/05/17 9:08
Hi Tim,
Can I use this to render portlet based on region? Like Aisa Pacific, Europe etc?
alex winnerへのコメント。投稿日時:12/03/26 13:06
This post is really good, but how to get RenderRules. i am using liferay 6.6.1 version. yes, Ia m interested in this, i want to show the particular portlet based on particular role.

Thanks in advance for helping me.
Tim FoXへのコメント。投稿日時:13/03/04 21:53