フォーラム

ホーム » Liferay Portal » English » 3. Development

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
Rajesh Chaurasia
how to update the expando column for the right key
2011/12/17 23:46
答え

Rajesh Chaurasia

ランク: Regular Member

投稿: 119

参加年月日: 2011/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 ?
Venkat Koppavolu
RE: how to update the expando column for the right key
2011/12/18 22:40
答え

Venkat Koppavolu

ランク: Junior Member

投稿: 85

参加年月日: 2010/07/25

最近の投稿

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
Rajesh Chaurasia
RE: how to update the expando column for the right key
2011/12/19 2:44
答え

Rajesh Chaurasia

ランク: Regular Member

投稿: 119

参加年月日: 2011/08/18

最近の投稿

Thanks for your inputs , I will check and let you know about the outcome
Rajesh Chaurasia
RE: how to update the expando column for the right key
2011/12/21 23:10
答え

Rajesh Chaurasia

ランク: Regular Member

投稿: 119

参加年月日: 2011/08/18

最近の投稿

How can I get the classPK Value ?
Rajesh Chaurasia
RE: how to update the expando column for the right key
2011/12/31 20:40
答え

Rajesh Chaurasia

ランク: Regular Member

投稿: 119

参加年月日: 2011/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());
}
Apoorva Prakash
RE: how to update the expando column for the right key
2011/12/31 21:32
答え

Apoorva Prakash

ランク: Liferay Master

投稿: 659

参加年月日: 2010/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