Introduction-:
Liferay provide us custom attributes which help us to add additional fields to existed models/entities.
This help's us to add some more additional attributes to existed entities so that we can meet your requirements.
Expando represents objects whose member can be added and removed dynamically at run time.
Liferay Expando API-:

These are the default table which we get while installing liferay.
Expando Table-:
-- Table: expandotable
CREATE TABLE expandotable
(
tableid bigint NOT NULL,
companyid bigint,
classnameid bigint,
name character varying(75),
CONSTRAINT expandotable_pkey PRIMARY KEY (tableid)
)
Expando Row-:
-- Table: expandorow
CREATE TABLE expandorow
(
rowid_ bigint NOT NULL,
companyid bigint,
modifieddate timestamp without time zone,
tableid bigint,
classpk bigint,
CONSTRAINT expandorow_pkey PRIMARY KEY (rowid_)
)
Expando Column-:
-- Table: expandocolumn
CREATE TABLE expandocolumn
(
columnid bigint NOT NULL,
companyid bigint,
tableid bigint,
name character varying(75),
type_ integer,
defaultdata text,
typesettings text,
CONSTRAINT expandocolumn_pkey PRIMARY KEY (columnid)
)
Expando Value-:
-- Table: expandocolumn
CREATE TABLE expandocolumn
(
columnid bigint NOT NULL,
companyid bigint,
tableid bigint,
name character varying(75),
type_ integer,
defaultdata text,
typesettings text,
CONSTRAINT expandocolumn_pkey PRIMARY KEY (columnid)
)
In this Example we are adding two columns-:
-> myOrganizationId
-> myContactId
Liferay provide us custom attributes which help us to add additional fields to existed models/entities.
This help's us to add some more additional attributes to existed entities so that we can meet your requirements.
Expando represents objects whose member can be added and removed dynamically at run time.
Liferay Expando API-:
These are the default table which we get while installing liferay.
Expando Table-:
-- Table: expandotable
CREATE TABLE expandotable
(
tableid bigint NOT NULL,
companyid bigint,
classnameid bigint,
name character varying(75),
CONSTRAINT expandotable_pkey PRIMARY KEY (tableid)
)
Expando Row-:
-- Table: expandorow
CREATE TABLE expandorow
(
rowid_ bigint NOT NULL,
companyid bigint,
modifieddate timestamp without time zone,
tableid bigint,
classpk bigint,
CONSTRAINT expandorow_pkey PRIMARY KEY (rowid_)
)
Expando Column-:
-- Table: expandocolumn
CREATE TABLE expandocolumn
(
columnid bigint NOT NULL,
companyid bigint,
tableid bigint,
name character varying(75),
type_ integer,
defaultdata text,
typesettings text,
CONSTRAINT expandocolumn_pkey PRIMARY KEY (columnid)
)
Expando Value-:
-- Table: expandocolumn
CREATE TABLE expandocolumn
(
columnid bigint NOT NULL,
companyid bigint,
tableid bigint,
name character varying(75),
type_ integer,
defaultdata text,
typesettings text,
CONSTRAINT expandocolumn_pkey PRIMARY KEY (columnid)
)
In this article we will do all the expando related operations on Organization entity. we are going to use 4 LocalServices for all the operations
- ExpandoTableLocalServiceUtil
- ExpandoRowLocalServiceUtil
- ExpandoColumnLocalServiceUtil
- ExpandoValueLocalServiceUtil
1. Add Expando Table
Use this method ExpandoTableLocalServiceUtil.addTable(className, name)
Class Name-: Organization
Name-: CUSTOM_FIELD
Table table = null;
table = ExpandoTableLocalServiceUtil.addTable(Organization.class.getName(), "CUSTOM_FIELDS");
2. Add Expando Column
In this Example we are adding two columns-:
-> myOrganizationId
-> myContactId
Use this method ExpandoColumnLocalServiceUtil.addColumn(tableId, name, type)
TableID-: generated from previous step
Name-: name of the col
type-: we can get various type col from ExpandoColumnConstants.java
ExpandoColumnLocalServiceUtil.addColumn(table.getTableId(), myOrganizationId, ExpandoColumnConstants.LONG);
ExpandoColumnLocalServiceUtil.addColumn(table.getTableId(), myContactId, ExpandoColumnConstants.LONG);
ExpandoColumnLocalServiceUtil.addColumn(table.getTableId(), myContactId, ExpandoColumnConstants.LONG);
3. Add Expando Row
Use the method ExpandoRowLocalServiceUtil.addRow(long tableId, long classPK) to add expando row.
TableId-: This is the id of the table that we generated in the Step 1.
ClassPK-: This is generally primary key of particular record of the Entity for which we are adding row. In our case userId is the classPK
ExpandoRowLocalServiceUtil.addRow(expandoTable.getTableId(), user.getUserId());
4. Add Expando Value
ExpandoValueLocalServiceUtil.addValue(long classNameId, long tableId, long columnId, long classPK, String data)
ClassNameId : In our case the classNameId is the ID for the class User
TableId: Its the table ID which is created in Step 1
ColumnId : Its ID for the column which is generated in Step 2
ClassPK : Its the primary key of the record in User. In our user.getUserId is the classPK
Data : Its the actual expando value
ExpandoValueLocalServiceUtil.addValue(classNameId, expandoTable.getTableId(),expandoColumn.getColumnId(), user.getUserId(), "MyOrganizationColumnData");
Comments
Post a Comment