我怎样才能找到 - Liferay 6.1中哪些页面部署了哪些portlet?

时间:2014-10-03 18:55:18

标签: liferay

换句话说,我需要考虑哪些数据库表来将portlet映射到组织中的页面?如果有这样的事情?!我们正在使用Liferay 6.1.20

4 个答案:

答案 0 :(得分:4)

除了marketplace portlet

如果您有权访问数据库,则可以在Layout表上触发一个简单查询,以了解您的portlet添加的所有页面:

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

您还可以使用service-builder构建FinderImpl,以通过portlet执行此查询,并将该portlet添加到页面以便以您想要的任何格式显示。


下面是另一个没有部署任何portlet而无法访问数据库的解决方案(在MySQL DB上测试):

  1. 转到“服务器管理”
  2. 转到“脚本”标签
  3. 从语言下拉列表中选择Beanshell
  4. 将以下脚本代码粘贴到textarea中,然后按按钮执行:

    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. 请记得将字符串my_WAR_myportlet更改为您的portletId

  6. 毋庸置疑,您可以修改脚本以更新样式,并可以显示选择性列。您还可以运行任何SQL查询,只需更新String sqlQuery
  7. 希望这有帮助。

答案 1 :(得分:2)

这是一个解决方案,一个解决您问题的免费市场插件。

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

答案 2 :(得分:2)

这是从第一列获取所有portlet的代码

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
}

答案 3 :(得分:0)

[layout]是一个表,您可以在其中找到在哪个页面上部署了哪些portlet(typeSettings)