0

テーマに埋め込まれたポートレットがあります。テーマがポートレットからパラメータ値を取得できる唯一の解決策は、中間データベースを使用することです。私がしたことは、ポートレットにテーブルを作成してから、テーマからこのテーブルにアクセスしようとしたことです。

ポートレットの Java コード:

ExpandoTable table=null;
        try {
            table = ExpandoTableLocalServiceUtil.addTable(CompanyLocalServiceUtil.getCompanies().get(0).getCompanyId(), User.class.getName(), "ClientTab");
        }
        catch (  DuplicateTableNameException dtne) {
            table=ExpandoTableLocalServiceUtil.getTable(CompanyLocalServiceUtil.getCompanies().get(0).getCompanyId(), User.class.getName(), "ClientTab");
        }

テーマの速度コード:

#set ($accountsTableName = "ClientTab")

#set ($accountsTable = $expandoTableLocalService.getTable($accountsTableName, $accountsTableName))

#if (!$accountsTable)
 <h2> The table ClientTab doesn't exist </h2>
#else
 <h2> Well The table ClientTab exists </h2>
#end

しかし、私が得た結果は次のとおりです。

テーブル ClientTab が存在しません

これらの参照を使用してコードを開発しました。

http://myjavaexp.blogspot.com/2013/01/liferay-expando-services.html

http://www.programcreek.com/java-api-examples/index.php?api=com.liferay.portlet.expando.DuplicateColumnNameException

http://www.liferay.com/fr/web/raymond.auge/blog/-/blogs/715049

4

1 に答える 1

0

ポートレットからテーマに値を渡すだけの場合は、次のように、render メソッドに新しい Velocity 変数を追加できます。

HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(request);
Map<String, Object> velocityVariables = (Map<String, Object>)httpRequest.getAttribute(WebKeys.VM_VARIABLES);
if(velocityVariables == null) {
    velocityVariables = new HashMap<String, Object>();
}

velocityVariables.put("mySpecialKey", "mySpecialValue");
request.setAttribute(WebKeys.VM_VARIABLES, velocityVariables);

次に、次のようにテーマで変数を使用できます。

<h1>Here's the value added by my portlet --> $mySpecialKey</h1>

$変数の先頭の文字を忘れないでください。

于 2015-01-08T20:00:41.520 に答える