Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
[SOLVED]Getting a custom user field value (expando) Daniel Kreiseder July 17, 2009 2:00 AM
RE: Getting a custom user field value (expando) Amos Fong July 16, 2009 3:14 PM
RE: Getting a custom user field value (expando) Daniel Kreiseder July 16, 2009 10:53 PM
RE: Getting a custom user field value (expando) Mahmoud kallel January 27, 2014 1:50 PM
RE: Getting a custom user field value (expando) Mahmoud kallel January 27, 2014 1:51 PM
RE: Getting a custom user field value (expando) Daniel Kreiseder July 17, 2009 1:59 AM
RE: Getting a custom user field value (expando) ilke Muhtaroglu November 17, 2009 5:29 AM
RE: Getting a custom user field value (expando) Daniel Kreiseder December 2, 2009 7:33 AM
RE: Getting a custom user field value (expando) vikash kumar chaurasia February 24, 2010 8:23 PM
RE: Getting a custom user field value (expando) jeff Leitman June 21, 2010 9:53 AM
RE: Getting a custom user field value (expando) Borja Gómez November 24, 2010 10:15 AM
RE: Getting a custom user field value (expando) Piotr Filipowicz November 24, 2010 12:31 PM
RE: Getting a custom user field value (expando) kuki last February 24, 2011 12:59 AM
RE: Getting a custom user field value (expando) Adolfo Benedetti March 30, 2011 5:51 AM
RE: Getting a custom user field value (expando) Mykola M June 16, 2011 4:09 AM
RE: Getting a custom user field value (expando) Jack Daniels July 28, 2011 8:38 AM
RE: Getting a custom user field value (expando) Marc Piparo September 13, 2011 10:33 AM
RE: Getting a custom user field value (expando) Krishan Kumar March 9, 2012 11:32 PM
RE: Getting a custom user field value (expando) Praveen P April 20, 2012 1:37 AM
RE: Getting a custom user field value (expando) Julien GRESSE June 29, 2012 8:20 AM
RE: Getting a custom user field value (expando) Pranoti Nandurkar May 28, 2013 5:59 AM
RE: Getting a custom user field value (expando) Mahmoud kallel January 27, 2014 1:48 PM
RE: Getting a custom user field value (expando) Mahmoud kallel January 27, 2014 1:48 PM
RE: Getting a custom user field value (expando) Ehsan Rashidy March 12, 2014 6:14 AM
RE: [SOLVED]Getting a custom user field value (expando) ilke Muhtaroglu November 17, 2009 5:15 AM
RE: [SOLVED]Getting a custom user field value (expando) Anil Sunkari July 28, 2011 10:00 PM
RE: [SOLVED]Getting a custom user field value (expando) Tejas patel February 23, 2012 8:48 PM
RE: [SOLVED]Getting a custom user field value (expando) Jack Bakker September 13, 2011 10:41 AM
RE: [SOLVED]Getting a custom user field value (expando) Samir Gami September 14, 2011 5:16 AM
RE: [SOLVED]Getting a custom user field value (expando) Mahmoud kallel January 27, 2014 1:49 PM
RE: [SOLVED]Getting a custom user field value (expando) Mahmoud kallel January 27, 2014 1:52 PM
RE: [SOLVED]Getting a custom user field value (expando) Archi Madhu January 27, 2014 7:02 PM
RE: [SOLVED]Getting a custom user field value (expando) Mahmoud kallel February 5, 2014 4:11 PM
Daniel Kreiseder
[SOLVED]Getting a custom user field value (expando)
July 17, 2009 2:00 AM
Answer

Daniel Kreiseder

Rank: New Member

Posts: 12

Join Date: January 7, 2009

Recent Posts

I added a custom user field in Liferay, and set a value on a specific user.

How can I access this value programmatically?


If I try this, I always get null:

1    String customAttr = (String)user.getExpandoBridge().getAttribute("customAttr");


user.getExpandoBridge().getAttribute("customAttr") returns a value of Type java.IO.Serializable.
Maybe the cast here is wrong?

But the Custom Attribute does exist (following code prints out the attribute key):
1
2    for (Enumeration<String> attrs = user.getExpandoBridge().getAttributeNames(); attrs.hasMoreElements();)
3        _log.info("elem: '" + attrs.nextElement() + "'");


Somehow I miss the point here....
Amos Fong
RE: Getting a custom user field value (expando)
July 16, 2009 3:14 PM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1844

Join Date: October 7, 2008

Recent Posts

Hi Daniel,

When you created the custom attribute, which type did you choose? Maybe try casting into that type.
Daniel Kreiseder
RE: Getting a custom user field value (expando)
July 16, 2009 10:53 PM
Answer

Daniel Kreiseder

Rank: New Member

Posts: 12

Join Date: January 7, 2009

Recent Posts

The custom field is of type string...
Daniel Kreiseder
RE: Getting a custom user field value (expando)
July 17, 2009 1:59 AM
Answer

Daniel Kreiseder

Rank: New Member

Posts: 12

Join Date: January 7, 2009

Recent Posts

It was a security problem...

In com.liferay.portlet.expando.service.impl.ExpandoValueServiceImpl.getData(String className, String tableName, String columnName, long classPK)
:
 1
 2        if (ExpandoColumnPermission.contains(
 3                getPermissionChecker(), column, ActionKeys.VIEW)) {
 4
 5            return expandoValueLocalService.getData(
 6                className, tableName, columnName, classPK);
 7        }
 8        else {
 9            [b]return null;[/b]
10        }


I only had to set the view permisson on the custom expando value, and everything worked fine ....
ilke Muhtaroglu
RE: [SOLVED]Getting a custom user field value (expando)
November 17, 2009 5:15 AM
Answer

ilke Muhtaroglu

Rank: Regular Member

Posts: 223

Join Date: May 12, 2009

Recent Posts

Hi,

I try to access to a custom attribute of users.

The result comes as Serializable and when i cast the result to Integer, and when i print the value it appears as "null", not the integer value i have given to that custom attribute !

user.getExpandoBridge().getAttribute("sessionNo");

am i supposed to cast it ?

the custom attribute exists ! I checked it as you proposed. How did you solve this "null" problem ???

ilke
ilke Muhtaroglu
RE: Getting a custom user field value (expando)
November 17, 2009 5:29 AM
Answer

ilke Muhtaroglu

Rank: Regular Member

Posts: 223

Join Date: May 12, 2009

Recent Posts

Hi,

I am trying to access this value before i log-in ! Where and how what do we set ?

"had to set the view permisson on the custom expando value" Can you please inform more about how to do this?

thanks for co-operation.

ilke
Daniel Kreiseder
RE: Getting a custom user field value (expando)
December 2, 2009 7:33 AM
Answer

Daniel Kreiseder

Rank: New Member

Posts: 12

Join Date: January 7, 2009

Recent Posts

Control Panel-> Users->Custom Attributes->Actions->Permissions


Set Guest Permission to read
vikash kumar chaurasia
RE: Getting a custom user field value (expando)
February 24, 2010 8:23 PM
Answer

vikash kumar chaurasia

Rank: Junior Member

Posts: 97

Join Date: January 8, 2010

Recent Posts

Hi,


My question is:

If I have created a custom attribute for User e.g. country from the control panel and set it's value as "France" for a user. How can I get that attribute value for that user in a portlet in Plugin SDK envt.

Thanks.
jeff Leitman
RE: Getting a custom user field value (expando)
June 21, 2010 9:53 AM
Answer

jeff Leitman

Rank: New Member

Posts: 4

Join Date: August 20, 2009

Recent Posts

vikash kumar chaurasia:
Hi,


My question is:

If I have created a custom attribute for User e.g. country from the control panel and set it's value as "France" for a user. How can I get that attribute value for that user in a portlet in Plugin SDK envt.

Thanks.



I am wondering the same thing. I have a custom attribute of type java.lang.String[], used for timezones (e.g. "America/New York", "America/Chicago") for Organizations. I put the list of available timezones into the Default Value to get the list to show up, and chosoe "Selection" when creating the custom attribute. Then for an organization, I can choose one timezone from the list. But when I try to do
1
2(String) org.getExpandoBridge().getAttribute("timezone");


it always throws an error because "timezone" attribute has type "java.lang.String[]", not "java.lang.String".

So how do I retrieve only the chosen timezone String?
Borja Gómez
RE: Getting a custom user field value (expando)
November 24, 2010 10:15 AM
Answer

Borja Gómez

Rank: New Member

Posts: 6

Join Date: November 18, 2010

Recent Posts

I have the same problem. Have you solved it?

It can't be so difficult!
Piotr Filipowicz
RE: Getting a custom user field value (expando)
November 24, 2010 12:31 PM
Answer

Piotr Filipowicz

Rank: Junior Member

Posts: 51

Join Date: November 18, 2010

Recent Posts

Maybe you should write something like this:

 1
 2String name = "myAttr";
 3        int type = user.getExpandoBridge().getAttributeType(name);
 4        Serializable value = user.getExpandoBridge().getAttribute(name);
 5        Serializable defaultValue = user.getExpandoBridge().getAttributeDefault(name);
 6        if (type == ExpandoColumnConstants.STRING_ARRAY) {
 7            String[] curValue = (String[])value;
 8            for (String curDefaultValue : (String[])defaultValue) {
 9                if ((curValue != null) && (curValue.length > 0) && (curDefaultValue.equals(curValue[0]))) {
10                    System.out.println(curDefaultValue);
11                }
12            }
13        }


I saw similar code in tag ui:custom-attribute in file: portal/portal-web/docroot/html/taglib/ui/custom_attribute/page.jsp.

Give me the answer if this code looks right.

--
Best regards,
Piotr Filipowicz
kuki last
RE: Getting a custom user field value (expando)
February 24, 2011 12:59 AM
Answer

kuki last

Rank: New Member

Posts: 1

Join Date: November 22, 2010

Recent Posts

This is not solved! I cannot get the value of expando atrributes it always gives me defaultValue. I tried

1
2Boolean a = (Boolean)file.getExpandoBridge().getAttribute("Date_attr");
3Date ad = (Date)file.getExpandoBridge().getAttribute("Arch_it");


and

1
2Map<String, Serializable> expandoAttribs = file.getExpandoBridge().getAttributes();
3Boolean a = (Boolean)file.getExpandoBridge().getAttribute("Date_attr");
4Date ad = (Date)file.getExpandoBridge().getAttribute("Arch_it");


It still gives me the default values ... i can see them in the db table 'expandovalue'

I've tried to do it like this:

1
2            ExpandoTable et = ExpandoTableLocalServiceUtil.getTable(eb.getClassName(), eb.get);
3            System.out.println("et: "+et.getTableId()+" "+et.getName()+" "+et.getPrimaryKey());
4            ExpandoColumn ec = ExpandoColumnLocalServiceUtil.getColumn(et.getTableId(), et.getName());
5            System.out.println("ec: "+ec.getColumnId()+" ");
6            //ExpandoRowLocalServiceUtil.getRow(et.getTableId(), et.getPrimaryKey());
7            //ExpandoValueLocalServiceUtil.getValue(columnId rowId)


and ... THERE IS NOOOOOOOOO *$@% DOCUMENTATION on the parameters exceppt for @depricated...
Adolfo Benedetti
RE: Getting a custom user field value (expando)
March 30, 2011 5:51 AM
Answer

Adolfo Benedetti

Rank: Junior Member

Posts: 45

Join Date: June 3, 2009

Recent Posts

kuki last:
This is not solved! I cannot get the value of expando atrributes it always gives me defaultValue.

Did you try to change the values of your test? maybe the values retrieved from the custom fields are not the ones sent by the browser in the last submit, but the old ones(in your case the default values). see this post
Mykola M
RE: Getting a custom user field value (expando)
June 16, 2011 4:09 AM
Answer

Mykola M

Rank: New Member

Posts: 4

Join Date: January 20, 2011

Recent Posts

kuki last:
This is not solved! I cannot get the value of expando atrributes it always gives me defaultValue. I tried

1
2Boolean a = (Boolean)file.getExpandoBridge().getAttribute("Date_attr");
3Date ad = (Date)file.getExpandoBridge().getAttribute("Arch_it");


and

1
2Map<String, Serializable> expandoAttribs = file.getExpandoBridge().getAttributes();
3Boolean a = (Boolean)file.getExpandoBridge().getAttribute("Date_attr");
4Date ad = (Date)file.getExpandoBridge().getAttribute("Arch_it");


It still gives me the default values ... i can see them in the db table 'expandovalue'

I've tried to do it like this:

1
2            ExpandoTable et = ExpandoTableLocalServiceUtil.getTable(eb.getClassName(), eb.get);
3            System.out.println("et: "+et.getTableId()+" "+et.getName()+" "+et.getPrimaryKey());
4            ExpandoColumn ec = ExpandoColumnLocalServiceUtil.getColumn(et.getTableId(), et.getName());
5            System.out.println("ec: "+ec.getColumnId()+" ");
6            //ExpandoRowLocalServiceUtil.getRow(et.getTableId(), et.getPrimaryKey());
7            //ExpandoValueLocalServiceUtil.getValue(columnId rowId)


and ... THERE IS NOOOOOOOOO *$@% DOCUMENTATION on the parameters exceppt for @depricated...


This is ridiculous. Spent ~6h hours digging it, had to look up eventually how they display values of custom fields in control panel, and look what I have found!
Sorry for being somewhat emotional, but this is just stupid.

If you define custom field "myfield" on for instance Organization, and you call
org.getExpandoBridge().getAttribute("random") - returns null, because there's no field "random" defined
org.getExpandoBridge().getAttribute("myfield") - returns value as expected.

Simple, yep? But!
DLFileEntry (document library documents) is very special.
dlFileEntry.getExpandoBridge().getAttribute("random") - returns null, ok
dlFileEntry.getExpandoBridge().getAttribute("myfield") - returns default value! (like empty string for Text, 1 Jan 1970 for Date etc)

Extensive debugging shows, that in expandovalue for document with id say 100000 there's a record with classPK column value 100001. So class is somehow wrong.
Looking up liferay-portal-src-6.0.6\portal-web\docroot\html\portlet\document_library\edit_file_entry.jsp expained it all - they use DLFileVersion!

dlFileEntry.getFileVersion().getExpandoBridge().getAttribute("myfield") - returns desired value

Had to learn it the hard way )-:
So I hope sharing this knowledge will save mankind some wasted resources (-:
Enjoy.
Jack Daniels
RE: Getting a custom user field value (expando)
July 28, 2011 8:38 AM
Answer

Jack Daniels

Rank: New Member

Posts: 19

Join Date: May 17, 2010

Recent Posts

That is absurd indeed.

Thank you so much for providing a solution for others to follow. I was about to embark on the same quest when I stumbled on your post. Thanks again!!!
Anil Sunkari
RE: [SOLVED]Getting a custom user field value (expando)
July 28, 2011 10:00 PM
Answer

Anil Sunkari

Rank: Expert

Posts: 378

Join Date: August 11, 2009

Recent Posts

Hi ilke,

ilke Muhtaroglu:
Hi,

I try to access to a custom attribute of users.

The result comes as Serializable and when i cast the result to Integer, and when i print the value it appears as "null", not the integer value i have given to that custom attribute !

user.getExpandoBridge().getAttribute("sessionNo");

am i supposed to cast it ?

the custom attribute exists ! I checked it as you proposed. How did you solve this "null" problem ???

ilke


As per my understanding if i am right you can try using below code to get field value from expandovalue.

long userClassNameId = ClassNameLocalServiceUtil.getClassNameId(User.class.getName());
ExpandoTable table = ExpandoTableLocalServiceUtil.getDefaultTable(themeDisplay.getCompanyId(), userClassNameId );
ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(table.getTableId(), "portraitId");
ExpandoValue expandoValue = ExpandoValueLocalServiceUtil.getValue(table.getTableId(), column.getColumnId(), themeDisplay.getUserId());


Regards,
Anil Sunkari
Marc Piparo
RE: Getting a custom user field value (expando)
September 13, 2011 10:33 AM
Answer

Marc Piparo

Rank: Junior Member

Posts: 43

Join Date: March 14, 2011

Recent Posts

thanks!!
Jack Bakker
RE: [SOLVED]Getting a custom user field value (expando)
September 13, 2011 10:41 AM
Answer

Jack Bakker

Rank: Liferay Master

Posts: 500

Join Date: January 3, 2010

Recent Posts

ilke Muhtaroglu:

I try to access to a custom attribute of users.
The result comes as Serializable and when i cast the result to Integer, and when i print the value it appears as "null", not the integer value i have given to that custom attribute !
user.getExpandoBridge().getAttribute("sessionNo");
am i supposed to cast it ?
the custom attribute exists ! I checked it as you proposed. How did you solve this "null" problem ???


and check permissions on the custom field
Samir Gami
RE: [SOLVED]Getting a custom user field value (expando)
September 14, 2011 5:16 AM
Answer

Samir Gami

Rank: Regular Member

Posts: 159

Join Date: February 3, 2011

Recent Posts

Hey Guys,

What about ExpandoValueLocalServiceUtil , It have same purpose.
ExpandoValueLocalServiceUtil.getValue(companyId, User.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME, "Custom_Field_Name", userID);


Also it don't requires the Guest user permission to retrieve/update/add the custom field value.

Hope this may helps.
Tejas patel
RE: [SOLVED]Getting a custom user field value (expando)
February 23, 2012 8:48 PM
Answer

Tejas patel

Rank: Junior Member

Posts: 71

Join Date: January 23, 2012

Recent Posts

HI Anil
Do you please explain the objects you taken that which object refers to which class and what it returns .
Because i am new in this technology so please explain in detail so i understand how they works .
I use existing code but it gives error in ExpandoColumn and ExpandoValue.
and one thing can u please explain where to use this code like in processAction class or any other class.
Thanks and Regards,
Tejas patel
Krishan Kumar
RE: Getting a custom user field value (expando)
March 9, 2012 11:32 PM
Answer

Krishan Kumar

Rank: New Member

Posts: 16

Join Date: January 18, 2012

Recent Posts

Hi Mykola M,

I need a little help on Docuemnt Lib. custom Fields. If you can help me on this, that wud save my life.

I want to search documents on custom Fields value. That is, I added a custom field - say "Package" - in DL file and added a value - say "1234"- to it.

Now when is search the Liferay portal through open search portlet, it should give me this document. Currently Open search is searching on Custom fileds in User but not on Custom Fields in Document Library.

If you can suggest any solution, plz give it step by step as I am new to Liferay.

I am using Liferay 6.0.6 + tomcat 6.0.29 + MySQL 5.5.

Thanx in advance...

Krishan Kumar
Praveen P
RE: Getting a custom user field value (expando)
April 20, 2012 1:37 AM
Answer

Praveen P

Rank: Regular Member

Posts: 100

Join Date: February 20, 2012

Recent Posts

Hi i added custom field like country, and given some group of values but while fetching the data useing
(String) user.getExpandoBridge().getAttribute("Country") it is not displaying a desired value, how to get?

Thanks in advance
Julien GRESSE
RE: Getting a custom user field value (expando)
June 29, 2012 8:20 AM
Answer

Julien GRESSE

Rank: New Member

Posts: 4

Join Date: January 9, 2012

Recent Posts

Hi everybody,

We found a way to retreive custom fields value, it's bit complicated but it works fine.

 1
 2long versionID = DLFileVersionLocalServiceUtil.getLatestFileVersion(fileId, true).getFileVersionId();
 3ExpandoTable expandoTable = ExpandoTableLocalServiceUtil.getDefaultTable(companyId, DLFileEntry.class.getName());
 4ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(expandoTable.getTableId(), "custom.order");
 5if (column != null) {
 6ExpandoValue val = ExpandoValueLocalServiceUtil.getValue(expandoTable.getTableId(), column.getColumnId(), versionID);
 7  if (val != null) {
 8    return val.getInteger();
 9  } else {
10    return 0;
11  }
12}


Hope this helps
Pranoti Nandurkar
RE: Getting a custom user field value (expando)
May 28, 2013 5:59 AM
Answer

Pranoti Nandurkar

Rank: Junior Member

Posts: 46

Join Date: February 2, 2012

Recent Posts

Thanks Julien, It worked for me... emoticon
Mahmoud kallel
RE: Getting a custom user field value (expando)
January 27, 2014 1:48 PM
Answer

Mahmoud kallel

Rank: New Member

Posts: 7

Join Date: November 20, 2013

Recent Posts

please ,
i need help
i want to add custom field like nationality or grade
what can i do ??
thanks
Mahmoud kallel
RE: Getting a custom user field value (expando)
January 27, 2014 1:48 PM
Answer

Mahmoud kallel

Rank: New Member

Posts: 7

Join Date: November 20, 2013

Recent Posts

please ,
i need help
i want to add custom field like nationality or grade
what can i do ??
thanks
Mahmoud kallel
RE: [SOLVED]Getting a custom user field value (expando)
January 27, 2014 1:49 PM
Answer

Mahmoud kallel

Rank: New Member

Posts: 7

Join Date: November 20, 2013

Recent Posts

please ,
i need help
i want to add custom field like nationality or grade
what can i do ??
thanks
Mahmoud kallel
RE: Getting a custom user field value (expando)
January 27, 2014 1:50 PM
Answer

Mahmoud kallel

Rank: New Member

Posts: 7

Join Date: November 20, 2013

Recent Posts

please ,
i need help
i want to add custom field like nationality or grade
what can i do ??
thanks
Mahmoud kallel
RE: Getting a custom user field value (expando)
January 27, 2014 1:51 PM
Answer

Mahmoud kallel

Rank: New Member

Posts: 7

Join Date: November 20, 2013

Recent Posts

please ,
i need help
i want to add custom field like nationality or grade
what can i do ??
thanks
Mahmoud kallel
RE: [SOLVED]Getting a custom user field value (expando)
January 27, 2014 1:52 PM
Answer

Mahmoud kallel

Rank: New Member

Posts: 7

Join Date: November 20, 2013

Recent Posts

please ,
i need help
i want to add custom field like nationality or grade
what can i do ??
thanks
Archi Madhu
RE: [SOLVED]Getting a custom user field value (expando)
January 27, 2014 7:02 PM
Answer

Archi Madhu

Rank: Regular Member

Posts: 238

Join Date: March 24, 2008

Recent Posts

Mahmoud kallel:
please ,
i need help
i want to add custom field like nationality or grade
what can i do ??
thanks


I think following should work -

long userClassNameId = ClassNameLocalServiceUtil.getClassNameId(User.class.getName());
ExpandoTable table = ExpandoTableLocalServiceUtil.getDefaultTable(themeDisplay.getCompanyId(), userClassNameId );
ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(table.getTableId(), "nationality");
ExpandoValue expandoValue = ExpandoValueLocalServiceUtil.addValue(userClassNameId ,table.getTableId(), column.getColumnId(), classPK, "indian");
Mahmoud kallel
RE: [SOLVED]Getting a custom user field value (expando)
February 5, 2014 4:11 PM
Answer

Mahmoud kallel

Rank: New Member

Posts: 7

Join Date: November 20, 2013

Recent Posts

thanks, but in what field i shoul put this code?
Ehsan Rashidy
RE: Getting a custom user field value (expando)
March 12, 2014 6:14 AM
Answer

Ehsan Rashidy

Rank: New Member

Posts: 10

Join Date: April 24, 2013

Recent Posts

Daniel Kreiseder:
Control Panel-> Users->Custom Attributes->Actions->Permissions

Set Guest Permission to read


Hi,
Thank you Daneil for your helpful post,

I had the same problem with custom fields, here is my scenario:

First i created a custom field through control panel for organization (here),
Then I changed the permissions for this fields
(
1-login as administrator, go to control panel
2-Portal -> custom fields
3- click Actions -> permissions on you desired custom field
4- then check view check box for guest role
)

And at the end i just get the value of the custom field by ExpandoBridge.(organization.getExpandoBridge().getAttribute("CUSTOM_FIELD_NAME");)