【问题标题】:categorizing layouts and menu links in liferay在 liferay 中对布局和菜单链接进行分类
【发布时间】:2011-11-14 09:42:19
【问题描述】:

我正在通过钩子安装布局

友好的网址如下

/cat1/link1, /cat1/link2

/cat2/link3, /cat2/link4

我希望当我导航到 cat1/link1 时

导航链接应该是link1和link2

当我导航到 cat2/link3 时

导航链接应该是link3和link4

我怎样才能做到这一点?

或者任何人都可以建议我如何在同一个 liferay 安装中将多个站点的布局分组到不同的类别中?

谢谢..

【问题讨论】:

  • 你使用内置导航portlet吗?
  • 不..我没有使用导航portlet..我是liferay的新手..你能告诉我这是做什么的吗?
  • “我正在通过挂钩安装布局”是什么意思?你是说控制面板吗? “当我导航到 cat1/link1 时,导航链接应该是 link1 和 link2”是什么意思?你能显示网址吗?
  • no not control panel.. 类似于 7 cogs hook.. 我们部署了一个 hook,它将在 liferay 启动期间安装组织和相关的布局.. 假设我的组织是 org1 .. 所以我的友好url 是 org1/dashboard (eg) .. 所以我想显示与 org1 相关的菜单链接 .. 同样我想创建 org2 并在其下安装布局并相应地显示菜单链接.. 我的意思是说如何创建多个liferay 中的组织.. 抱歉我的问题中的数据不足.. 谢谢

标签: menu navigation liferay


【解决方案1】:

创建组织(来自七齿轮StartupAction.java

long userId = defaultUserId;
long parentOrganizationId = OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID;

String name = "7Cogs, Inc.";
String type = OrganizationConstants.TYPE_REGULAR_ORGANIZATION;

boolean recursable = true;
long regionId = 0;
long countryId = 0;
int statusId = GetterUtil.getInteger(PropsUtil.get("sql.data.com.liferay.portal.model.ListType.organization.status"));
String comments = null;

ServiceContext serviceContext = new ServiceContext();

serviceContext.setAddCommunityPermissions(true);
serviceContext.setAddGuestPermissions(true);

Organization organization =
        OrganizationLocalServiceUtil.addOrganization(
        userId, parentOrganizationId, name, type, recursable, regionId,
        countryId, statusId, comments, serviceContext);

Group group = organization.getGroup();
GroupLocalServiceUtil.updateFriendlyURL(group.getGroupId(), "/7cogs");

您确定需要两个组织而不是两个社区吗?

更新评论中的问题:

要在主题(速度)中获取组织名称,您可以使用(如果您在组织的页面(组)中)

在portal-ext.properties中

journal.template.velocity.restricted.variables=

在主题 vm 文件中

Liferay 6

#set($os = $serviceLocator.findService("com.liferay.portal.service.OrganizationLocalService"))
#set($organization = $os.getOrganization($themeDisplay.getScopeGroup().getOrganizationId()))
$organization.getName()

Liferay 5.x

#set($os = $serviceLocator.findService("com.liferay.portal.service.OrganizationLocalServiceUtil"))
#set($organization = $os.getOrganization($themeDisplay.getScopeGroup().getOrganizationId()))
$organization.getName()

编辑:

如果您的用户是组织的成员,则您可以使用

#foreach($org in $themeDisplay.getUser().getOrganizations())
    $org.getName()<br>
#end

请注意,用户可以是多个组织的成员,您将获得所有这些组织。

【讨论】:

  • 是的 .. 我认为我需要 2 个不同的组织 .. 像 7 个 cogs .. 一个域与其他域完全不同
  • $organization.getName() 按原样打印.. 它不打印组织名称.. 我还需要做什么?
  • 如果按原样打印而不是您不在组织页面中,您可能在访客社区中。尝试去yourserver:port/web/organization_friendly_url。您还必须将主题设置为用于组织页面。让我知道发生了什么,如果它不起作用,我们会尝试其他方法
  • 它不在访客页面中.. url 就像 /user/admin/org_name/dashboard ...我将您提供的代码块放在 navigation.vm.. 我打印了 $themeDisplay.getScopeGroup ().getOrganizationId() .. 它打印 0。
  • 您在用户(管理员用户)页面而不是组织中,因此它无法工作。如果您确实需要用户页面中的组织名称,我会寻找解决方案。
【解决方案2】:

关于代码你需要知道的:

在 Martin 提到的同一个课程中,我已经组合了可以满足您需要的代码。

请注意,有些变量没有定义。您必须使用特定于 Liferay 安装的正确值。例如,userId 可以是任何人,但我建议使用默认用户的 userId 或管理员的 userId。

代码:

Organization organization =
    OrganizationLocalServiceUtil.addOrganization(
        userId, OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID,
        "My Org 1", OrganizationConstants.TYPE_REGULAR_ORGANIZATION, true,
        regionId, countryId, statusId, comments, true, serviceContext);

Group group = organization.getGroup();

GroupLocalServiceUtil.updateFriendlyURL(group.getGroupId(), "/cat1");

LayoutLocalServiceUtil.addLayout(
    group.getCreatorUserId(), group.getGroupId(), "false",
    LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "My Link 1", StringPool.BLANK,
    StringPool.BLANK, LayoutConstants.TYPE_PORTLET, false, "/link1",
    false, serviceContext);

LayoutLocalServiceUtil.addLayout(
    group.getCreatorUserId(), group.getGroupId(), "false",
    LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "My Link 2", StringPool.BLANK,
    StringPool.BLANK, LayoutConstants.TYPE_PORTLET, false, "/link2",
    false, serviceContext);

organization =
    OrganizationLocalServiceUtil.addOrganization(
        userId, parentOrganizationId, name, type, recursable, regionId,
        countryId, statusId, comments, true, serviceContext);

group = organization.getGroup();

GroupLocalServiceUtil.updateFriendlyURL(group.getGroupId(), "/cat2");

LayoutLocalServiceUtil.addLayout(
    group.getCreatorUserId(), group.getGroupId(), "false",
    LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "My Link 3", StringPool.BLANK,
    StringPool.BLANK, LayoutConstants.TYPE_PORTLET, false, "/link3",
    false, serviceContext);

LayoutLocalServiceUtil.addLayout(
    group.getCreatorUserId(), group.getGroupId(), "false",
    LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "My Link 4", StringPool.BLANK,
    StringPool.BLANK, LayoutConstants.TYPE_PORTLET, false, "/link4",
    false, serviceContext);

【讨论】:

  • 假设用户是否属于两个组织.. 他看到两个组织的链接.. 我想对友好的 url 进行分类
  • 让我说清楚 .. 对于每个用户,我们正在添加私有布局 .. 正如你所说,我在 org1 和 org2 中添加了一些布局,并为每个用户添加了相同的布局,以便用户拥有访问这两个组织.. 一旦我去 org1/link1 .. 我看到所有链接 org1+org2.. 我需要它根据友好的 url 决定.. 有什么想法吗??
  • 是否可以在主题速度模板中获取组织名称
猜你喜欢
  • 2014-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-30
  • 2010-10-31
  • 1970-01-01
相关资源
最近更新 更多