Thursday, 10 October 2013

How to get Custom Field value in Liferay using liferay API?

This code is done for the Expando of User Model (UserExpando) and the custom filed "userCity"



//////////////////////////////

LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
               
                long companyId = liferayFacesContext.getCompanyId();
               
                User user = liferayFacesContext.getUser();
                System.out.println("User info "+user.getUserId()+" --- "+user.getFirstName()+" ---- "+user.getEmailAddress());
                Locale locale = liferayFacesContext.getLocale();
                ExpandoValue val=null;
                ExpandoTable expandoTable = ExpandoTableLocalServiceUtil.getDefaultTable(companyId,User.class.getName());
                long expandoTableId=expandoTable.getTableId();
                ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(expandoTableId, UserExpando.USER_CITY.getName());
                 if (column != null) {
                 val = ExpandoValueLocalServiceUtil.getValue(expandoTableId, column.getColumnId(), user.getUserId());
                   if (val != null) {
                     System.out.println("val====================="+ val);
                   }
                  
                }

/////////////////////////////////

No comments:

Post a Comment