Subscribe via RSS Feed

Liferay Service builder – Step by Step

February 8, 2013 1 Comment


Liferay Service Builder is a specific feature in Lifray 6.0 which facilitate us database centric Development.

In Liferay Eclipse IDE,

1> Select a new Service Builder Option

2> Create package path and namespace for the service builder

3> Clicking on finish, it will make a Service.xml file for which the Structure will be -

<entityname=“Foo”local-service=“true”remote-service=“true”>

<!– PK fields –>

<columnname=“fooId”type=“long”primary=“true”/>

 <!– Audit fields –>

 <columnname=“companyId”type=“long”/>

<column name=“userId” type=“long” />

<column name=“userName” type=“String” />

<column name=“createDate” type=“Date” />

<column name=“modifiedDate” type=“Date” />

 <!– Other fields –>

 <columnname=“field1″type=“String”/>

<column name=“field2″ type=“boolean” />

<column name=“field3″ type=“int” />

<column name=“field4″ type=“Date” />

<column name=“field5″ type=“String” />

 <!– Order –>

 <orderby=“asc”>

<order-column name=“field1″ />

</order>

 <!– Finder methods –>

 <findername=“Field2″return-type=“Collection”>

<finder-column name=“field2″ />

</finder>

</entity>

Now for a table like UOM with 2 fields uom_id and uom_desc the service.xml file will be -
<entityname=“uom”remote-service=“false”local-service=“true”table=“uom”>

<column name=“uom_id” type=“long” primary=“true”></column>

<column name=“uom_desc” type=“String”></column>

</entity>

4> Run the build-service target in Ant Build.xml

5> It will generate all the necessary files for the service layer.

6> From the Portlet we can access all the useful methods for the service layer such as -

uom uom = new uomImpl(); // new entity object initialisation

uomLocalServiceUtil.adduom(uom);//Add Entity

uomLocalServiceUtil.deleteuom(uom); // Delete Entity

uomLocalServiceUtil.updateuom(uom); // Update Entity

 Except those autogenerated methods, there are ways to write Custom Entity fetch specific code and other codes. But those should be created and used when the code specific in service layer requires to do so.

Enter your email address:

Delivered by FeedBurner

Sign Up to read the rest of the content

Email will be used only for updates of our site

No Thanks