在Liferay中创建组的IllegalArgumentException

时间:2013-03-14 12:52:21

标签: java liferay liferay-6 illegalstateexception illegalargumentexception

我正在尝试使用类addGroup的方法GroupLocalServiceUtil在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。 Exception的堆栈跟踪是:

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

2 个答案:

答案 0 :(得分: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());

答案 1 :(得分:0)

  • 您确定url可以为空吗?
  • 你能用Group.class.getName()吗?
  • 替换类名