zoukankan      html  css  js  c++  java
  • liferay中如何获取实例的id和portletId

    在Portlet中request分为两种renderRequet和actionRequest而portlet需要取得实例Id的时候都在renderRequest的时候才可以取到,如下例子

    PortletPreferences preferences = renderRequest.getPreferences();
    String portletResource = ParamUtil.getString(request, "portletResource");
    if (Validator.isNotNull(portletResource)) {
    	preferences = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);
    	
    }
    其中portletResource是portlet的id 然后通过PortletPreferencesFactoryUtil工具类可以取得相应的portlet配置信息。

    而在actionRequest是取不到的portlet实例的id的,actionRequest只是把当前页面所有东西传进来而已,中间经过portletAcition做了处理,如果在portletAction中做取portletId是不可取的,但是在Liferay中已经提供了这样的方法可以让我们在actionRequest中取得portlet的实例Id代码如下

     ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest
    		 .getAttribute(WebKeys.THEME_DISPLAY);
    		 PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
    		System.out.println("portletDisplay---->"+portletDisplay.getInstanceId());
    		System.out.println("portletDisplay getId---->"+portletDisplay.getId());
    		System.out.println("portletDisplay getPortletName---->"+portletDisplay.getPortletName());

    这样就可以取到我们需要的对应的portlet实例id了

    其中WebKeys.THEME_DISPLAY是Liferay中里面的接口常量 对应的名字是 THEME_DISPLAY

    这篇文章是转载人家的文章,文章的出处是http://www.cnblogs.com/edwardlauxh/archive/2010/03/26/1918614.html

  • 相关阅读:
    作业七—“南通大学教务管理系统微信公众号”用户体验分析
    作业6—成绩录入系统设计(第一阶段)
    作业5-需求分析(EX:南通大学成绩录入系统)
    几次接触Collection排序使用总结
    作业4-两人编程<词频统计>
    ACE智能指针
    Buddy Memorry
    子数组和与积
    数字转化为大写(16位以下)
    【阿里巴巴-飞猪旅行-内推】2020年应届实习生招聘
  • 原文地址:https://www.cnblogs.com/airycode/p/4813850.html
Copyright © 2011-2022 走看看