问题描述:

I want to add a form into my application for generating rules considering the attributes of Liferay Users.

Do you know a function for getting a list of this attributes? (List of parameter names)

Example:

1. Address,

2. FullName,

3. AccountId,

4. Create Date,

5. Employee Numbre,

6. And so on.....

Do you know a function for getting the type of each parameter? (Due to check type errors)

Example:

1. Address -> String

2. FullName -> String

Thank you,

Oriol

网友答案:

AFAIK, there is not such a method. But even if it existed, it would not provide all the info you're going for, because some of it, is not an attribute of the User Class, or the corresponding 'user_' table in the LF database.

If you understand how ServiceBuilder Model works, you'll see that there's a complex Model running under the hood, and it's not working like attributes.

For example, there is no 'user.getAddress()'., Because, Address is a Complex Class, subclassing Contact, and keeps a FK to the User. If you want one of his addresses, You can only get all his addresses (User.getAddresses()), and iterate through them, check by ContantactType and e.g. get his "business address". Respectfully, you can't call 'user.setAddress(String)', not even a "user.addAddress(Address)". A working code would look much more like :

             //update an existing Address
                existingAddr.setStreet1(street);
                existingAddr.setZip(zip);
                existingAddr.setCity(city);
                AddressLocalServiceUtil.updateAddress(existingAddr);            

                    //then update the user, to store the changes.
        UserLocalServiceUtil.updateUser(user);

The same goes for the birthday, the Phones, websites and facebook urls etc

For the rest of the 'Attributes' (names and Types), you should look here

网友答案:

You can get a User object by calling:

User u = userService.getUserById(0);

or check liferay docs for UserService

then you can use getters like:

u.getAddresses();
u.getBirthday();
u.getFullName();
网友答案:

you can get it from:

User user = UserLocalServiceUtil.getUser(userId); 

user.getFullName(); user.getEmailAddress();

相关阅读:
Top