留言板

Custom User creation page

thumbnail
Shravan Babu,修改在12 年前。

Custom User creation page

New Member 帖子: 16 加入日期: 11-11-17 最近的帖子
Hi,

I need to create a custom user creation page with extra fields like user type. I tried implementing it through a hook.
The custom jsp loads and the extra fields are displayed on the create_account.jsp.
But the fields are not being updated in the tables.

Below code is from my jsp:

<aui:input model="<%= UserType.class %>" name="type">
<aui:validator name="required" />
</aui:input>

Code from my ExtUserLocalService.java

UserTypeLocalServiceImpl uType = new UserTypeLocalServiceImpl();
String type = ParamUtil.getString(serviceContext, "type");
uType.addType(creatorUserId, type);

Liferay-hook.xml

<hook>
<custom-jsp-dir>/META-INF/custom_jsps</custom-jsp-dir>
<service>
<service-type>
com.liferay.portal.service.UserLocalService
</service-type>
<service-impl>com.userext.ExtUserLocalService</service-impl>
</service>
</hook>

Code from my UserTypeLocalServiceImpl.java:

public UserType addType(long userId,String type) throws SystemException, PortalException{

UserType uType = userTypePersistence.create(userId);
uType.setType(type);
return userTypePersistence.update(uType, false);
}

Please help.

Regards,
Shravan
thumbnail
jelmer kuperus,修改在12 年前。

RE: Custom User creation page

Liferay Legend 帖子: 1191 加入日期: 10-3-10 最近的帖子
Which method are you overriding in your service wrapper? You'll need to extend the addUser method that has a ton of arguments. Eg in lr 6.0.6 it's

    public User addUser(long companyId, boolean autoPassword, String password1, String password2, boolean autoScreenName,
                        String screenName, String emailAddress, long facebookId, String openId, Locale locale,
                        String firstName, String middleName, String lastName, int prefixId, int suffixId, boolean male,
                        int birthdayMonth, int birthdayDay, int birthdayYear, String jobTitle, long[] groupIds,
                        long[] organizationIds, long[] roleIds, long[] userGroupIds, boolean sendEmail,
                        ServiceContext serviceContext) throws PortalException, SystemException {
thumbnail
Shravan Babu,修改在12 年前。

RE: Custom User creation page

New Member 帖子: 16 加入日期: 11-11-17 最近的帖子
Hi jelmer,

Thanks for your reply.
I'm using Liferay 6.1.

My Code


package com.userext;

import java.util.Locale;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.model.User;
import com.liferay.portal.model.UserGroup;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.UserGroupLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceWrapper;
import com.liferay.portal.service.UserLocalService;
import com.myschool.userext.login.service.base.UserTypeLocalServiceBaseImpl;
import com.myschool.userext.login.service.impl.UserTypeLocalServiceImpl;

public class ExtUserLocalService extends UserLocalServiceWrapper {
/* (non-Java-doc)
* @see com.liferay.portal.service.UserLocalServiceWrapper#UserLocalServiceWrapper(UserLocalService userLocalService)
*/

private static final Log log = LogFactoryUtil.getLog(ExtUserLocalService.class);
public ExtUserLocalService(UserLocalService userLocalService) {
super(userLocalService);
}

@Override
public User addUser(long creatorUserId, long companyId,
boolean autoPassword, String password1, String password2,
boolean autoScreenName, String screenName, String emailAddress,
long facebookId, String openId, Locale locale, String firstName,
String middleName, String lastName, int prefixId, int suffixId,
boolean male, int birthdayMonth, int birthdayDay, int birthdayYear,
String jobTitle, long[] groupIds, long[] organizationIds,
long[] roleIds, long[] userGroupIds, boolean sendEmail,
ServiceContext serviceContext) throws PortalException,
SystemException {
// TODO Auto-generated method stub
// write your logic here to store your custom field into database //

UserTypeLocalServiceImpl uType = new UserTypeLocalServiceImpl();
String type = ParamUtil.getString(serviceContext, "type");
uType.addType(creatorUserId, type);

return super.addUser(creatorUserId, companyId, autoPassword, password1,
password2, autoScreenName, screenName, emailAddress, facebookId,
openId, locale, firstName, middleName, lastName, prefixId, suffixId,
male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds,
organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);
}

Is this correct?

Regards,
Shravan
}
thumbnail
jelmer kuperus,修改在12 年前。

RE: Custom User creation page

Liferay Legend 帖子: 1191 加入日期: 10-3-10 最近的帖子
Instead of

UserTypeLocalServiceImpl uType = new UserTypeLocalServiceImpl();
String type = ParamUtil.getString(serviceContext, "type");
uType.addType(creatorUserId, type);


do

String type = ParamUtil.getString(serviceContext, "type");
UserTypeLocalServiceUtil.addType(creatorUserId, type);
thumbnail
Shravan Babu,修改在12 年前。

RE: Custom User creation page

New Member 帖子: 16 加入日期: 11-11-17 最近的帖子
Hi Jelmer,

I made the changes as you said.
But it didn't work. What else could be wrong?

Regards,
Shravan
thumbnail
jelmer kuperus,修改在12 年前。

RE: Custom User creation page

Liferay Legend 帖子: 1191 加入日期: 10-3-10 最近的帖子
Upon further inspection, you are passing the creatorUserId to the addType method. The creatorUserId is not the id of the newly created user which you probably would want to use. instead call super then take the userId of the user object that is returned.

If it still does not work

1. Are there any errors in the log ?
2. Make sure your method is actually called by setting a breakpoint on it or doing some System.out.println 's
thumbnail
Shravan Babu,修改在12 年前。

RE: Custom User creation page

New Member 帖子: 16 加入日期: 11-11-17 最近的帖子
Hi Jelmer,

Now i'm passing the usedId of the user object returned.

But there is a problem. I think my service class is not being loaded.
The info logs in the service class is not being generated nor the print statments.

My liferay-hook.xml :

<hook>
<custom-jsp-dir>/custom_jsps</custom-jsp-dir>
<service>
<service-type>
com.liferay.portal.service.UserLocalService
</service-type>
<service-impl>com.userext.ExtUserLocalService</service-impl>
</service>
</hook>

My ExtUserLocalService.java


package com.userext;

import java.util.Locale;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.model.User;
import com.liferay.portal.model.UserGroup;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.UserGroupLocalServiceUtil;
import com.liferay.portal.service.UserLocalService;
import com.liferay.portal.service.UserLocalServiceWrapper;
import com.myschool.userext.login.service.UserTypeLocalServiceUtil;

public class ExtUserLocalService extends UserLocalServiceWrapper {
/* (non-Java-doc)
* @see com.liferay.portal.service.UserLocalServiceWrapper#UserLocalServiceWrapper(UserLocalService userLocalService)
*/

private static final Log log = LogFactoryUtil.getLog(ExtUserLocalService.class);
public ExtUserLocalService(UserLocalService userLocalService) {
super(userLocalService);
}

@Override
public User addUser(long creatorUserId, long companyId,
boolean autoPassword, String password1, String password2,
boolean autoScreenName, String screenName, String emailAddress,
long facebookId, String openId, Locale locale, String firstName,
String middleName, String lastName, int prefixId, int suffixId,
boolean male, int birthdayMonth, int birthdayDay, int birthdayYear,
String jobTitle, long[] groupIds, long[] organizationIds,
long[] roleIds, long[] userGroupIds, boolean sendEmail,
ServiceContext serviceContext) throws PortalException,
SystemException {
// TODO Auto-generated method stub
// write your logic here to store your custom field into database //

User user = super.addUser(creatorUserId, companyId, autoPassword, password1,
password2, autoScreenName, screenName, emailAddress, facebookId,
openId, locale, firstName, middleName, lastName, prefixId, suffixId,
male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds,
organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);

String type = ParamUtil.getString(serviceContext, "type");
UserTypeLocalServiceUtil.addType(user.getUserId(), type);
log.info("In ExtUserLocalService creatorUserId-"+user.getUserId()+"Type-"+type);



return user;
}


}

Regards,
Shravan
thumbnail
jelmer kuperus,修改在12 年前。

RE: Custom User creation page

Liferay Legend 帖子: 1191 加入日期: 10-3-10 最近的帖子
Are there any errors in the log if you hotdeploy the hook ?
thumbnail
Shravan Babu,修改在12 年前。

RE: Custom User creation page

New Member 帖子: 16 加入日期: 11-11-17 最近的帖子
Hi Jelmer,

I'm not getting any error while hot deploying the hook.
Not able to figure out what the problem is ... emoticon

Regards,
Shravan