How can i find - which portlets are deployed on which pages in Liferay 6.1?

随声附和 提交于 2019-12-04 04:41:57

问题


In other words, Which Database tables do i need to look into for the mapping of a portlet to a page in an organization? If there is such a thing?! We are using Liferay 6.1.20


回答1:


Apart from the marketplace portlet.

If you have access to the Database you can fire a simple query on the Layout table to know in what all pages your portlet is added:

SELECT * FROM Layout WHERE typeSettings LIKE '%my_WAR_myportlet%';

Also you can build a FinderImpl with service-builder to execute this query through a portlet and add that portlet to page to display in whatever format you want.


Below is another solution without deploying any portlet and without having access to the DB (tested on MySQL DB):

  1. Go to Server Administration
  2. Go to Script tab
  3. Select Beanshell from the Language drop-down
  4. Paste the following script code in the textarea and press the button execute:

    import com.liferay.portal.kernel.dao.jdbc.DataAccess;
    import com.liferay.portal.kernel.log.Log;
    import com.liferay.portal.kernel.log.LogFactoryUtil;
    import com.liferay.portal.kernel.util.StringBundler;
    
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
    
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Iterator;
    import java.util.List;
    
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    
    try {
        con = DataAccess.getUpgradeOptimizedConnection();
    
        // your custom query here
        String sqlQuery = "SELECT * FROM Layout WHERE typeSettings LIKE '%my_WAR_myportlet%'";
    
        out.println("SQL Query: "+ sqlQuery);
    
        ps = con.prepareStatement(sqlQuery);
    
        rs = ps.executeQuery();
    
        ResultSetMetaData rsmd = rs.getMetaData();
    
        int columnCount = rsmd.getColumnCount();
    
        List rows = new ArrayList();
    
        List columnLabels = new ArrayList();
    
        columnLabels.add("Sr. No.");
    
        for (int c = 1; c <= columnCount; c++) {
            String cl = rsmd.getColumnLabel(c);
            columnLabels.add(cl);
        }
    
        while (rs.next()) {
            List row = new ArrayList(columnCount);
    
            for (int c = 1; c <= columnCount; c++) {
                Object value = rs.getObject(c);
                row.add(value);
            }
    
            rows.add(row);
        }
    
        // --- formatting the results ---
    
        out.append("<div class=\"lfr-search-container \"><div class=\"results-grid\">");
        out.append("<table class=\"taglib-search-iterator\">");
        out.append("<thead>");
        out.append("<tr class=\"portlet-section-header results-header\">");
    
        for (String value : columnLabels) {
            out.append("<th>");
            out.append(value);
            out.append("</th>");
        }
    
        out.append("</tr>");
        out.append("</thead>");
        out.append("<tbody>");
    
        boolean alt = false;
    
        long resultsCount = 1;
    
        for (List line : rows) {
            out.append("<tr class=\"portlet-section-alternate results-row " + (alt ? "alt" : "") + "\">");
    
            // for sr. no.
            out.append("<td>");
            out.append(resultsCount + "");
            out.append("</td>");
    
            resultsCount = resultsCount + 1;
    
            for (Iterator iterator = line.iterator(); iterator.hasNext();) {
                Object value = (Object) iterator.next();
                out.append("<td>");
                if (value != null) {
                    out.append(value.toString());
                } else {
                    out.append("<span style=\"font-style:italic\">null</span>");
                }
                out.append("</td>");
            }
            out.append("</tr>");
            alt = !alt;
        }
    
        out.append("</tbody>");
    
        out.append("</table>");
        out.append("</div></div>");
    
    } catch (Exception exp) {
        out.println("ERROR: " + exp);
        throw exp;
    }
    finally {
        DataAccess.cleanUp(con, ps, rs);
    }
    
  5. Please remember to change the string my_WAR_myportlet to your portletId

  6. Needless to say you can modify the script to update the styles and can show selective columns. Also you can run any SQL query, just update String sqlQuery.

Hope this helps.




回答2:


This is the solution, a free marketplace plugin that resolve your issue.

http://www.liferay.com/it/marketplace/-/mp/application/27156990




回答3:


Here is a code to get all the portlets from the first column

ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
Layout layout = themeDisplay.getLayout();
LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();
List<Portlet> portlets = layoutTypePortlet.getAllPortlets("column-1");
for (Portlet portlet : portlets) {
    // print your portlet.getPortletId() or do whatever you need
}



回答4:


[layout] is the table in which you can find out which portlets(typeSettings ) are deployed on which page



来源:https://stackoverflow.com/questions/26185039/how-can-i-find-which-portlets-are-deployed-on-which-pages-in-liferay-6-1

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