Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Oriol Mesia
Expando get String from String Array or Text Group Values.
October 25, 2013 9:51 AM
Answer

Oriol Mesia

Rank: Junior Member

Posts: 64

Join Date: April 4, 2013

Recent Posts

Hi guys,

I extend the registration of my Liferay Web Page.

I set the new attributes in Custom Attributes this way...

1user.getExpandoBridge().setAttribute("Parameter", new String[] {"value"});



Now I have a Hook with the LoginAction extended and I want to reed this custom Attributes, which is the way to read that attributes?
(I want to get the string selected from String Array or Text Group Values Custom Attribute)

I tryed lot of things and anyone functions, for example this one...

1String[] parameter = (String[])user.getExpandoBridge().getAttribute("Parameter");

1String parameter = (String)user.getExpandoBridge().getAttribute("Parameter");

And none works..


Does anyone knows a solution???


Thank you so much,
Oriol
Oriol Mesia
RE: Expando get String from String Array or Text Group Values.
October 25, 2013 10:15 AM
Answer

Oriol Mesia

Rank: Junior Member

Posts: 64

Join Date: April 4, 2013

Recent Posts

I have update and view permissions for all the users.

I set the Default Values for each attribute, and I also try this method for reading the custom attributes:

 1    public static String getExpandoValues (User currentUser, long userId, long companyId, long groupId, long classPK, String CustomField) {
 2        String data = "";
 3        ExpandoTable expandoTableBC;
 4        try {
 5            expandoTableBC = ExpandoTableLocalServiceUtil.getDefaultTable(companyId, User.class.getName());
 6            if(Validator.isNull(expandoTableBC)){
 7                System.out.println("ExpandoTable created!");
 8                expandoTableBC = ExpandoTableLocalServiceUtil.addTable(companyId, User.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME);
 9            }
10            System.out.println("CF : " + CustomField);
11            ExpandoColumn expandoColumnBC = ExpandoColumnLocalServiceUtil.getColumn(companyId, User.class.getName(), expandoTable.getName(), CustomField);
12            if(Validator.isNotNull(expandoColumnBC)){
13                System.out.println("Existing Column: " + expandoColumnBC);
14                ExpandoValue expandoValueBC = ExpandoValueLocalServiceUtil.getValue(expandoTable.getTableId(), expandoColumn.getColumnId(), classPK);
15                System.out.println("expandoValueBC : " + expandoValueBC);
16                data = expandoValueBC.getData();
17                System.out.println("data : " + data);
18                if(!Validator.isNotNull(expandoValueBC)){
19                    System.out.println("Error al llegir expandoValue;");
20                }
21            }
22        } catch (PortalException e) {
23            e.printStackTrace();
24        } catch (SystemException e) {
25            e.printStackTrace();
26        }
27        System.out.println("data : " + data);
28        return data;
29    }


But I get this result:

expandoValueBC : {valueId=21110, companyId=10154, tableId=10432, columnId=10433, rowId=21107, classNameId=10005, classPK=21101, data=}
data :
Oriol Mesia
RE: Expando get String from String Array or Text Group Values.
October 25, 2013 10:47 AM
Answer

Oriol Mesia

Rank: Junior Member

Posts: 64

Join Date: April 4, 2013

Recent Posts

This finally works for me...


1ExpandoValue expandoValueBC = ExpandoValueLocalServiceUtil.getValue(companyId, User.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME, "Salary",currentUser.getUserId());
2String salaryresult = expandoValueBC.getData();