Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Yannick Weinz
ExpandoValue of new Custom Field is null
8 de Dezembro de 2011 15:31
Resposta

Yannick Weinz

Ranking: Junior Member

Mensagens: 69

Data de entrada: 15 de Novembro de 2010

Mensagens recentes

Hi,

i have a little (or rather big) Problem with the Custom fields and Expando Values.

I need to create Custom Fields to extend the Data that is stored for Users.
Now, on a custom Profile Page, I try to read the CustomFields using the ExpandoValueLocalServiceUtil.
The Problem now ist: its null.

Thats not big of a deal for the Custom Profile Display, but a very big Problem when i want to change the Custom Field.

For Example, i have a field called Department, its a Text Custom Field. When i read it, i get back null und it simply displays nothing. But when i now want to update that value, i have the problem that i get back null rather then an Empty ExpandoValue...

And i just can't create a new one using ExpandoValueLocalServiceUtil.createExpandoValue, because it wants an id, but how do i determin the next higher ID for that, because i can't just give that some id because every user has this value...

Edit: I'm using Liferay 6.0.5

Greetings,

Yannick
Jack Bakker
RE: ExpandoValue of new Custom Field is null
8 de Dezembro de 2011 16:52
Resposta

Jack Bakker

Ranking: Liferay Master

Mensagens: 882

Data de entrada: 3 de Janeiro de 2010

Mensagens recentes

did u set the permission on the custom field appropriately ?
Rajesh Chaurasia
RE: ExpandoValue of new Custom Field is null
8 de Dezembro de 2011 22:12
Resposta

Rajesh Chaurasia

Ranking: Regular Member

Mensagens: 119

Data de entrada: 18 de Agosto de 2011

Mensagens recentes

Apart from per missioon that you need to set , the below might interest you.
I too was getting an empty value for expando in my java action(EditArticleAction.java) class but the same code when I use in jsp ( EditArticle.jsp ) gave me desired value which i had set in my acion class.I used a custom field with propery text and name as dlFileIds in webcontent category.

In java file :
if(fileEntry!= null && article != null){
String dlFileIds = ParamUtil.getString(actionRequest, "dlFileIds");
if(dlFileIds!= null && !("").equals(dlFileIds)){
dlFileIds = dlFileIds +","+String.valueOf(fileEntry.getFileEntryId());
}else{
dlFileIds = String.valueOf(fileEntry.getFileEntryId());
}
if(dlFileIds!= null){
article.getExpandoBridge().setAttribute("dlFileIds", dlFileIds);
}else{

}
}


As you can see above I had passed the dlFileIds from java using a form submit to action class

if(article != null ){
value = (String)article.getExpandoBridge().getAttribute("dlFileIds");
}
<aui:form action="<%= editArticleActionURL %>" enctype="multipart/form-data" method="post" name="fm1">
......
<aui:input name="dlFileIds" type="hidden" value="<%= value %>" />
......

Hope this helps you.
Yannick Weinz
RE: ExpandoValue of new Custom Field is null
8 de Dezembro de 2011 23:25
Resposta

Yannick Weinz

Ranking: Junior Member

Mensagens: 69

Data de entrada: 15 de Novembro de 2010

Mensagens recentes

thx,
but right now, this doesn't really help me, because i'm doing a complete different aproach (at least i think so, when it comes to the Expando i'm never entirely sure what happens -.-).

So my code to get the Information of a Custom Field looks like this:

 1
 2public ExpandoValue getValue(String fieldName) throws SystemException, PortalException{
 3        return ExpandoValueLocalServiceUtil.getValue(user.getCompanyId(), User.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME, fieldName, user.getUserId());
 4}
 5
 6public String getDisplayValue(String key) throws SystemException, PortalException{
 7        ExpandoValue value = getValue(key);
 8        if(key == PROPERTY_BEHOERDE){
 9            return (String) BEHOERDE_DESC.get(value.getInteger());
10        }
11        if(key == PROPERTY_EINRICHTUNG){
12            return (String) EINRICHTUNG_DESC.get(value.getInteger());
13        }
14        if(value != null){
15            return value.getData();
16        }else{
17            return "";
18        }
19    }


And that works completely finde... But the Problem comes, when i want to edit the Values of a Custom Field for a User, if i havn't set a value for it yet (meaning i never gave this custom Field a specific value after creating it):

 1
 2    public void setValue(String key, Object value, String type) throws SystemException, PortalException{
 3        ExpandoValue expandoValue = getValue(key);
 4        if(type == "Integer"){
 5            expandoValue.setInteger(Integer.parseInt((String) value));
 6        }
 7        if(type == "String"){
 8            expandoValue.setString((String)value);
 9        }
10        ExpandoValueLocalServiceUtil.updateExpandoValue(expandoValue);
11    }


The Problem here is, that "getValue(key) returns null, because that Custom Field for the User does not has a value yet, so right now i have no means of initializing the ExpandoValue, because i get back null instead of an empty ExpandoValue...

I wanted to try the EpandoValueLocalServiceUtil.createExpandoValue, but that method wants an ID, and i don't know how i can look up all the other IDs for the ExpandoTable and simply make it the highest ID +1...

Edit: The really strange thing is... sometimes it works! I don't know y, but today, after starting my eclipse and develop server, assigning the new field works! I could simply insert a value and everything worked... but i have absolutely no idea, why...

after deleting theCustom Field and creating it again (it was just a testfield), the same problem happens again (getting null back when i use my "getValue" method)...
Yannick Weinz
RE: ExpandoValue of new Custom Field is null
16 de Dezembro de 2011 05:07
Resposta

Yannick Weinz

Ranking: Junior Member

Mensagens: 69

Data de entrada: 15 de Novembro de 2010

Mensagens recentes

Ok, i found a solution. I simply rewrote my Code to use the expandoBridge and the getAttribute / setAttribute Methods from the user, like Rajesh Chaurasia posted with his example. Now it works finde.

thx again
Pradip A Bhatt
RE: ExpandoValue of new Custom Field is null
27 de Fevereiro de 2014 21:26
Resposta

Pradip A Bhatt

Ranking: Junior Member

Mensagens: 51

Data de entrada: 29 de Janeiro de 2013

Mensagens recentes

Hello All,
I am using Liferay 6.1 CE version. I added my custom attribute in User entity from control panel. I want to add this my custom field in create_account.jsp hook page. I added like this way.

<div class="exp-ctrl-holder">
<liferay-ui:custom-attribute className="<%=User.class.getName()%>"
classPK="<%=0%>" editable="<%=true%>" label="<%=true%>"
name="user-default-group-name" />

After that i am trying to getting this value in UserLocalService hook class which extends UserLocalServiceWrapper class - (hook). I find each value from this but can not able to get my custom field value.

I am trying to get custom field value like this.

String defaultGroup = (String) User.getExpandoBridge().getAttribute("defaultGroupName");
log.info("Default Group Name :" + defaultGroup);

But I am getting null value or default value which I set at the time of adding custom attribute. I can not find my entered value from jsp page.

Please help me.

Regards :
Pradip Bhatt
pradip.bhatt@aspiresoftware.in