0

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

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 
+0

因为你有例外:它在哪里抛出 - 你在那个地方检查过Liferay的源代码吗?如果您检查该位置,可能很明显是什么导致此异常。至少给出栈跟踪和你使用的版本 – 2013-03-14 19:53:30

+0

@OlafKock:看看我的更新 – arjacsoh 2013-03-15 08:57:17

回答

1

我使用的Liferay 6.1.1,并在GroupLocalServiceImpl.addGroup寻找线276,我可以看到这一点:

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()); 
0
  • 你肯定url可以为空?
  • 你能用Group.class.getName()替换类名吗?
+0

根据文档friendlyUrl可以是可选的null。我按照上面的建议改变了班级名称,但没有任何效果。仍然是一个例外。 – arjacsoh 2013-03-14 13:15:03