Fórumok

[SOLVED]Getting a custom user field value (expando)

thumbnail
Daniel Kreiseder, módosítva 14 év-val korábban

[SOLVED]Getting a custom user field value (expando)

New Member Bejegyzések: 12 Csatlakozás dátuma: 2009.01.08. Legújabb bejegyzések
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:

    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):

    for (Enumeration<string> attrs = user.getExpandoBridge().getAttributeNames(); attrs.hasMoreElements();)
    	_log.info("elem: '" + attrs.nextElement() + "'");
</string>


Somehow I miss the point here....
thumbnail
Amos Fong, módosítva 14 év-val korábban

RE: Getting a custom user field value (expando)

Liferay Legend Bejegyzések: 2047 Csatlakozás dátuma: 2008.10.07. Legújabb bejegyzések
Hi Daniel,

When you created the custom attribute, which type did you choose? Maybe try casting into that type.
thumbnail
Daniel Kreiseder, módosítva 14 év-val korábban

RE: Getting a custom user field value (expando)

New Member Bejegyzések: 12 Csatlakozás dátuma: 2009.01.08. Legújabb bejegyzések
The custom field is of type string...
Mahmoud kallel, módosítva 10 év-val korábban

RE: Getting a custom user field value (expando)

New Member Bejegyzések: 7 Csatlakozás dátuma: 2013.11.20. Legújabb bejegyzések
please ,
i need help
i want to add custom field like nationality or grade
what can i do ??
thanks
Mahmoud kallel, módosítva 10 év-val korábban

RE: Getting a custom user field value (expando)

New Member Bejegyzések: 7 Csatlakozás dátuma: 2013.11.20. Legújabb bejegyzések
please ,
i need help
i want to add custom field like nationality or grade
what can i do ??
thanks
thumbnail
Daniel Kreiseder, módosítva 14 év-val korábban

RE: Getting a custom user field value (expando)

New Member Bejegyzések: 12 Csatlakozás dátuma: 2009.01.08. Legújabb bejegyzések
It was a security problem...

In com.liferay.portlet.expando.service.impl.ExpandoValueServiceImpl.getData(String className, String tableName, String columnName, long classPK)
:

		if (ExpandoColumnPermission.contains(
				getPermissionChecker(), column, ActionKeys.VIEW)) {

			return expandoValueLocalService.getData(
				className, tableName, columnName, classPK);
		}
		else {
			[b]return null;[/b]
		}


I only had to set the view permisson on the custom expando value, and everything worked fine ....
thumbnail
ilke Muhtaroglu, módosítva 14 év-val korábban

RE: Getting a custom user field value (expando)

Regular Member Bejegyzések: 226 Csatlakozás dátuma: 2009.05.12. Legújabb bejegyzések
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
thumbnail
Daniel Kreiseder, módosítva 14 év-val korábban

RE: Getting a custom user field value (expando)

New Member Bejegyzések: 12 Csatlakozás dátuma: 2009.01.08. Legújabb bejegyzések
Control Panel-> Users->Custom Attributes->Actions->Permissions


Set Guest Permission to read
thumbnail
vikash kumar chaurasia, módosítva 14 év-val korábban

RE: Getting a custom user field value (expando)

Junior Member Bejegyzések: 97 Csatlakozás dátuma: 2010.01.08. Legújabb bejegyzések
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, módosítva 13 év-val korábban

RE: Getting a custom user field value (expando)

New Member Bejegyzések: 4 Csatlakozás dátuma: 2009.08.20. Legújabb bejegyzések
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

(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, módosítva 13 év-val korábban

RE: Getting a custom user field value (expando)

New Member Bejegyzések: 6 Csatlakozás dátuma: 2010.11.18. Legújabb bejegyzések
I have the same problem. Have you solved it?

It can't be so difficult!
thumbnail
Piotr Filipowicz, módosítva 13 év-val korábban

RE: Getting a custom user field value (expando)

Junior Member Bejegyzések: 52 Csatlakozás dátuma: 2010.11.18. Legújabb bejegyzések
Maybe you should write something like this:


String name = "myAttr";
		int type = user.getExpandoBridge().getAttributeType(name);
		Serializable value = user.getExpandoBridge().getAttribute(name);
		Serializable defaultValue = user.getExpandoBridge().getAttributeDefault(name);
		if (type == ExpandoColumnConstants.STRING_ARRAY) {
			String[] curValue = (String[])value;
			for (String curDefaultValue : (String[])defaultValue) {
				if ((curValue != null) &amp;&amp; (curValue.length &gt; 0) &amp;&amp; (curDefaultValue.equals(curValue[0]))) {
					System.out.println(curDefaultValue);
				}
			}
		}


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, módosítva 13 év-val korábban

RE: Getting a custom user field value (expando)

New Member Bejegyzés: 1 Csatlakozás dátuma: 2010.11.22. Legújabb bejegyzések
This is not solved! I cannot get the value of expando atrributes it always gives me defaultValue. I tried


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


and


Map<string, serializable> expandoAttribs = file.getExpandoBridge().getAttributes();
Boolean a = (Boolean)file.getExpandoBridge().getAttribute("Date_attr");
Date ad = (Date)file.getExpandoBridge().getAttribute("Arch_it");
</string,>


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

I've tried to do it like this:


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


and ... THERE IS NOOOOOOOOO *$@% DOCUMENTATION on the parameters exceppt for @depricated...
thumbnail
Adolfo Enrique Benedetti, módosítva 13 év-val korábban

RE: Getting a custom user field value (expando)

Junior Member Bejegyzések: 45 Csatlakozás dátuma: 2009.06.04. Legújabb bejegyzések
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, módosítva 12 év-val korábban

RE: Getting a custom user field value (expando)

New Member Bejegyzések: 4 Csatlakozás dátuma: 2011.01.20. Legújabb bejegyzések
kuki last:
This is not solved! I cannot get the value of expando atrributes it always gives me defaultValue. I tried


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


and


Map<string, serializable> expandoAttribs = file.getExpandoBridge().getAttributes();
Boolean a = (Boolean)file.getExpandoBridge().getAttribute("Date_attr");
Date ad = (Date)file.getExpandoBridge().getAttribute("Arch_it");
</string,>


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

I've tried to do it like this:


			ExpandoTable et = ExpandoTableLocalServiceUtil.getTable(eb.getClassName(), eb.get);
			System.out.println("et: "+et.getTableId()+" "+et.getName()+" "+et.getPrimaryKey());
			ExpandoColumn ec = ExpandoColumnLocalServiceUtil.getColumn(et.getTableId(), et.getName());
			System.out.println("ec: "+ec.getColumnId()+" ");
			//ExpandoRowLocalServiceUtil.getRow(et.getTableId(), et.getPrimaryKey());
			//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, módosítva 12 év-val korábban

RE: Getting a custom user field value (expando)

New Member Bejegyzések: 19 Csatlakozás dátuma: 2010.05.17. Legújabb bejegyzések
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!!!
Marc Piparo, módosítva 12 év-val korábban

RE: Getting a custom user field value (expando)

Junior Member Bejegyzések: 43 Csatlakozás dátuma: 2011.03.14. Legújabb bejegyzések
thanks!!
Krishan Kumar, módosítva 12 év-val korábban

RE: Getting a custom user field value (expando)

New Member Bejegyzések: 16 Csatlakozás dátuma: 2012.01.18. Legújabb bejegyzések
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
thumbnail
Praveen P, módosítva 12 év-val korábban

RE: Getting a custom user field value (expando)

Regular Member Bejegyzések: 100 Csatlakozás dátuma: 2012.02.21. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: Getting a custom user field value (expando)

New Member Bejegyzések: 5 Csatlakozás dátuma: 2012.01.09. Legújabb bejegyzések
Hi everybody,

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


long versionID = DLFileVersionLocalServiceUtil.getLatestFileVersion(fileId, true).getFileVersionId();
ExpandoTable expandoTable = ExpandoTableLocalServiceUtil.getDefaultTable(companyId, DLFileEntry.class.getName());
ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(expandoTable.getTableId(), "custom.order");
if (column != null) {
ExpandoValue val = ExpandoValueLocalServiceUtil.getValue(expandoTable.getTableId(), column.getColumnId(), versionID);
  if (val != null) {
    return val.getInteger();
  } else {
    return 0;
  }
}


Hope this helps
thumbnail
Pranoti Nandurkar, módosítva 10 év-val korábban

RE: Getting a custom user field value (expando)

Junior Member Bejegyzések: 48 Csatlakozás dátuma: 2012.02.03. Legújabb bejegyzések
Thanks Julien, It worked for me... emoticon
Mahmoud kallel, módosítva 10 év-val korábban

RE: Getting a custom user field value (expando)

New Member Bejegyzések: 7 Csatlakozás dátuma: 2013.11.20. Legújabb bejegyzések
please ,
i need help
i want to add custom field like nationality or grade
what can i do ??
thanks
Mahmoud kallel, módosítva 10 év-val korábban

RE: Getting a custom user field value (expando)

New Member Bejegyzések: 7 Csatlakozás dátuma: 2013.11.20. Legújabb bejegyzések
please ,
i need help
i want to add custom field like nationality or grade
what can i do ??
thanks
thumbnail
Ehsan Rashidy, módosítva 10 év-val korábban

RE: Getting a custom user field value (expando)

New Member Bejegyzések: 17 Csatlakozás dátuma: 2013.04.24. Legújabb bejegyzések
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");)
thumbnail
ilke Muhtaroglu, módosítva 14 év-val korábban

RE: [SOLVED]Getting a custom user field value (expando)

Regular Member Bejegyzések: 226 Csatlakozás dátuma: 2009.05.12. Legújabb bejegyzések
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
thumbnail
Anil Sunkari, módosítva 12 év-val korábban

RE: [SOLVED]Getting a custom user field value (expando)

Expert Bejegyzések: 427 Csatlakozás dátuma: 2009.08.12. Legújabb bejegyzések
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
thumbnail
Tejas Patel, módosítva 12 év-val korábban

RE: [SOLVED]Getting a custom user field value (expando)

Junior Member Bejegyzések: 71 Csatlakozás dátuma: 2012.01.24. Legújabb bejegyzések
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
Ved Mishra, módosítva 7 év-val korábban

RE: [SOLVED]Getting a custom user field value (expando)

New Member Bejegyzés: 1 Csatlakozás dátuma: 2016.06.09. Legújabb bejegyzések
Excellent job

it works , thanks emoticon
thumbnail
Jack Bakker, módosítva 12 év-val korábban

RE: [SOLVED]Getting a custom user field value (expando)

Liferay Master Bejegyzések: 978 Csatlakozás dátuma: 2010.01.03. Legújabb bejegyzések
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
thumbnail
Samir Gami, módosítva 12 év-val korábban

RE: [SOLVED]Getting a custom user field value (expando)

Regular Member Bejegyzések: 162 Csatlakozás dátuma: 2011.02.04. Legújabb bejegyzések
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.
Mahmoud kallel, módosítva 10 év-val korábban

RE: [SOLVED]Getting a custom user field value (expando)

New Member Bejegyzések: 7 Csatlakozás dátuma: 2013.11.20. Legújabb bejegyzések
please ,
i need help
i want to add custom field like nationality or grade
what can i do ??
thanks
Mahmoud kallel, módosítva 10 év-val korábban

RE: [SOLVED]Getting a custom user field value (expando)

New Member Bejegyzések: 7 Csatlakozás dátuma: 2013.11.20. Legújabb bejegyzések
please ,
i need help
i want to add custom field like nationality or grade
what can i do ??
thanks
thumbnail
Archi Madhu, módosítva 10 év-val korábban

RE: [SOLVED]Getting a custom user field value (expando)

Regular Member Bejegyzések: 237 Csatlakozás dátuma: 2008.03.25. Legújabb bejegyzések
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, módosítva 10 év-val korábban

RE: [SOLVED]Getting a custom user field value (expando)

New Member Bejegyzések: 7 Csatlakozás dátuma: 2013.11.20. Legújabb bejegyzések
thanks, but in what field i shoul put this code?