根据Portletid跳转到其他画面

来源:互联网 发布:查看linux安装的字体 编辑:程序博客网 时间:2024/04/30 10:56

Inter Portlet Communication (IPC) for Portlets on Different Page

Use the below code for Inter Portlet Communication (IPC) for Portlets on Different Page:-

String plidName = "Sample_WAR_Sampleportlet";
long plidForward = getPortletId(plidName);
PortletURL url = new PortletURLImpl(request,plidName, plidForward, PortletRequest.ACTION_PHASE);

---------------------------------------------------------------------------------

public static long getPortletId(String portletId) {

PortletPreferences prfs = null;
try {
DetachedCriteria dCriteria = DetachedCriteria
.forClass(PortletPreferences.class);
dCriteria.add(Restrictions.eq("portletId", portletId));
DynamicQuery dynamicQuery = new DynamicQueryImpl(dCriteria);

List list = PortletPreferencesLocalServiceUtil.dynamicQuery(dynamicQuery);

if (!list.isEmpty()) {
prfs = (PortletPreferences) list.get(0);
}

} catch (Exception e) {
e.printStackTrace();
}
return prfs.getPlid();
}

 

---------------------------------------------------------------------------------------------------

还可以这样写

---------------------------------------------------------------------------------------------------

public static long getPortletId(String portletId) {

        PortletPreferences list = null;
        try {   
            List<com.liferay.portal.model.PortletPreferences> temp = PortletPreferencesLocalServiceUtil.getPortletPreferences();
            for (int i = 0; i < temp.size(); i++) {
                if ((temp.get(i)).getPortletId().equals(portletId)) {
                    return temp.get(i).getPlid();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

 

long plid = TestClass.getPortletId("Sample_WAR_Sampleportlet");
LiferayPortletURL url  = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(renderRequest), "Sample_WAR_Sampleportlet", plid, PortletRequest.RENDER_PHASE);