2011-12-06 16 views

risposta

5

per l'esempio completo presumo che si voglia aggiungere il portlet nidificato alla pagina corrente utilizzando un altro gestore di azioni portlet. (Se usato da rendere l'azione non vedrebbe portlet nidificato fino al prossimo visualizzazione della pagina)

Aggiungi questi metodi al codice

private static String addPortlet(final long p_userId, final Layout p_layout, final String p_portletId, final String p_columnId, final int p_position, final boolean p_checkPermission) 
       throws PortalException, SystemException 
{ 
    if (p_layout.isTypePortlet()) { 
     final LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) p_layout.getLayoutType(); 

     final String portletId = layoutTypePortlet.addPortletId(p_userId, p_portletId, p_columnId, p_position, p_checkPermission); 
     if (portletId != null) { 
      final String rootPortletId = PortletConstants.getRootPortletId(portletId); 
      final String portletPrimaryKey = PortletPermissionUtil.getPrimaryKey(p_layout.getPlid(), portletId); 
      ResourceLocalServiceUtil.addResources(p_layout.getCompanyId(), p_layout.getGroupId(), 0, rootPortletId, portletPrimaryKey, true, true, true); 
      LayoutLocalServiceUtil.updateLayout(p_layout.getGroupId(), p_layout.isPrivateLayout(), p_layout.getLayoutId(), p_layout.getTypeSettings()); 
     } 
     return portletId; 
    } 

    return null; 
} 

private static void addNestedPortlet(final PortletRequest p_request) throws PortalException, SystemException { 
    final ThemeDisplay themeDisplay = (ThemeDisplay) p_request.getAttribute(WebKeys.THEME_DISPLAY); 
    final Layout layout = themeDisplay.getLayout(); 
    long userId = themeDisplay.getUserId(); 

    //create nested portlet and add it to "column-1" 
    final String nestedPortletId = addPortlet(userId, layout, "118", "column-1", -1, false); 

    //this will be used to target nested portlet's columns 
    final String nestedColumnPrefix = "_" + nestedPortletId + "__"; 

    //default page layout (used by nested portlet) has two columns 
    //we'll add two portlets (in this example two iframe portlets), one portlet to each column 
    addPortlet(userId, layout, "48", nestedColumnPrefix + "column-1", -1, false); 
    addPortlet(userId, layout, "48", nestedColumnPrefix + "column-2", -1, false); 
} 


Se volete, e probabilmente si sarebbe, da aggiungere portlet nidificato su un'altra pagina o non dal portlet, è possibile cercare Layout e Utente invece di recuperarli da ThemeDisplay.

Problemi correlati