掲示板

how to update the expando column for the right key

thumbnail
12年前 に Rajesh Chaurasia によって更新されました。

how to update the expando column for the right key

Regular Member 投稿: 183 参加年月日: 11/08/18 最新の投稿
created few custom fields for web content and assigned them default values as per my requirement for intitial stage.
I am displaying these field values in Archive Setting screen that I created as ;part of my use case.In that screen I am allowing it to update the values of custom fieldsa

I am retreiving the individual field values as give below in jsp:
//durationArchiveInactiveSite
Integer durationArchiveInactiveSite = 0;
long jrnlClassNameId = ClassNameLocalServiceUtil.getClassNameId(JournalArticle.class.getName());
long company_id = user.getCompanyId();
ExpandoTable jnrnlTable = ExpandoTableLocalServiceUtil.getDefaultTable(company_id, jrnlClassNameId);
ExpandoColumn jrnlColumn = ExpandoColumnLocalServiceUtil.getColumn(jnrnlTable.getTableId(), "durationArchiveInactiveSite");
String value = jrnlColumn.getDefaultData();
if (value != null) {
durationArchiveInactiveSite= Integer.parseInt(value);
}

I am calling the EditServerAction method with cmd ="archiveSettings" and in the method where I want to update the field values retrieved from jsp page on user edit as below:

int defaultSortOrderForAutogeneratedPortlets = ParamUtil.getInteger(actionRequest, "defaultSortOrderForAutogeneratedPortlets");

//Update the Expando column with correct values
long jrnlClassNameId = ClassNameLocalServiceUtil.getClassNameId(JournalArticle.class.getName());
long company_id = PortalUtil.getCompanyId(actionRequest);
ExpandoTable jnrnlTable = ExpandoTableLocalServiceUtil.getDefaultTable(company_id, jrnlClassNameId);
//Specific Handling for durationArchiveInactiveSite
ExpandoColumn jrnlColumn = ExpandoColumnLocalServiceUtil.getColumn(jnrnlTable.getTableId(), "durationArchiveInactiveSite");
jrnlColumn.setDefaultData(String.valueOf(durationArchiveInactiveSite));
ExpandoColumn eColumndurationArchiveInactiveSite = ExpandoColumnLocalServiceUtil.updateColumn(jrnlColumn.getColumnId(), "durationArchiveInactiveSite", ExpandoColumnConstants.INTEGER, durationArchiveInactiveSite);
eColumndurationArchiveInactiveSite.persist();


But I failed to update the expando column for the right key.

Can someone let me knwo what is wrong ?
12年前 に Venkat Koppavolu によって更新されました。

RE: how to update the expando column for the right key

Junior Member 投稿: 85 参加年月日: 10/07/26 最新の投稿
Hi,

I guess Liferay handles custom attributes through 4 tables
exapandotable, exapandorow, exapandocolumn and exapandovalue.

If we create any custom attributes for any entity like Journal Article from admin UI. values will be stored in (exapandotable, exapandorow, exapandocolumn) and exapandovalue is where exactly stores the values regarding to each journal article.
We can use Liferay API ( ExpandoValueLocalServiceUtil) to manage columnValues from LiferayDB.(since all other infomation is related to table,row and column and created using UI).

ExpandoValue expandoValue = ExpandoValueLocalServiceUtil.getValue(companyId, className, tableName, columnName, classPK); //Getting ExpandoValue EexpandoValue = ExpandoValueLocalServiceUtil.addValue(companyId, className, tableName, columnName, classPK, //Updating

addValue method check the record in exapandocolumn table, if not adds/inserts in it. if exists it will update the record.

See below methods..

public static int getDurationArchiveInactiveSite(long companyId, long classPK) {

int durationArchiveInactiveSite = 0;

try {

String tableName = ExpandoTableConstants.DEFAULT_TABLE_NAME;//is default table for storing custom attributes (exapandotable)
String columnName = "durationArchiveInactiveSite"; //since columnName
String className = JournalArticle.class.getName();

ExpandoValue expandoValue = ExpandoValueLocalServiceUtil.getValue(companyId, className, tableName, columnName, classPK);
String value = expandoValue.getDefaultData();
if (value != null) {
durationArchiveInactiveSite= Integer.parseInt(value);
}
} catch (Exception e) {
durationArchiveInactiveSite = 0;
}

//System.out.println("classPK::" + classPK + "::durationArchiveInactiveSite:" + durationArchiveInactiveSite);

return durationArchiveInactiveSite;
}

public static void updateDurationArchiveInactiveSite(long companyId, long classPK, int durationArchiveInactiveSite) {

try {

String tableName = ExpandoTableConstants.DEFAULT_TABLE_NAME; //is default table for storing custom attributes (exapandotable)
String columnName = "durationArchiveInactiveSite"; //since columnName
String className = JournalArticle.class.getName();

ExpandoValue expandoValue = ExpandoValueLocalServiceUtil.addValue(companyId, className, tableName, columnName, classPK, durationArchiveInactiveSite);
} catch (Exception e) {

}
}
Hope it will help you..

Thanks,
Venkat
thumbnail
12年前 に Rajesh Chaurasia によって更新されました。

RE: how to update the expando column for the right key

Regular Member 投稿: 183 参加年月日: 11/08/18 最新の投稿
Thanks for your inputs , I will check and let you know about the outcome
thumbnail
12年前 に Rajesh Chaurasia によって更新されました。

RE: how to update the expando column for the right key

Regular Member 投稿: 183 参加年月日: 11/08/18 最新の投稿
How can I get the classPK Value ?
thumbnail
12年前 に Rajesh Chaurasia によって更新されました。

RE: how to update the expando column for the right key

Regular Member 投稿: 183 参加年月日: 11/08/18 最新の投稿
Thanks Venkat,your solution helped me and I used it to achieve my reqrmnt.

Below is the way to do it:

1.Create custom field with default data.

2.In jsp pick the value of custom field with default data only if there is no value for that custom field in Expando Value table to that column id else pick this value.

In action class , write the following :
long
company_id = PortalUtil.getCompanyId(actionRequest);
ExpandoTable jnrnlTable = ExpandoTableLocalServiceUtil.getDefaultTable(company_id, jrnlClassNameId);
String className = JournalArticle.
class.getName();
//Specific Handling for durationArchiveInactiveSite
ExpandoColumn jrnlColumn = ExpandoColumnLocalServiceUtil.getColumn(jnrnlTable.getTableId(),
"durationArchiveInactiveSite");
ExpandoValue ev = ExpandoValueLocalServiceUtil.addValue(jrnlClassNameId, jnrnlTable.getTableId(), jrnlColumn.getColumnId(), 0, String.valueOf(durationArchiveInactiveSite));
In jsp write a check to pick Expando value if it exists else pick the default value for that custom field.

Integer durationArchiveInactiveSite = 0;
long jrnlClassNameId = ClassNameLocalServiceUtil.getClassNameId(JournalArticle.class.getName());
long company_id = user.getCompanyId();
ExpandoTable jnrnlTable = ExpandoTableLocalServiceUtil.getDefaultTable(company_id, jrnlClassNameId);

//durationArchiveInactiveSite
ExpandoColumn jrnlColumn = ExpandoColumnLocalServiceUtil.getColumn(jnrnlTable.getTableId(), "durationArchiveInactiveSite");
ExpandoValue ev0 = ExpandoValueLocalServiceUtil.getValue( jnrnlTable.getTableId(), jrnlColumn.getColumnId(), 0);

if (ev0 != null) {
String value = ev0.getData();
durationArchiveInactiveSite= Integer.parseInt(value);
System.out.println("durationArchiveInactiveSite in server.jspf ev:"+durationArchiveInactiveSite.intValue());
}else{
String value = jrnlColumn.getDefaultData();
durationArchiveInactiveSite= Integer.parseInt(value);
System.out.println("durationArchiveInactiveSite in server.jspf non-ev:"+durationArchiveInactiveSite.intValue());
}
thumbnail
12年前 に Apoorva Prakash によって更新されました。

RE: how to update the expando column for the right key

Liferay Master 投稿: 658 参加年月日: 10/06/15 最新の投稿
Hello Rajesh,
Have a look on the following link. It may help you.
http://www.apoorvaprakash.blogspot.com/2010/11/custom-attributes-in-liferay.html
Thanks and Regards,
Apoorva Prakash