0

我正在尝试使用类GroupLocalServiceUtil的addGroup方法在 Liferay 中创建一个新组。我根据文档传递参数类型,但是它会莫名其妙地抛出一个。这是我的纯代码:IllegalArgumentException

ServiceContext sc = new ServiceContext();
sc.setScopeGroupId(10);
GroupLocalServiceUtil.addGroup(11101, "com.liferay.portal.model.Group", 0, 0, "aaa","foo", description, 
            10, null, true, true, sc);

怎么了?我可以将 ServiceContext 参数设置为 null 吗?

更新:我使用的版本是 6.1。异常的堆栈跟踪是:

Caused by: java.lang.IllegalStateException: Something went wrong: 
at com.pro.liferay.startUpHook.ReadGroupFromCsv.addData(ReadGroupFromCsv.java:69)
at com.pro.liferay.startUpHook.CreateUserOnStartUp.run(CreateUserOnStartUp.java:27)
at com.liferay.portal.kernel.events.InvokerSimpleAction.run(InvokerSimpleAction.java:42)
at com.liferay.portal.deploy.hot.HookHotDeployListener.initEvent(HookHotDeployListener.java:1177)
at com.liferay.portal.deploy.hot.HookHotDeployListener.initEvents(HookHotDeployListener.java:1239)
at com.liferay.portal.deploy.hot.HookHotDeployListener.initPortalProperties(HookHotDeployListener.java:1595)
at com.liferay.portal.deploy.hot.HookHotDeployListener.doInvokeDeploy(HookHotDeployListener.java:563)
at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:273)
... 23 more
Caused by: java.lang.IllegalArgumentException
at com.liferay.portal.service.impl.GroupLocalServiceImpl.addGroup(GroupLocalServiceImpl.java:276)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:122)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.security.pacl.PACLAdvice.invoke(PACLAdvice.java:51)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:211)
at $Proxy23.addGroup(Unknown Source)
at com.liferay.portal.service.GroupLocalServiceUtil.addGroup(GroupLocalServiceUtil.java:300)
at com.pro.liferay.startUpHook.customutils.GroupUtil.addGroup(GroupUtil.java:63)
at com.pro.liferay.startUpHook.customutils.GroupUtil.addGroup(GroupUtil.java:69)
at com.pro.liferay.startUpHook.ReadGroupFromCsv.addData(ReadGroupFromCsv.java:67)
... 30 more
4

2 回答 2

1

我正在使用Liferay 6.1.1,在第 276 行GroupLocalServiceImpl.addGroup可以看到:

if (className.equals(Group.class.getName())) {
    if (!site && (liveGroupId == 0)) {
        throw new IllegalArgumentException(); // this is line 276
    }
}

所以你必须设置site=falseliveGroupId=0

无论如何,我曾经使用这段代码来创建网站(我重复一遍,Liferay 6.1.1),据我所知,它工作得非常好;)

GroupLocalServiceUtil.addGroup(userId, Group.class.getName(), 0, "title","description",GroupConstants.TYPE_SITE_OPEN, "/siteFriendlyUrl", true, true, new ServiceContext());
于 2013-03-15T13:02:13.807 回答
0
  • 你确定url可以为空吗?
  • 你能用 Group.class.getName() 替换类名吗?
于 2013-03-14T13:12:09.487 回答