Foros de discusión
RE: expandoValue is Null
Oriol Mesia, modificado hace 12 años.
expandoValue is Null
Junior Member Mensajes: 64 Fecha de incorporación: 4/04/13 Mensajes recientes
Hi,
I'm extending Login post action this way...
The obtained expandoValue is Null, I'm desperated I don't know how to solve this and get + set my Segmentation User Custom Field.
This Code Functions if I Before edited the CustomField by Hand(I also create a default value for It).
It seems that the linking with the expandoValue table is not working.
I tried these solutions:
1. The one I placed on the top.
2. This other...
method getAttribute returns Null.
3. Another one...
When expandoValue is null I want to create a new one and set the Default Data (even I already defined default data through CP). After processing information I set new Data and Update ExpandoValue.
As you see, the problem now is that I'm not able to find a free ID for a new ExpandoValue.
Does anyone knows a solution for some of the choices I presented here?
Thank you in advance,
Oriol
I'm extending Login post action this way...
public class LoginAction extends Action {
public void run(HttpServletRequest req, HttpServletResponse res) {
User currentUser;
try {
currentUser = PortalUtil.getUser(req);
long userId = PrincipalThreadLocal.getUserId();
long companyId = currentUser.getCompanyId();
long groupId = GroupLocalServiceUtil.getGroup(companyId, "Guest").getGroupId();
/* Get de CustomField Segmentation */
ExpandoTable expandoTable = ExpandoTableLocalServiceUtil.getDefaultTable(companyId, User.class.getName());
ExpandoColumn expandoColumn = ExpandoColumnLocalServiceUtil.getColumn(companyId, User.class.getName(), expandoTable.getName(), "Segmentation");
if (expandoColumn != null) {
ExpandoValue expandoValue = ExpandoValueLocalServiceUtil.getValue(expandoTable.getTableId(), expandoColumn.getColumnId(), classPK);
The obtained expandoValue is Null, I'm desperated I don't know how to solve this and get + set my Segmentation User Custom Field.
This Code Functions if I Before edited the CustomField by Hand(I also create a default value for It).
It seems that the linking with the expandoValue table is not working.
I tried these solutions:
1. The one I placed on the top.
2. This other...
String segments = (String)currentUser.getExpandoBridge().getAttribute("Segmentation");
System.out.println("Segments : " + segments);
method getAttribute returns Null.
getExpandoBridge().getAttribute("Segmentation");
3. Another one...
When expandoValue is null I want to create a new one and set the Default Data (even I already defined default data through CP). After processing information I set new Data and Update ExpandoValue.
ExpandoValue expandoValue = ExpandoValueLocalServiceUtil.getValue(expandoTable.getTableId(), expandoColumn.getColumnId(), classPK);
if (expandoValue==null)
expandoValue = ExpandoValueLocalServiceUtil.createExpandoValue([b]expandoColumn.getColumnId()+1[/b]);
expandoValue.setColumnId(expandoColumn.getColumnId());
expandoValue.setTableId(expandoTable.getTableId());
expandoValue.setClassPK(userId);
expandoValue.setData("Undefined");
ExpandoValueLocalServiceUtil.updateExpandoValue(expandoValue);
ExpandoValue expandoValue2 = ExpandoValueLocalServiceUtil.getValue(expandoTable.getTableId(), expandoColumn.getColumnId(), classPK);
System.out.println(expandoValue2);
}
As you see, the problem now is that I'm not able to find a free ID for a new ExpandoValue.
Does anyone knows a solution for some of the choices I presented here?
Thank you in advance,
Oriol
Apoorva Prakash, modificado hace 12 años.
RE: expandoValue is Null
Liferay Master Mensajes: 659 Fecha de incorporación: 15/06/10 Mensajes recientesOriol Mesia:
As you see, the problem now is that I'm not able to find a free ID for a new ExpandoValue.
Does anyone knows a solution for some of the choices I presented here?
Thank you in advance,
Oriol
Hi Mesai,
Expando works very well, see the following code:
try{
ExpandoTable expGroupTable = ExpandoTableLocalServiceUtil.getTable(themeDisplay.getCompanyId(), User.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME);
if(Validator.isNull(expGroupTable)){
_log.info("ExpandoTable created!");
expGroupTable = ExpandoTableLocalServiceUtil.addTable(themeDisplay.getCompanyId(), User.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME);
}
Util.updateColumnValue(expGroupTable.getTableId(), "CustomFieldName", "CustomFieldValue", themeDisplay, themeDisplay.getUserId());
_log.error("User expando created successfully...");
}catch(Exception e){
_log.error("Problem in ExpandoTable update " + e.getLocalizedMessage());
}
public static void updateColumnValue(long expGroupTableId, String columnName, String value, ThemeDisplay themeDisplay, long groupId){
ExpandoColumn expandoColumn = null;
ExpandoValue expandoValue = null;
try{
expandoColumn = ExpandoColumnLocalServiceUtil.getColumn(expGroupTableId, columnName);
if(Validator.isNotNull(expandoColumn)){
expandoValue = ExpandoValueLocalServiceUtil.getValue(themeDisplay.getCompanyId(),User.class.getName(),ExpandoTableConstants.DEFAULT_TABLE_NAME,columnName,groupId);
if(Validator.isNotNull(expandoValue)){
expandoValue.setData(value);
ExpandoValueLocalServiceUtil.updateExpandoValue(expandoValue);
}else{
ExpandoValueLocalServiceUtil.addValue(themeDisplay.getCompanyId(),User.class.getName(),ExpandoTableConstants.DEFAULT_TABLE_NAME,columnName,groupId,value);
}
}else{
ExpandoColumnLocalServiceUtil.addColumn(expGroupTableId, columnName, ExpandoColumnConstants.STRING);
ExpandoValueLocalServiceUtil.addValue(themeDisplay.getCompanyId(),User.class.getName(),ExpandoTableConstants.DEFAULT_TABLE_NAME,columnName,groupId,value);
}
}catch(Exception e){
e.printStackTrace();
}
}
Check the following posts also:
- http://www.liferay.com/community/forums/-/message_boards/message/23726446
- https://www.liferay.com/community/forums/-/message_boards/message/23428000
HTH.
Thanks and Regards,
Apoorva Prakash
Oriol Mesia, modificado hace 12 años.
RE: expandoValue is Null
Junior Member Mensajes: 64 Fecha de incorporación: 4/04/13 Mensajes recientes
Thank you so much,
your code was great and I use it for adding new Expando's when they're null!
Another Appointment is that I don't used themeDisplay 'cause it's not available from LoginAction.
Cheers!
your code was great and I use it for adding new Expando's when they're null!
Another Appointment is that I don't used themeDisplay 'cause it's not available from LoginAction.
currentUser = PortalUtil.getUser(req);
long userId = PrincipalThreadLocal.getUserId();
long companyId = currentUser.getCompanyId();
long groupId = GroupLocalServiceUtil.getGroup(companyId, "Guest").getGroupId();
long classPK = Long.valueOf(currentUser.getPrimaryKey());
Cheers!