« Back

Portal Pack : Write Database Portlet using Service Builder Plug-in

March 16, 2009 By satya ranjan

The service builder framework in Liferay represents the database layer and all the interactions with database are done through service builder infrastructure. So in this blog, I will explain how you can use service builder framework inside your custom portlet using NetBeans 6.5 & Portal Pack 3.0. To use service builder framework, you first need to create a service xml and then generate the required code. The Portal Pack here helps you by providing a nice GUI editor for service.xml file where you can define the entities or database structures and from the same GUI you can generate the services code which can be used inside your portlet.

I have taken an example of Simple Form Submission Portlet here. Using this portlet you can submit customer details which will be stored inside liferay's database and the same portlet will also show the no of customer records present in the database.

First create a Webapplication with "Portlet Support" framework and add a new Portlet to it. Now you need to create the service.xml file. Let's create the portlet application as "CustomerApp" and a portlet "CustomerPortlet" inside it.

Creating the service.xml File

After creating a portlet application, you need to create a service.xml file inside the portlet application.

To Create a service.xml File

  1. From the CustomerApp application, right click on Web Pages and select New > Others > Web Space/Liferay Plugins > Service Builder XML

  2. Enter the file name as service. Make sure the "Folder" is selected as web. Then click Finish.

  3. The service.xml file is created inside the web directory and the IDE opens the service.xml inside the editor area.

You can see two tabs "Design" and "XML" in the editor. The "Design" tab helps the user to add/modify entities through GUI and using "XML", user can directly modify the xml.

Fig: 1


Now we are ready to add entities to our service xml.

To Create Entity

  1. Click on "Add" button.

    The Service Definition window appears. 

  2. Specify the Entity Name as "CustomerDtls" and table name as "CustomerDtls". The Entity name and table name doesn't need to be same.

  3. Now Click "Add". So a new entity called "CustomerDtls" is now created.
  4. Change the default Package Path name to com.sample.customer and namespace to "customer". The namespace should be unique for every portlet application. No two portlet applications should have the same namespace.

Add Columns

After creating an entity, you need to add columns for that entity. So to create columns for an entity

  • Select an entity. 
  • Click "Add" under the Columns tab as shown in the Fig : 3.
 

Fig : 3
  • The Column Details window appears. 
  • Specify the Name of the column as "id" and the column type as long. You can choose the column type as String, Double, and Date from the drop down list. 
  • Select the Primary Key checkbox and click Add. So for this entity, id is the primary key. A column is created with the Column Name as id and type as long
  • Add two more columns with column name name, age with types String, int respectively. 
  • You can see that there are three columns created for the "CustomerDtls" entity. (Fig: 4)
Note: There should be atleast one primary key defined for an entity.
 

                                                    Fig : 4

Add Finder Methods

You can also add your custom finder methods to the entity from "Finders" tab. In "Finders" tab, click "Add Finder" to add finder methods. It provides a GUI where you can select different columns required for your finder methods.(Fig. 5)



Fig. 5

Generating Services

  • From the service.xml GUI editor, click the "Generate Services" button. 
  • You can see the creation of classes, services, and data models that are required for the database interaction. The service api classes are generated under $project/services directory and added to the project classpath. You should not do any modification in those classes as those will be overwritten next time when you run "Generate Service". But the implementation classes which can be modified by the user, are added to the project source path and you can modify them as you want. But after modifying anything in the service implementation classes, you need to run "Generate Service" again.
  • By default the generated service api jar will be bundled inside the portlet war file. But if you want other applications to access your services then the service api jar file needs to be there in the server classpath. You can do that by changing the preference which can be accessed by clicking on "Preferences" button. (Fig: 6)

Fig: 6
  • Now in the GUI editor, click the Local Methods tab. This tab lists local method defined in the local service implementation. Now you can select "Go to Source"  to go the local service implementation. In our example this is "CustomerDtlsLocalServiceImpl.java" file. But we don't need to add any local method for our current example.

Creating the View Page for Customer Portlet

  • From the Projects pane, click the CustomerPortlet_view.jsp file. 
  • Add code to the CustomerPortlet_view.jsp file to create a HTML form to specify the id,name and age of a customer. This jsp also shows the no of customers in the database. Replace the CustomerPortlet_view.jsp code with following code snippets.
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ page import="javax.portlet.*"%>
<%@ page import="com.example.customer.service.*"%>
<%@ page import="com.example.customer.model.*"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>

<portlet:defineObjects />
<%PortletPreferences prefs = renderRequest.getPreferences();%>
<table>
<form method="POST" action="<portlet:actionURL/>">

    <tr>
        <td>Customer ID:</td>
        <td><Input type="text" name="id"/></td>
    </tr>
    <tr>
        <td>Name:</td>
        <td><Input type="text" name="name"/></td>
    </tr>
    <tr>
        <td>Age:</td>
        <td><Input type="text" name="age"/></td>
    </tr>
    <tr>
        <td><Input type="submit"/></td>
    </tr>
</form>
</table>
<H3> No of Customers in Database :
    <%
        out.println(CustomerDtlsLocalServiceUtil.getCustomerDtlsesCount());
    %>
</H3>

 

  • From the Projects pane, click the CustomerPortlet.java file under the com.test package. Add the following code to processAction method. This method gets the data from the browser and add customer details to the database.
public void processAction(ActionRequest request, ActionResponse response) throws PortletException,IOException {
     
        try {
            long id = Long.parseLong(request.getParameter("id"));
            String name = request.getParameter("name");
            int age = Integer.parseInt(request.getParameter("age"));
            CustomerDtls customer = CustomerDtlsLocalServiceUtil.createCustomerDtls(id);
            customer.setId(id);
            customer.setName(name);
            customer.setAge(age);
            CustomerDtlsLocalServiceUtil.addCustomerDtls(customer);
            System.out.println("Added");
        } catch (Exception ex) {
            ex.printStackTrace();
           
        }
    }

 

Deploy And Test

So we are now ready to deploy the portlet application. Right click on the portlet project and select "Deploy" to deploy the portlet on Liferay Portal Server. I am assuming you have selected "Liferay Portal Server"  as runtime for the portlet application. The required table is created automatically during the deployment time, so ideally you don't need to create the table manually. But incase you get "Table not Found Exception" while accessing the portlet, you can run the generated table.sql manually to create the required tables. The table.sql can be found under "WEB-INF/sql" directory.

Now access your liferay portal from the browser and add the new "CustomerPortlet" to a page. You can see a simple form for customer data and below that no of customers in database which is initially "0". Now try to add a customer and after successful addition of data to the database, the "No of Customers in Database" will be changed to 1.
 
Fig: 7

Showing 77 Comments

Jane Eriksson
4/1/09 2:52 AM

This seemed to be a nice example, so I had to try it, but am I suprised ... it did not work emoticon I might be stupid maybe, but now I am really tired of that nothing wont work for me in Liferay development.
Now when I deploy this I get the answer that package com.liferay.util.services does not exist. Where do I get this and how do I get it into Netbeans? I have Liferay 5.2.1, Tomcat, Liferay SDK and Netbeans 6.5.
It is not the only error I get either but the first.
In CustomerPortlet_view.jsp there is an error on the first line. It says for "<%@page contentType="text/html"%>" that package com.example.customer.service and com.example.customer.model does not exist. How do I solve that?
In CustomerPortlet.java there is errors in the processAction method. It says "Cannot find symbol" in CustomerDtls, and the same for setId, setName, setAge and so on.
It would be most greatful if you have the time to give me a hint for what I am doing wrong. I have followed your instructions line by line for two times, so I dont think I have done anything wrong, but probably there is something missin in my installation.

/Jane

satya ranjan
4/1/09 3:39 AM

>>In CustomerPortlet_view.jsp there is an error on the first line. It says for "<%@page >>contentType="text/html"%>" that package com.example.customer.service and >>com.example.customer.model does not exist. How do I solve that?
I hope you have done "Generate Service" . To make sure the services are generated properly, check in your file system if there's a directory called "services" under your project directory and also check the contents of that directory.
It also generate some implementation classes under your source root, just check if those packages exist or not.

Ideally all the generated services classes are automatically added to the project's classpath. You can check the compile library of the project.

Let me know if that helps. If that doesn't work you can send me your project if possible.

Jane Eriksson
4/1/09 5:40 AM

Yes I have done "Generate Service" and I have a directory called serivces with a lot of files in.
I would be glad if you could take a look at my files, but where can I send them? Can I send them to you if I become your friend from your profile? Otherwise you can send an answer to my mailadress, jane.eriksson@miun.se, and I will post the files back to you. Is that ok?

/Jane

Dariusz Sawicki
4/3/09 1:17 AM

I have the same problem.
how to fixed it?

Rui Abreu
4/3/09 9:45 AM

Yap, I got the exact same problem. Any ideas?

satya ranjan
4/3/09 10:10 AM

Are you facing the same "Cannot find Symbol" in java file ? If yes, did you try fixing import by fix import option. (Right click on editor > Fix Imports).

Have you selected the project's target runtime as Liferay Server ?

Rui Abreu
4/4/09 8:05 AM

Hi Satya,

I just did what you suggested. The Fix Imports option doesn't do anything.
And the project's runtime is a Liferay Server. I can deploy portlets to my Liferay instance.

Cheers

satya ranjan
4/4/09 8:19 AM

If possible send me your sample project to me. I will check that. Also you can send me the screenshot of exact error.
my mail id is ranjansatya at gmail dot com

Jane Eriksson
4/4/09 2:11 PM

The "Fix import" fixed one kind of error for me, but now get an other error about a missing package called com.liferay.util.service. Is there anyone who gets that error to?
I have Netbeans 6.5.1 and Liferay Plugins SDK 5.2.2. Can it depend on Netbeans or what?

Brant Levinson
4/5/09 9:47 AM

This is really great, it was working fine, I added the Columns then clicked on "Generate Services". It generated all the classes and I could see the newly generated source code in the folders although the Columns went blank and when I clicked "Add" in "Columns" section again nothing happened. The Design does not match the XML. I've attempted to make a new project then deleted them all and reinstalled several times and I still get the same result.
I running this on a mac, any ideas?

Brant Levinson
4/5/09 6:00 PM

I have submitted a bug to NetBeans.org. I also tried this on a windows machine (vista) and it wouldn't let me click "Add" even the first time I tried it. PLEASE HELP.
http://www.netbeans.org/issues/show_bug.cgi?id=162004

satya ranjan
4/5/09 10:24 PM

Jane,

Make sure you have selected the target runtime as "Liferay Portal Server" for the project. When you set the server as LR, then only portal-service.jar (required for com.liferay.util.service package) is added to the project's compile classpath.

Thanks !!!

satya ranjan
4/5/09 10:32 PM

Brant,

Thanks for filing the issue. First you have to select any entity in "Entity" section and then you have to click "Add Column" in column section to add new columns. Sometime after adding columns, the focus goes away automatically from the selected entity and you see blank column section (it's a bug). You have to select a particular entity first to see the columns defined for that entity and then click add to add column. Hope that helps !!
Let me know if it works for you..

Jane Eriksson
4/6/09 12:03 AM

Hi,
do you mean that I must have "Liferay Portal Server" chosen as server for the project? If that is what you mean I already have that and have had so all the time for this project.
The file portal-service.jar does not exist in my LiferaySDK environment at all. Is that wrong? I made a search in the Liferay portal environment and then I found it under \liferay-portal-5.2.1\tomcat-5.5.27\common\lib\ext.

Jane Eriksson
4/6/09 12:11 AM

Me again ...
I just want to add that in my project CustomerApp opened in NetBeans I can see the file portal-service.jar under Libraries/Liferay Portal Server 5.1.x/5.2.x, so that must be correct, or ...

satya ranjan
4/6/09 12:39 AM

Jane,

Sorry for the confusion, the com.liferay.util.service package is there inside util-java.jar file. I tried with LR 5.2.2 (with Tomcat 5.5 bundle) and I could see the util-java.jar under the Libraries/Liferay Portal Server. You can expand util-java.jar to see the com.liferay.util.service package. But in someway if your IDE still doesn't recognize that package, I would suggest you to remove the liferay server from IDE and then reconfigure it again.

Let me know if that solves your issue.

Jane Eriksson
4/6/09 5:46 AM

Hi,
That did it as a matter of fact ... emoticon
I didn´t have any util-java.jar at all under Libraries/Liferay Portal Server, but when I did as you kindly told me, removed the Liferay server and added it again, and after a restart of Netbeans it was there. Strange, is´nt it? I was then able to Run the project and could finally test the new portlet.
I have some questions thow:
1. Where does the information go that I add in the portlet? I cant find it.
2. When I run the project two pages of Liferay was opened. Why?
3. I still get some errors about zip-files that cant be opened and servlet default threw exception java.lang.NullPointerException and some warnings to.
Is it possible to also send you the error-file and maybe get some tip again about what it can be. As I said I can run the project now, but it doesnt feel good with the errors.

Thanks again!

Rui Abreu
4/6/09 6:12 AM

Well, the util-java.jar wasn't under Libraries/Liferay Portal Server, but I found in another location in the Liferay folder: /util-java. I imported it to the project and everything seems to work.

Thanks a lot emoticon

satya ranjan
4/6/09 11:20 AM

Jane,

Good to hear that it worked. Strange, how the util-java.jar got removed automatically first time.
>>1. Where does the information go that I add in the portlet? I cant find it.
Do you mean output ? If yes, then you need to add that portlet on your portal page using "Add Application".

>>2. When I run the project two pages of Liferay was opened. Why?
Not sure. Sometime when the liferay is started in the developer mode it starts the browser automatically. Also netbeans launches browser after server restart from IDE. May be both are happening in your case. To avoid this, you can do only "Deploy" instead of "Run". And later go to the browser to see the output.

>>3. I still get some errors about zip-files that cant be opened and servlet default threw exception java.lang.NullPointerException

Send me the error log to my mail id.
Thanks !!!

Brant Levinson
4/6/09 12:25 PM

I needed to select the "Entity" for it to work. Yay! Thanks for you help, it looks like it works fine.

Brant Levinson
4/6/09 1:09 PM

Okay, I had the same issue as above where I had to add in the java-util but after doing that I still get an issue with the added code:
/Users/Brant/NetBeansProjects/CustomerApp/src/java/com/test/CustomerPortlet­.java:21: cannot find symbol
symbol : class CustomerDtls
location: class com.test.CustomerPortlet
CustomerDtls customer = CustomerDtlsLocalServiceUtil.createCustomerDtls(id);

I have CustomerDtlsServiceImpl but no CustomerDtlsLocalServiceUtil, was this supposed to be created? I am using the PortalPack 3.0.

Brant

Brant Levinson
4/6/09 1:09 PM

I meant "util-java.jar" opposed to "java-util".

Brant Levinson
4/6/09 3:36 PM

Fix Imports fixed this.

Brant Levinson
4/6/09 4:06 PM

Okay, this is hopefully the last issue. When I click deploy I get this in the console:
init:
deps-module-jar:
deps-ear-jar:
deps-jar:
library-inclusion-in-archive:­
library-inclusion-in-manifest:
compile:
compile-jsps:
/Users/Brant/NetBeansProjects­/CustomerApp/nbproject/build-impl.xml:552: Problem: failed to create task or type nbdeploy
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
BUILD FAILED (total time: 0 seconds)

satya ranjan
4/6/09 11:58 PM

Brant,

Regarding your deploy issue, I am not sure why it's happening as it's not reproducible always. I could see some forum posts on that issue but got no answer
http://forums.netbeans.org/post-29506.html
http://forums.netbeans.org/ptopi­c4031.html

I will try to investigate what exactly is going wrong in your case ? (Looks like this issue is only on MAC sometimes)

Meanwhile could you please try to see if you can deploy a normal web application on Glassfish server from your NetBeans IDE ?

Thanks,

Jane Eriksson
4/7/09 12:00 AM

Satya,
>>1. Where does the information go that I add in the portlet? I cant find it.
Maybe a stupid question ... I have added the portlet to my portal and have added a couple av names and can se that it works. The number of customers in the Database increases as it should, but I want to look in the Database and se the posts from there. Where is the Database so I can watch them?
I will send the mail with my errors then.
Thanks again!

satya ranjan
4/7/09 12:11 AM

Jane,
You could see the data using NetBeans's database explorer or if you are using MySQL DB then you could query mysql. But if you are using HSQL DB (default DB in Liferay) you need a HSQL DB explorer or you can configure your NetBeans's DB explorer to show your HSQL DB.

Brant Levinson
4/24/09 11:58 AM

I was able to take the war file created and copy it to the deploy folder. I'm quite dependent on Tomcat as I have a number of other webapps.

Brant Levinson
4/24/09 12:00 PM

I am not able to see the JSON service being generated. Is this supposed to be accessible during generation. How do I get access to the JSON service for using remote clients.

Regards,
Brant

Tony Lim
4/24/09 1:57 PM

Great tutorial on using the portalpack service utility.

Can you extend it and show us how to Update, Delete and View the data?

Thanks!

Tony Lim
4/24/09 5:35 PM

Do you know how to show the list in a search container?

Like this one? "http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/SearchContainer"

satya ranjan
4/27/09 2:21 AM

Currently the JSON services are not being generated for services in a stand alone portlet. But if you find any way to make the json service work in external portlet, please let me know.

satya ranjan
4/27/09 2:22 AM

>>Great tutorial on using the portalpack service utility.
>>Can you extend it and show us how to Update, Delete and View the data?

I will try to write a new blog which will cover these.

satya ranjan
4/27/09 2:28 AM

This wiki explain everything about Search Container.
Here is a sample code snppet where I am showing the list of movies from databse. Hope it will be useful for you.

<%
List headers = new ArrayList();
headers.add("Movies");
headers.add("Release Date");
SearchContainer sc = new SearchContainer();
sc.setHeaderNames(headers);
sc.setEmptyResultsMessage("No movies found");

List resultRows = sc.getResultRows();

Collection<Movie> movies = MovieLocalServiceUtil.getMovies();
Iterator it = movies.iterator();
int i =0;
while (it.hasNext()) {
Movie m = (Movie) it.next();
ResultRow row = new ResultRow(m.getName(), m.getName(), i++);
PortletURL url = renderResponse.createActionURL();
url.setParameter("movie_name", m.getName());
row.addText(m.getName(), url);
Date d = m.getReleaseDate();
String ds = "";
if(d != null)
ds = d.toString();
row.addText(ds);
resultRows.add(row);
}
%>

<ui:search-iterator searchContainer="<%=sc%>"/>

Rui Abreu
5/11/09 4:02 AM

Hi,

I've been following your tutorial and everything works great. But instead of letting the user specify the customer ID, I want to use the Counter Service.
I'm able to deploy this version with no erros, but I always get execution errors.
Have you ever used Counter Service?

Rui Abreu
5/14/09 8:25 AM

Hello again,

Regarding my last post, the issue is fixed.
Now, regarding your last post on SearchContainer, I have some doubts emoticon

Is the code you posted enough to display the table contents or is there something missing?

Cheers mate

vijay krishna kudva
5/21/09 5:02 AM

This example didnt work for me emoticon for portalpack3.01) Allthough it worked for beta version.
Don know what is the problem. Compiles successfully but doesnt get deployed on liferay 5.2.2 through netbeans.
But if i copy the war file direcly to the tomcat depoy folder it works!

Satish Iyer
6/9/09 1:37 AM

Informative.
Is there a similar set of instructions with eclipse?

Joss Sanglier
7/15/09 3:57 AM

This I am looking forward to. Since I am not a programmer, this entire system is perfect to allow me to use Liferay as an important part of the MMO I work for.

I have now evaluated around 20 systems, and I am hoping that the easy portlet development you are championing will mean that Liferay is our final choice.

tore gard andersen
7/19/09 2:14 PM

Did not manage to generate service. I got this message:

classpath could not be modified
please add $project_dir/service/glasses folder to your project classpath
but don't pakage this folder in your webapp war

tore gard andersen
7/19/09 3:49 PM

used Glassfish ESB v2.1 (netbeans 6.5.1). Installed netbeans 6.5.1. Then "Generate Services worked.

N. Belo
7/29/09 11:14 AM

This is a great tutorial, it shows what I exactly needed to work with liferay database in my portlets with changing the ext environment.

Now I have 2 issues:
- In the jsp file(view mode) the: out.println(CustomerDtlsLocalServiceUtil.getCustomerDtlsesCount()); is not showing the actual record count number. But i've tried to debug this inside the java code by simply
System.out.println(CustomerDtlsLocalServiceUtil.getCustomerDtlsesCount());­
and the value is correct there. Why isn't this value updated in the jsp ???

Other problem is about the database connection. I would like to have my portlets working with a different database different from the one that liferay uses.
How can I specify that???

Thank you.

John-Paul Drawneek
8/9/09 12:09 PM

using liferay 5.2.3 tomcat 6 bundle with netbeans 6.7.1, portal pack 3.0.1.

Got the service generation to work once, and managed to get this portlet deployed.

Tried to do it again and it failed with: Exception in thread "main" java.lang.NoClassDefFoundError: com/liferay/portal/tools/servicebuilder/ServiceBuilder

Any ideas why this has happened, and which jar ServiceBuilder is in.

satya ranjan
8/10/09 12:37 AM

Just check if the target runtime for your application is still "Liferay Portal Server". The ServiceBuilder class is there inside portal-impl.jar which automatically gets added to the netbeans project classpath whenever Liferay Portal Server is selected as target runtime.

John-Paul Drawneek
8/11/09 2:34 PM

Thanks for the reply.

From the look I got the portal auto deploy dir wrong so it was looking in the wrong place.

MohdFaizul Sulaiman
8/17/09 2:48 AM

Hi Satya,

I have follow all your instruction but it is not working at all.

In the jsp, there is no method "getCustomerDtlsesCount()". It is not generated in CustomerDtlsLocalServiceUtil. Same with the CustomerPortlet. No methods "addCustomerDtls(customer)" and "createCustomerDtls(id)" in CustomerDtlsLocalServiceUtil class.

However, I found the create() method in CustomerDtlsPersistenceImpl.class and
the addCustomerDtls() and getCustomerDtlsesCount() in CustomerDtlsLocalService.class.

I believe this CustomerDtlsLocalServiceUtil is autogenerated and can't be edited like the Impl classes. Can you tell me whats wrong with the code?

I'm using Liferay 5.1.1 and netbeans 6.5.

Thanks

N. Belo
8/18/09 10:14 AM

Hi,

Do you have any sugestion on how to add a table column as a Foreign Key (Which is a Primary Key from other table) ?

Thanks.

Jim Klo
10/5/09 6:40 PM

Is there a way to expose the services generated within the plugin to Velocity via Web Content Portlet?

R charan
10/15/09 11:00 PM

hi satya,

i have created a portlet using netbeans. i had generated the service also, all the classes generated in service folder but not in project dir, and also no methods are created in ..LocalServiceUtil class.

see here
http://www.liferay.com/web/guest/community/forums/-/message_boards/message/41465­47

satya ranjan
10/15/09 11:25 PM

The Util classes are generated under services/ folder and the service.jar is created from that folder. And the implementation sources are there inside your project directory.

The Util class under services folder should have atleast setService() & getService() method initially. (Assuming you are using Liferay 5.2.3)

R charan
10/19/09 10:07 PM

hi faizul,
iam facing same problem. Methods in util class are not generated , only set and getService methods are present. iam also using netbeans 6.5, portal 5.1.1 and portal pack 3.0.1.

did u get the solution ?

paul francis cunningham
11/3/09 1:25 AM

With Netbeans 6.5.1 and 6.8 beta the add column button does nothing.
Is this an known issue.
I would like to try this example.
Does it work on any version Netbeans.?

satya ranjan
11/3/09 1:42 AM

Make sure you have selected entity name while clicking "add column" button.

Joss Sanglier
11/4/09 3:23 PM

I have just gone to the Portal Pack website and it is now a blog aggregation called Planet Netbeans.

Where has the portal pack gone?

satya ranjan
11/4/09 10:12 PM

The migration for netbeans.org is going on. It will be done by 9th Nov. Check this blog
http://blogs.sun.com/lukas/entry/page_not_found_at_netbeans

Joss Sanglier
11/12/09 3:41 PM

Thanks Satya, but I still cant find it - Do I assume that it has not been migrated yet?

Also, how are you going with the tutorial for update, delete, view and so on??? *Large cheesy hopeful grin*

satya ranjan
11/13/09 8:25 AM

>>Thanks Satya, but I still cant find it - Do I assume that it has not been migrated yet?

Yes the portal pack migration is not done yet. It should be done by next week. I will post a message here once done.

Nicolas Grolleau
11/27/09 2:54 PM

Thanks for this interesting article!

In the design mode there are several options that I can't find : reference, mapping-table...
Is it I didn't search well or are those options not supported yet?

Portal pack sure seems amazing emoticon

Dariusz Sawicki
12/10/09 3:45 AM

How I can chenge lenght of column.
I create service.xml when i clikck is always for typ=String generate lenght 75.
Can you give me instructions how I can change it?

Regards

Al Zoid
12/16/09 7:05 AM

I'm getting an error using Netbeans 6.8.

I downloaded the Glassfish Bundle for Liferay 5.2.3.

I set up the bundled Glassfish as my Websynergy server.

When I click Generate Service I get the following dialog and error:


Classpath could not be modified.
Please add $project/service/classes folder to your project class path
But dont package this folder in your webapp war.


C:\LifeRayDev\UserExt\web\.service.properties
build-service:
C:\liferay-portal­-5.2.3\glassfish\domains\domain1\applications\WEB-INF\lib
C:\Users\usr29587\.netb­eans\6.8\servicebuilder\build-service.xml:74: C:\liferay-portal-5.2.3\glassfish\domains\domain1\applications\WEB-INF\lib not found.
BUILD FAILED (total time: 0 seconds)

Do you have any suggestions on what is going wrong?

Oleg Derid
2/7/10 3:28 PM

Thanks man, the Fix Imports netbeans feature has resolved the trouble.

Charmaine Rebollido
2/9/10 9:27 PM

This tutorial is great, can anyone help me or teach me on how to retrieve data from liferay's database using the same method as mentioned above.

I did the tutorial and it is working, now, what I want to do is retrieve the stored data and display it in the portlet via a table for viewing.

Thanks in advance! I'd really appreciate any help. emoticon

Klaus Zimmer
3/9/10 2:17 AM

For placing tables in a different datasource than in liferays' scheme, what do we need to add or change to the exaples above?

BTW, excellent introduction. Works fine for me.

Sonali Prasadinie Mendis
3/23/10 5:06 AM

Hi,
This is a really good blog. It worked fine for me.
But I need a clarification regarding how to clear the database. I redeployed the portlet but the values in the database have not been cleared.

Thanks!

Andrey Siver
3/28/10 2:59 AM

Are there any examples on how to build remote method (and how to build a client for it)?

David Peng
6/30/10 11:45 AM

Follow the instruction, try to generate service, found the error message, can not move forward, any idea.

${service.property.file}
build-service:
G:\java\liferay-portal-6.0.2\tomcat-6­.0.26\webapps\ROOT\WEB-INF\lib
Loading jar:file:/G:/java/liferay-portal-6.0.2/tomcat-6.0.26/webapps/ROOT/WEB-INF/lib/po­rtal-impl.jar!/system.properties
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.liferay.portal.configuration.ConfigurationImpl.<init>(ConfigurationImpl.java­:122)
at com.liferay.portal.configuration.ConfigurationImpl.<init>(ConfigurationImpl.java­:63)
at com.liferay.portal.util.PropsUtil.<init>(PropsUtil.java:90)
at com.liferay.portal.util.PropsUtil.<clinit>(PropsUtil.java:231)
at com.liferay.portal.util.PropsValues.<clinit>(PropsValues.java:29)
at com.liferay.portal.spring.util.SpringUtil.loadContext(SpringUtil.java:46)
at com.liferay.portal.util.InitUtil.initWithSpring(InitUtil.java:132)
at com.liferay.portal.tools.servicebuilder.ServiceBuilder.main(ServiceBuilder.java:­106)
Caused by: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: No suitable Log constructor [Ljava.lang.Class;@1ef8cf3 for org.apache.commons.logging.impl.Log4JLogger (Caused by java.lang.NoClassDefFoundError: org/apache/log4j/Category) (Caused by org.apache.commons.logging.LogConfigurationException: No suitable Log constructor [Ljava.lang.Class;@1ef8cf3 for org.apache.commons.logging.impl.Log4JLogger (Caused by java.lang.NoClassDefFoundError: org/apache/log4j/Category))
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:5­43)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:2­35)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:2­09)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
at com.germinus.easyconf.EasyConf.<clinit>(EasyConf.java:33)
... 8 more
Caused by: org.apache.commons.logging.LogConfigurationException: No suitable Log constructor [Ljava.lang.Class;@1ef8cf3 for org.apache.commons.logging.impl.Log4JLogger (Caused by java.lang.NoClassDefFoundError: org/apache/log4j/Category)
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.­java:413)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:5­29)
... 12 more
Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/Category
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.getConstructor(Class.java:1657)
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.­java:410)
... 13 more
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Category
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
... 18 more
Java Result: 1
Warning: skipping zip archive F:\liferay\dev\portlet\customerapp\service\lib\customerapp-service.jar because no files were included.
${service.property.file}
copy-jar:
Incase the generated source files are not visible under 'Source Packages' node, then reopen the project again to see the generated files under 'Source Packages'.
BUILD SUCCESSFUL (total time: 36 seconds)

Jim Klo
6/30/10 12:01 PM

David, This looks like log4j.jar isn't on your classpath for running the service builder.

DarshanKumar N Bhatia
7/6/10 6:16 AM

Hi satya ranjan

May I have complete Video download of your seminar for Portal pack.
I know you have given seminar/presentation somewhere out side of india.

Thanks
Darshan

Arun Kumar Ramachandran
8/2/10 9:37 PM

Hi,
What are the things need to install for this development?
I installed netbeans, portal pack, liferay plugin,service builder plugin any more else..

Arun Kumar Ramachandran
8/3/10 2:08 AM

Hi,
I am developing portlet-Database connection using Netbeans 6.5 & Portal Pack 3.0. I am following the liferay blog tutorial LINK.

I almost complete the service.xml part but when i click Generate service button in GUI. I face an error. Please select Glassfish server for liferay portal. But i am using tomcat 6.0.18 for my liferay portal. Could anybody help me to fix this problem?




Thanks
Arun

Arun Kumar Ramachandran
8/4/10 12:44 AM

Hi,
I follow the steps, when i generate service. It shows an error " please select the target runtime as sun glassfish web space /liferay portal". I am using liferay 5.2.3 tomcat bundled version ,netbeans 6.5,portal pack 3.0.1 version. kindly help me fix this problem



Thanks
Arun

Arun Kumar Ramachandran
8/11/10 11:15 PM

Hi,
I done this successfully. I need to add more entity and write query for that. Which file i need to change.



Thanks
Arun

long vu
11/8/10 12:14 AM

Hi all
I want to create some custom queries with service builder because the methods they provide is not enough. Is it possible ?

N. Belo
11/8/10 6:02 AM

The queries you can build easily in service builder are Finders that can be defined for each attribute of your table.

You should create your custom queries, in e.g:
CustomerDtlsServiceImpl define your method signature and contents there.
The query can be built using DynamicQuery class methods
Search for samples for the usage of that.

And finally you should run service builder again so your methods can be used by the CustomerDtlsLocalServiceUtil

NB

7/12/11 5:09 PM

[...] Hi friends I want to write a portlet that works with the database. And I want to use the resources of the liferay. It seems to me that I can use a special service... I found something here:... [...] Read More

8/10/11 6:21 AM

[...] The service builder framework in Liferay represents the database layer and all the interactions with database are done through service builder infrastructure. So in this blog, I will explain how you... [...] Read More

11/22/11 8:54 AM

[...] Hi, Have you check this article for interaction with database. As modifying a table,requires re-generating service classes by using service builder xml file. Also check expando concept for extending... [...] Read More