在Liferay Portal中自定义CreateAccountAction

时间:2015-05-16 09:53:59

标签: liferay liferay-ide liferay-hook

我正在尝试在创建用户时添加“用户组”选择字段(自我用户注册表单 - create_account.jsp)。 此处自定义字段没有用,因为db中已存在Usergroup。我想插入现有的Users_UserGroups表。 我正在使用下面的钩子: 但是,用户未添加到组中,并且不会打印任何例外。

请建议我采取任何其他方式来实现这一目标。

public class CustomCreateAccountAction extends BaseStrutsPortletAction
{ 
    public void processAction(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) 
                    throws Exception 
            { 
                System.out.println("My Custom Process Action Method is Called"); 

                String emailid=ParamUtil.getString(actionRequest, "emailAddress");
                long[] userGroupIds = null;

                originalStrutsPortletAction.processAction(originalStrutsPortletAction, portletConfig, actionRequest,actionResponse); 

                System.out.println("This is after user is registered");
                if (SessionErrors.isEmpty(actionRequest)) 
                {
                ThemeDisplay themeDisplay =(ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

                long newlyCreatedUserId=UserLocalServiceUtil.getUserIdByEmailAddress(themeDisplay.getCompanyId(), emailid);

                long userIds[]={newlyCreatedUserId};
                long dummygroupid=16206;

                System.out.println("TEST UserID="+newlyCreatedUserId);
                System.out.println("TEST GroupID="+dummygroupid);
                //Everything went well until here.
                UserServiceUtil.addUserGroupUsers(dummygroupid, userIds);
                //below sysout is not printed. and no exception or user in group db created. 
                System.out.println("user added to group");
                }

            } 


            public String render(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig, RenderRequest renderRequest, RenderResponse renderResponse) throws Exception 
            { 
                System.out.println("My Custom Render Method is Called"); 
                return originalStrutsPortletAction.render(null, portletConfig, renderRequest, renderResponse);   
                } 

        } 

了解更多信息,请查看this主题。

2 个答案:

答案 0 :(得分:1)

使用 UserLocalServiceUtil 代替 UserServiceUtil 工作。基本上,区别在于* ServiceUtil检查权限而* LocalServiceUtil没有。

答案 1 :(得分:0)

我不确定这是最好的主意,但你可以使用钩子来修改用户creacióngsp并通过模型监听器在用户创建/修改时保存值。

Regsrds