Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Kannan G krishnan
expando values to database
August 21, 2013 6:01 AM
Answer

Kannan G krishnan

Rank: Regular Member

Posts: 121

Join Date: April 30, 2013

Recent Posts

1   String jiraUserId = ParamUtil.getString(actionRequest, "jiraUserId");
2             user.getExpandoBridge().setAttribute("jiraUserId", jiraUserId, false);


I tried to set the expando values to the database like above. But the value is not added. Can Somebody tell me is this correct or is there any other way to set the values???
Thanks in advance....
Victor Zorin
RE: expando values to database
August 21, 2013 2:23 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1178

Join Date: April 14, 2008

Recent Posts

This method also did not work for us in some releases of Liferay, so without further investigation we switched over to:
com.liferay.portlet.expando.service.ExpandoValueLocalServiceUtil.addValue(...).
Make sure that all permissions for the specific expando attribute are set properly to allow modification.

Edited, added some sample code for setting user custom attributes:
 1String expandoAttributeName = "jiraUserId";
 2String expandoAttributeValue="your value";
 3ExpandoValueLocalServiceUtil.addValue(
 4  user.getCompanyId(),
 5  User.class.getName(),
 6  ExpandoTableConstants.DEFAULT_TABLE_NAME,
 7  expandoAttributeName,
 8  user.getUserId(),
 9  expandoAttributeValue);
Kannan G krishnan
RE: expando values to database
August 21, 2013 9:57 PM
Answer

Kannan G krishnan

Rank: Regular Member

Posts: 121

Join Date: April 30, 2013

Recent Posts

Hi Victor

i have a "MyUserLocalService" class where the addUser method get called and the values inserted to the table. Can i use this code in the same class or i want to create a new class?
Ahamed Hasan
RE: expando values to database
August 21, 2013 9:52 PM
Answer

Ahamed Hasan

Rank: Expert

Posts: 306

Join Date: April 13, 2007

Recent Posts

Dear Kannan,

If you can state your requirements quite clearly then i can help you in this regard. Actually if you want to add custom fields on the User, you need not have to do anything programmatically to persist this to database expando tables. Liferay takes care of this automatically. I have covered this aspect in chapter 12 of my free eBook on Liferay. You can refer there as well.

Yours truly,
Ahamed Hasan
Author of the most comprehensive guide, Liferay Portlet Cookbook.
Kannan G krishnan
RE: expando values to database
August 21, 2013 10:05 PM
Answer

Kannan G krishnan

Rank: Regular Member

Posts: 121

Join Date: April 30, 2013

Recent Posts

Hi Ahmed

Actually i am researching on this aspect that how to create the custom fields programmatically and how to insert the values to the expando table. Anyway i will use your eBook on liferay for the future references.

Thank You
regards
Kannan G krishnan
Ahamed Hasan
RE: expando values to database
August 21, 2013 10:09 PM
Answer

Ahamed Hasan

Rank: Expert

Posts: 306

Join Date: April 13, 2007

Recent Posts

If you want to programmatically create custom fields, you can refer to this hook that i have developed for one of our projects.

Yours truly,
Ahamed Hasan
Author of the most comprehensive guide, Liferay Portlet Cookbook.
Kannan G krishnan
RE: expando values to database
August 21, 2013 10:18 PM
Answer

Kannan G krishnan

Rank: Regular Member

Posts: 121

Join Date: April 30, 2013

Recent Posts

Hi Ahmed

I have created the the custom fields and table. Now i want to insert the custom field value to the table. Can you help me with that?

regards
Kannan G krishnan
Pankaj Kathiriya
RE: expando values to database
August 21, 2013 10:49 PM
Answer

Pankaj Kathiriya

Rank: Liferay Master

Posts: 697

Join Date: August 4, 2010

Recent Posts

Hello Kanan.
If you want to add custom field for User then just created Custom Field for User from control panel and add below code some jsp of registration flow or edit user flow.
Set classPK to 0 if user is to be added else userId if user is to be updated.

1<liferay-ui:custom-attribute
2        label="LABEL"
3        className="<%= User.class.getName() %>"
4        classPK="<%=selUser!=null? selUser.getUserId():0 %>"
5        editable="<%= true %>"
6        name="CUSTOMFIELDNAME"
7    />


HTH,