Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
A. Ki
Add address to new user programaticaly
24. April 2010 14:14
Antwort

A. Ki

Rang: New Member

Nachrichten: 22

Eintrittsdatum: 19. Dezember 2007

Neue Beiträge

hey guys,
I need your help, because I´ve got some problems to add address and other information to new user. I need to add a new user, than add a postal adress, a web adresse or contact information for this user and at least deactivate him. All things works, but if I use the enterprise admin portet, I see this user, his deactivated but he´s got no address information - in the database I see this information.

what´s the right way to add an adress to a new user.

I add a new user in this way:

User newUser = UserLocalServiceUtil.addUser(....);
AddressLocalServiceUtil.addAddress(newUser.getId(), ....);
PhoneLocalServiceUtil.addPhone(newUser.getId(), ...);
...

at least
UserLocalServiceUtil.updateActive(newUser.getId(), false);

For the addAdress or Phone Service I used com.liferay.portal.model.Contact (information form the entries in the database) as className and 0 for classPK (-> what is the classPK ???)

Please help emoticon
Cheers,
Aki
lalit mohan
RE: Add address to new user programaticaly
25. April 2010 04:11
Antwort

lalit mohan

Rang: Junior Member

Nachrichten: 55

Eintrittsdatum: 2. Februar 2010

Neue Beiträge

Hi,

className is a reference to a database table and the classPK is the primary key reference in that table.

see here

So Valid className and classPk for Phone and Address.


PhoneLocalServiceUtil.addPhone(userId, className, classPK, number, extension, typeId, primary)
className: Contact.class.getName()
classPk user.getContactId() [contactId of user]




AddressLocalServiceUtil.addAddress(userId, className, classPK, street1, street2, street3, city, zip, regionId, countryId, typeId, mailing, primary)

className: Address.class.getName()
classPk: PortalUtil.getClassNameId(Address.class.getName())


Cheers,
Lalit
A. Ki
RE: Add address to new user programaticaly
25. April 2010 06:17
Antwort

A. Ki

Rang: New Member

Nachrichten: 22

Eintrittsdatum: 19. Dezember 2007

Neue Beiträge

Thanks Lalit for the quick response!

Now it works for me, but to add an address I must use Contact as class name. As I choose address, the adress still doesn´t be displayed.

Cheers,
Aki
lalit mohan
RE: Add address to new user programaticaly
25. April 2010 06:39
Antwort

lalit mohan

Rang: Junior Member

Nachrichten: 55

Eintrittsdatum: 2. Februar 2010

Neue Beiträge

Hi,

yes for address also you need to use Contact as className.

AddressLocalServiceUtil.addAddress(.....)

className: Contact.class.getName()
classPk: user.getContactId()



and for getting addresses for a user you can use.

AddressServiceUtil.getAddresses(Contact.class.getName(), user.getContactId());



Thanks,
Lalit
Raúl S
RE: Add address to new user programaticaly
25. August 2010 05:32
Antwort

Raúl S

Rang: New Member

Nachrichten: 3

Eintrittsdatum: 9. Juli 2010

Neue Beiträge

Works fine!!

Thanks a lot Lalit
Felipe Sere
RE: Add address to new user programaticaly
4. Dezember 2010 09:12
Antwort

Felipe Sere

Rang: Junior Member

Nachrichten: 87

Eintrittsdatum: 27. Januar 2010

Neue Beiträge

I am having this same problem. I call addAddress(.....) like this:
Address ad = AddressLocalServiceUtil.addAddress(u.getUserId(), Contact.class.getName(), u.getContactId(), ...);

This results in a NoSuchListTypeException.

What I am doing wrong here?

Felipe
Puj Z
RE: Add address to new user programaticaly
4. Dezember 2010 10:10
Antwort

Puj Z

Rang: Regular Member

Nachrichten: 219

Eintrittsdatum: 14. Januar 2010

Neue Beiträge

I'm having the same problem. It's driving me crazy....
Rex Petersen
RE: Add address to new user programaticaly
20. September 2011 08:45
Antwort

Rex Petersen

Rang: New Member

Nachrichten: 11

Eintrittsdatum: 10. März 2011

Neue Beiträge

Did you find an answer for this?
Roy Brondgeest
RE: Add address to new user programaticaly
31. Oktober 2011 07:45
Antwort

Roy Brondgeest

Rang: Junior Member

Nachrichten: 25

Eintrittsdatum: 13. Januar 2011

Neue Beiträge

Same problem here, please post your solution!
Roy Brondgeest
RE: Add address to new user programaticaly
31. Oktober 2011 08:58
Antwort

Roy Brondgeest

Rang: Junior Member

Nachrichten: 25

Eintrittsdatum: 13. Januar 2011

Neue Beiträge

I found an answer to this problem:
NoSuchListTypeException is caused by the unfound typeId that you have probably specified.

If you look at the contents of the Select Box address type in My Account -> Addresses you will find it has id 11000,

Setting typeId to 11000 or any other existing address type id should fix the problem.
Same goes for other attributes that users may carry such as phones, websites, add. email addresses.
Do watch out for different type ids that are available for each of these entities.

AddressLocalServiceUtil.addAddress(u.getPrimaryKey(), Contact.class.getName(), u.getContactId(), adres, "", "", plaats, postcode, 0, 0, 11000, false, true);


Good luck emoticon
Jesús Salinas
RE: Add address to new user programaticaly
9. Februar 2012 07:40
Antwort

Jesús Salinas

Rang: New Member

Nachrichten: 15

Eintrittsdatum: 1. Februar 2010

Neue Beiträge

Hi,

The problem is you're not using correct Type. We have to work with "com.liferay.portal.model.Contact.emailAddress".
If we want to add a new email address to a user, we must do somethis like this:

 1
 2...
 3// Step 1: We have to get contact user.
 4Contact contact = user.getContact();
 5
 6// Step 2:     We have to get all different Contact Email Address types: com.liferay.portal.model.Contact.emailAddress
 7List<ListType> lista = ListTypeServiceUtil.getListTypes("com.liferay.portal.model.Contact.emailAddress");
 8
 9// Step 3: We're working with Contact entities.
10ClassName className = ClassNameLocalServiceUtil.getClassName("com.liferay.portal.model.Contact");
11
12// Step 4: We can choose one of them, for example, the first one.
13ListType type = lista.get(0);
14
15// Step 4: Use addEmailAddress to insert the new email address
16EmailAddressLocalServiceUtil.addEmailAddress(u.getUserId(),
17                    className.getClassName(),
18                    contact.getContactId(),
19                    email,
20                    type.getListTypeId(), false);


I hope it helps.
shankar saibabu
RE: Add address to new user programaticaly
9. März 2012 08:31
Antwort

shankar saibabu

Rang: New Member

Nachrichten: 1

Eintrittsdatum: 11. Oktober 2011

Neue Beiträge

Hi,
In liferay 6.0.5 ee, I am trying to add additional e-mail addresses for a user through the tunnel-web web services. When i send in the additional email via the .addUser method, user gets created but the email is associated with the Contact. This email doesn't show on the User's Additional email address screen. Is there some configuration that needs to happen in liferay?

Secondly, if i use the Portal_EmailAddressService to addEmailAddress, I can add it for class "com.liferay.portal.model.Contact" but get java.rmiexception error when specifying "com.liferay.portal.model.User" as a className.


Thanks