vendredi 1 novembre 2013

Liferay Creating a Service Layer

Generating a service layer

In this section, we will generate a service layer that will help us to persist the book information whenever it gets added to our system.

Select the project in eclipse and click “New Liferay Service”




In the next popup, give the properties of the service layer we are going to generate like, package
path and Namespace. We recommend the package path to look something like “com.library.slayer”,
where slayer stands for service layer, so that all the generated files go under this package and do not
interfere with the files that we create for the portlet.




Once you click “Finish”, you will see the service.xml file opening as below.




Click the XML tab on this window to see the corresponding XML file.




Now edit the service.xml file by replacing the “entity” element with the following entity definition.


<entity name="LMSBook" local-service="true" remote-service="false">
         <!-- PK fields -->
         <column name="bookId" type="long" primary="true" />
       
         <!-- UI fields -->
         <column name="bookTitle" type="String" />
         <column name="author" type="String" />
       
         <!-- Audit fields -->
         <column name="dateAdded" type="Date" />
</entity>

In this most simplistic service.xml file, we have defined one field as primary key, two UI fields and
one audit field. We have also specified local-service as true and remote-service as false.

Now save the changes and click “Build services” button. If all well you will see the “BUILD
SUCCESSFUL” message on the console as below. If not, something might be wrong. Please go
back and check your service.xml as there could be some syntactical errors.





Now you see the complete list of files that are generated by the service layer.








Suite :  http://rsuna.blogspot.com/2013/11/invoking-service-layer-api.html

0 commentaires:

Enregistrer un commentaire

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More