掲示板
Increment user id
Hi there.
Is this the correct way to get hold of a new user id?
Appreciate any feedback!
Is this the correct way to get hold of a new user id?
Long newClientId = CounterLocalServiceUtil.increment(User.class.getName());
Appreciate any feedback!
11年前 に David H Nebinger によって更新されました。
RE: Increment user id
Liferay Legend 投稿: 14914 参加年月日: 06/09/02 最新の投稿
yup
11年前 に Hitoshi Ozawa によって更新されました。
RE: Increment user id
Liferay Legend 投稿: 7942 参加年月日: 10/03/24 最新の投稿
Almost. It's "long" with small "l"
long newClientId = CounterLocalServiceUtil.increment(User.class.getName());
long newClientId = CounterLocalServiceUtil.increment(User.class.getName());
11年前 に Mika Koivisto によって更新されました。
RE: Increment user id
Liferay Legend 投稿: 1519 参加年月日: 06/08/07 最新の投稿
What ever you are doing don't do it!!! It's probably a bad idea. If you need to add a new user use
or
UserLocalServiceUtil.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);
or
UserLocalServiceUtil.addUserWithWorkflow(
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);
Mika Koivisto:
What ever you are doing don't do it!!! It's probably a bad idea. If you need to add a new user use
UserLocalServiceUtil.addUser(
That was my first take. But it didn't do the job. The method just exits with no logging at all. Here's the old code:
currentUser = PortalUtil.getUser(this.request);
serviceContext = ServiceContextFactory.getInstance(this.request);
serviceContext.setCompanyId(ActionUtil.getCompanyId(this.request));
...
Button saveButton = new Button("Create new client", new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event)
{
String title = (String)titleBox.getValue();
String firstName = (String)firstNameField.getValue();
String familyName = (String)familyNameField.getValue();
Date dateOfBirth = (Date)dateOfBirthField.getValue();
String gender = (String)genderBox.getValue();
String loginName = (String)loginNameField.getValue();
String emailAddress = (String)emailAddressField.getValue();
String clientNumber = (String)clientNumberField.getValue();
Long facebookId = 0L;
String openId = null;
Locale locale = Locale.ENGLISH;
String middleName = "";
boolean male = gender.equals(Literals.Gender.Male.getLabel());
int prefixId = 0;
int suffixId = 0;
int birthdayMonth = dateOfBirth.getMonth();
int birthdayDay = dateOfBirth.getDay();
int birthdayYear = dateOfBirth.getYear();
String jobTitle = "";
long[] organizationIds = new long[] { chamberId };
long[] groupIds = new long[] { 0L };
long[] roleIds = new long[] { 0L };
long[] userGroupIds = new long[] { 0L };
boolean autoPassword = false;
boolean autoScreenName = false;
boolean sendEmail = false;
String password = "test";
User newClient = null;
try
{
Long creatorUserId = currentUser.getUserId();
Long companyId = currentUser.getCompanyId();
newClient = UserLocalServiceUtil.addUser(creatorUserId, companyId, autoPassword, password,
password, autoScreenName, loginName, emailAddress, facebookId, openId, locale, firstName,
middleName, familyName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear,
jobTitle, groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);
window.getParent().removeWindow(window);
}
So I decided to build up a "User" myself, create a new Id and "update" it. At least that indeed creates a new user. But the created Id smelled strange, hence my question..
EDIT:
Just replaced
String openId = null;
by
String openId = "";
and that original code (with .addUser(...)) works! Many thanks (to all of you)!
11年前 に David H Nebinger によって更新されました。
RE: Increment user id
Liferay Legend 投稿: 14914 参加年月日: 06/09/02 最新の投稿Ay Kay:
Just replaced
String openId = null;
by
String openId = "";
and that original code (with .addUser(...)) works! Many thanks (to all of you)!
That's a little known thing about the addUser() method. It should have thrown an NPE which, when combined w/ looking at the Liferay source, would have pointed out that the openId cannot be null.