Fórum
ExpandoValue of new Custom Field is null
Yannick Weinz, modificado 12 Anos atrás.
ExpandoValue of new Custom Field is null
Junior Member Postagens: 69 Data de Entrada: 15/11/10 Postagens 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
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, modificado 12 Anos atrás.
RE: ExpandoValue of new Custom Field is null
Liferay Master Postagens: 978 Data de Entrada: 03/01/10 Postagens Recentes
did u set the permission on the custom field appropriately ?
Rajesh Chaurasia, modificado 12 Anos atrás.
RE: ExpandoValue of new Custom Field is null
Regular Member Postagens: 183 Data de Entrada: 18/08/11 Postagens 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.
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, modificado 12 Anos atrás.
RE: ExpandoValue of new Custom Field is null
Junior Member Postagens: 69 Data de Entrada: 15/11/10 Postagens 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:
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):
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)...
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:
public ExpandoValue getValue(String fieldName) throws SystemException, PortalException{
return ExpandoValueLocalServiceUtil.getValue(user.getCompanyId(), User.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME, fieldName, user.getUserId());
}
public String getDisplayValue(String key) throws SystemException, PortalException{
ExpandoValue value = getValue(key);
if(key == PROPERTY_BEHOERDE){
return (String) BEHOERDE_DESC.get(value.getInteger());
}
if(key == PROPERTY_EINRICHTUNG){
return (String) EINRICHTUNG_DESC.get(value.getInteger());
}
if(value != null){
return value.getData();
}else{
return "";
}
}
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):
public void setValue(String key, Object value, String type) throws SystemException, PortalException{
ExpandoValue expandoValue = getValue(key);
if(type == "Integer"){
expandoValue.setInteger(Integer.parseInt((String) value));
}
if(type == "String"){
expandoValue.setString((String)value);
}
ExpandoValueLocalServiceUtil.updateExpandoValue(expandoValue);
}
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, modificado 12 Anos atrás.
RE: ExpandoValue of new Custom Field is null
Junior Member Postagens: 69 Data de Entrada: 15/11/10 Postagens 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
thx again
Pradip A Bhatt, modificado 10 Anos atrás.
RE: ExpandoValue of new Custom Field is null
Junior Member Postagens: 51 Data de Entrada: 29/01/13 Postagens 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
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