Sun GlassFish Web Space Server 10.0 Developer's Guide

Creating the service.xml File

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

ProcedureTo Create a service.xml File

  1. From the MovieApplication portlet, right click Web Pages and select New.

  2. Click Other.

    The New File wizard appears.

  3. In the Choose File Type pane, choose MovieApp from the Project drop down menu.

  4. Select Sun GlassFish Web Space Server Portlets from Categories and Service Builder XML from File Types.

  5. Click Next.

    The Name and Location window appears.

  6. Specify the File Name as service and click Finish.

    The service.xml file is created inside the web directory. The Design tab is created where you can see the GUI editor for the service.xml.

ProcedureCreating Entities in the service.xml GUI Editor

  1. Click Add.

    The Service Definition window appears.

  2. Specify the Entity Name as Movie and the Table Name for the entity as tb_movie.

  3. Select the Remote Service checkbox and click Add.

    The entity Movie is created with the Remote value as true.

  4. Change the default Package Path name to com.sample.movie.

    After creating an entity, you need to add columns for the entity.

  5. Click Add under the Columns tab.

    The Column Details window appears.

  6. Specify the Name of the column as name and the column type as String.

    You can choose the column type as String, Double, and Date from the drop down list.

  7. Select the Primary Key checkbox and click Add.

    A column is created with the Column Name as name and type as String.

  8. Add three more columns with the Column Types cast, story, and releaseDate with types String, String, and Date respectively.

    You can see that there are four columns created for the Movie entity.

  9. Add another entity called MovieFeedback with the Table Name as tb_moviefeedback.

  10. Add columns such as id, movieName, rating, and feedback with types long, string, string, and string respectively.

    You can see that there are four columns created for the MovieFeedback entity.

    You need to add a Finder method for the MovieFeedback entity.

  11. Click the Finders tab.

  12. Click Add Finder.

    The Finder Details window appears.

  13. Specify the Finder Name as MovieName.

  14. From the Available Columns pane, select movieName and click Add.

    The movieName method is added under the Finder Columns pane. Since the movieName is the finder method, you can search the details of a movie by the name of a movie.

    If you want to set the properties for the finder method, click Properties and choose any Comparators.

  15. Click Add.

    You can see that the finder method is added to the service.xml and the same method appears in GUI editor.

ProcedureGenerating Services

  1. From the service.xml GUI editor, click the Generate Services tab.

    You can see the creation of classes, services, and data models that are required for database interaction.

  2. In the GUI editor, click the Local Methods tab and click Go To Source.

    The local service file for the Movie entity appears.

  3. In the local service class file, add a method called getMovies to return the movies listed in the Movie entity.

    You can use the moviePersistance.findAll method to find the movies present in the Movie entity.

  4. Save the class file.

    In the GUI editor, you can see the getMovies method under the Local Methods tab.

  5. Click Generate Services.

    You can see that all the services are generated again.

ProcedureCreating the View Page for the Movie Data Entry Portlet

  1. From the Projects pane, click the MovieDataEntryPortlet_view.jsp file.

  2. Add code to the MovieDataEntryPortlet_view.jsp file to create a GUI form to specify the movie name, cast, and release date.

    This information is stored in the Movie entity.

  3. From the Projects pane, click the MovieDataEntryPortlet.java file under the com.test folder.

    The MovieDataEntryPortlet.java file appears in the right pane. You can see all the parameters to display the movie details are listed in this file. You can also add other required parameters in this file.

    If you expand the folders in the Project pane, you can see the classes that are automatically generated by the service builder infrastructure. If you click the Files tab, you can see all the .jar and .sql files that are automatically created. When you deploy the portlet on Sun GlassFish Web Space Server 10.0 or Liferay portal server, the .sql files are called and the tables will be created automatically.

ProcedureCreating the MovieList Portlet

  1. Right click on the MovieApp portlet, select New and click Other.

    The New File window appears.

  2. Select Portlet from Categories and Portlet from File Types.

  3. Click Next.

    The New Portlet window appears.

  4. In the Name and Location pane, specify the Class Name as MovieList, Package as com.test, and Portlet Name as MovieList.

  5. Click Next.

  6. In the Create Jsps for Portlet pane, specify the View Jsp as MovieList_view.jsp.

  7. Click Finish.

    The MovieList portlet is created. This portlet lists the movies in the Movie portlet database or Movie entity.

  8. From the Projects pane, click the MovieList_view.jsp file.

    The MovieList_view.jsp file appears in the right pane.

  9. Add code to the MovieList_view.jsp file to create a GUI for the MovieList portlet.

    Using this JSP file, you can fetch all the data from Movie entity from the Movie services class and display the movie details in the GUI form. In this JSP file, you can use the getMovies method to fetch the movie data.

  10. From the Projects pane, right click on the MovieApp portlet and click Run to deploy the portlet.

    The Sun GlassFish Web Space Server server is started. The MovieDataEntry and MovieList portlets are deployed successfully.

  11. In the Sun GlassFish Web Space Server 10.0, login as Admin user.

  12. Add the MovieDataEntry and MovieList portlets in a portal page.

ProcedureAdding Portlets in Sun GlassFish Web Space Server

  1. From the Welcome menu, click Add Application.

    The Add Application window appears. You can see the MovieDataEntry and MovieList portlets under User_Portlets.

  2. Click Add to add the MovieDataEntry and MovieList portlets in the portal page.

  3. In the MovieDataEntry portlet, add new records by specifying movie name, cast, story, and release date.

    You can see that the movie records that you have entered in the MovieDataEntry portlet appears in the MovieList portlet.