Sunday, February 6, 2011

First Struts Application in Liferay

Table of Contents :

Enviornment   
Steps to Configure Liferay on Local Machine:   
Steps to Configure PluginSDK on local system:   
Steps to setup database in Liferay using Service.xml :   
Creating First Jsp Portlet in Liferay:   
Creating First Struts Portlet in Liferay:   
Advance Struts Portlet Setup   















Enviornment
1.    Liferay Source Code :  5.2.3
2.    Tomcat : apache-tomcat-6.0.26.zip
3.    Eclipse : eclipse-jee-galileo-SR2-win32.exe
4.    Jdk : -   jdk-6u20-windows-i586.exe
5.    Ant : Ant1.8.zip

*** Different environment can cause conflict eg. Liferay 5.2 is non compatible with Tomcat 5.5

Trouble shooting steps:
1.    Check if you have set JAVA_HOME.
2.    Compatibility issue : Liferay 5.1 does not work with Tomcat 6.x
3.    Properties files are properly configured.
4.    Double quotes in word and eclipse are different watch out for “”.
 Steps to Configure Liferay on Local Machine:
2.    Install eclipse -  eclipse-jee-galileo-SR2-win32.exe
3.    Install JDK-   jdk-6u20-windows-i586.exe
4.    Unzip Ant 1.8 at C:/>Ant and create ANT_HOME pointing to C:/>Ant
      JAVA_HOME pointing to C:/>JAVA>JDK..
1.    SET PATH=%PATH%;C:/>ANT>bin;C:/>Java>JDK6.0(what ever is your path)
5.    Create a workspace with directory structure:
1.    C:>Liferay-Portal
i.    >Tomcat
ii.    >workspace
6.    Unzip apache-tomcat-6.0.26.zip at the location Tomcat under liferay folder as mentioned above.
7.    Open eclispse and install subeclipse
i.    From Help menu > Install New Software
ii.    Click on Add
iii.    In name type SVN
iv.    In Location : http://subclipse.tigris.org/update_1.4.x
v.    Click on check box Subeclipse and finish.
8.    Open the svn perspective from and checkout the portal source code.
1.    Right click on Svn repository and add new location svn://svn.liferay.com/repos/public
2.    Put in the password as guest.
3.    Right click and .Check out tag 5.2.3
4.    Place the location as C:>Liferay-Portal/workspace.
9.    Go back to Java perspective.
1.    From Windows Menu>Preference>Java Compiler>Installed Jre > Shift to JDK1.6 instead o f JRE1.6 which was installed on second step.
10.    Do a file search and replace all instances of ${user.name} in workspace with the your name eg. harshal.
11.    Create a app.server.harshal.properties file in portal -same location as app.server.properties.
1.    app.server.type=tomcat
2.    app.server.tomcat.dir=C:/Liferay-Portal/Tomcat
3.    app.server.tomcat.version=6.0
4.    app.server.tomcat.classes.global.dir=C:/Liferay-Portal/Tomcat/lib
5.    app.server.tomcat.lib.endorsed.dir=C:/Liferay-Portal/Tomcat/lib/ext
6.    app.server.tomcat.lib.global.dir=C:/Liferay-Portal/Tomcat/lib/ext
7.    app.server.tomcat.lib.support.dir=C:/Liferay-Portal/Tomcat/lib/ext
8.    app.server.tomcat.support.dir=C:/Liferay-Portal/Tomcat/lib/ext
12.    Create a file build.harshal.properties in portal- same location as  build.properties
1.     ant.build.javac.source=1.6
2.    ant.build.javac.target=1.6
13.    Create a release.harshal.properties in portal - same location as release.properties
1.    lp.ext.dir=C:/Liferay-Portal/workspace/ext
14.    Go to  C:\>Liferay-Portal> Tomcat folder>conf> catalina.properties.
1.    Update common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,${catalina.home}/lib/ext/*.jar
-----Here we have added ,${catalina.home}/lib/ext/*.jar
15.    In Eclipse go to build.xml and doubl click on  start target.
Then double click on build.ext target.
----This will create a ext folder in the workspace.

16.    From eclipse>Windows Menu> Show View> Navigator.
17.    In navigator screen –right click and import ext folder into eclipse.
18.    Install Mysql 5.0 from the location
1.    Download mysql-5.0.22-win32.exe and Install as standard.
2.    mysql-administrator-1.1.9-win
3.    start mysql client command prompt from program files
4.    mysql > drop database if exists lportal;
              create database lportal character set utf8;
             grant all on lportal.* to ‘lportal’@’localhost’ identified by
             ‘lportal’ with grant option;
 Grant all on lportal.* to ‘lportal’@’localhost.localdomain’ identified by ‘lportal’                with grant option;
         // here we are creating a database with user name and password lportal.
19.    Now back in eclipse – in ext folder copy the app.server.harshal.properties, build.harshal.properties at the same location as app.server.properties and build.properties respectively.
20.    In ext/ext-impl/src/ there is a file portal-ext.properties. Add the below lines in this file
##MySql
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&c              haracterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=lportal
jdbc.default.password=lportal
21.    Again do a file search and replace all instances of ${user.name} in workspace with the your name eg. harshal.
22.    Now open the build.xml of ext and double click on clean then double click on deploy.
23.    Once all done. Create a setenv.bat file in tomcat>bin
set JAVA_OPTS=%JAVA_OPTS% -Xms128m -Xmx1024m -XX:MaxPermSize=128m -Dfile.encoding=UTF8 -Duser.timezone=GMT
24.     Start the tomcat server from bin>startup.bat
25.    Go to brower> http://localhost:8080/web/guest.



Steps to Configure PluginSDK on local system:
1.    Create a static project in eclipse.
2.    Download the pluginsdk or check out from the svn
a.    Svn location : svn://svn.liferay.com/repos/public.
b.    Download location : http://www.liferay.com/web/guest/downloads/additional 
--Make sure that the version matches.
3.    Unzip at the location C:/>Liferay-Portal>workspace>PluginSDK.
26.    Open in eclipse. Do a file search and replace all instances of ${user.name} in workspace with the your name eg. harshal.
4.    Create a build.harshal.properties at the same location as build.properties.
a.    app.server.dir=C:/Liferay-Portal/Tomcat
b.    java.complier=C:/Java/jdk1.6.0_20
c.    project.dir=C:/Liferay-Portal/workspace/Plugin SDK
5.    Unzip Ant 1.8 at C:/>Ant and create ANT_HOME pointing to C:/>Ant
a.    SET PATH=%PATH%;C:/>ANT>bin

6.    Go to portlets folder and execute the following command as shown below
C:\Liferay-Portal\workspace\Plugin SDK\portlets>ant -Dportlet.name=hello -Dportl
et.display.name="Hello World" create
---Here portlet hello has been created under portlets.
7.    Now fire > ant deploy
-- this will deploy the portlet
8.    Now this helloword portlet is available at inside the Category Samples. (You know where to go for Category, don’t you?)

Configuration file:
liferay-display.xml: This file describes for Liferay what category the portlet should appear under in
the Add Application window.
             liferay-portlet.xml: This file describes some optional Liferay-specific enhancements
portlet-name The portlet-name element contains the canonical name of the portlet. This needs to be the same as the portlet-name given in portlet.xml
icon Path to icon image for this portlet
instanceable Indicates if multiple instances of this portlet can appear on the same page.
struts-path Tells the portal that all requests with the path ext/library/* are considered part of this portlet's scope.
For example, a struts-path of ext/library will give us access to /ext/library/view in struts-config.xml, but not /ext/reports/view.

       portlet.xml:  This files has the below configuration options.
portlet-name:  The portlet-name element contains the canonical name of the portlet.   Each portlet name is unique within the portlet application. (This is also referred within Liferay Portal as the portlet id)
display-name The display-name type contains a short name that is intended to be displayed by tools. It is used by display-name elements. The display name need not be unique.
portlet-class The portlet-class element contains the fully qualified class name of the portlet.
init-param The init-param element contains a name/value pair as an initialization param of the portlet.
expiration-cache Expiration-cache defines expiration-based caching for this portlet. The parameter indicates the time in seconds after which the portlet output expires. -1 indicates that the output never expires.
supports The supports element contains the supported mime-type. Supports also indicates the portlet modes a portlet supports for a specific content type. All portlets must support the view mode.
portlet-info Portlet-info defines portlet information.
security-role-ref
The securit-role-ref element contains the declaration of a security role reference in the code of the
web application. Specifically in Liferay, the role-name references which role’s can access the portlet.
(A Power User can personalize the portal, whereas a User cannot.)

Steps to setup database in Liferay using Service.xml :
We are taking an example of Reports which is supplied by Liferay ext code.
1.    In eclipse move to location :ext\ext-impl\src\com\ext\portlet\reports\service.xml
2.    In ext-impl >build.xml> build-service-portlets-reports (double click on this target)
i.    I t will create the required folders, following most of the J2EE design patterns.
ii.    It will set up database in mysql as per service.xml.
3.    In eclipse move to location ext\ext-web\docroot\html\portlet\ext\reports you will see 3 files belonging to reports portlet.
4.    In eclipse move to location C:\Liferay-Portal\workspace\ext\ext-web\docroot\WEB-INF
i.    It has configuration files for the reports portlet.
Portlet-ext.xml : Defines the portlet.
Liferay-portlet-ext.xml: Defining custom portlet registration in Liferay portal.
Liferay-display.xml: Shows the category in which the portlet should appear.
Struts-config.xml : Define action mapping on basis of struts.
Tiles-defs.xml: Defining tiles based on the Struts.
Creating First Jsp Portlet in Liferay:

1.    Locate /ext/ext-web/docroot/WEB-INF
Open portlet-ext.xml and place the below code in between </portlet> and </portlet-app>
<portlet>
        <portlet-name>jsp_portlet</portlet-name>
        <display-name>JSP Portlet Introduction </display-name>
        <portlet-class>com.liferay.util.bridges.jsp.JSPPortlet
</portlet-class>
        <init-param>
            <name>view-jsp</name>
            <value>/html/portlet/ext/jsp_portlet/view.jsp</value>
        </init-param>
        <expiration-cache>0</expiration-cache>
        <supports>
            <mime-type>text/html</mime-type>
        </supports>
<resource-bundle> com.liferay.portlet.StrutsResourceBundle
</resource-bundle>
        <security-role-ref>
            <role-name>power-user</role-name>
        </security-role-ref>
        <security-role-ref>
            <role-name>user</role-name>
        </security-role-ref>
    </portlet>

2.    Open liferay-portlet-ext.xml in /docroot/WEB-INF and add the following lines below <!—Custom Portlets -- - >
<portlet>
        <portlet-name>jsp_portlet</portlet-name>
    </portlet>
3.    In eclipse go to location \ext\ext-web\docroot\html\portlet\ext. Create a folder
jsp_portlet
4.    Inside jsp_portlet folder create a file init.jsp. Replace the contents with below contents
<%include file="/html/common/init.jsp" %>
<portlet:defineObjects/>
5.    Inside jsp_portlet folder create a file view.jsp. Replace the contents with below contents.
<%include file ="/html/portlet/ext/jsp_portlet/init.jsp" %>
<a href="http://liferay.cignex.com" title="First Jsp">Jsp Portlet for Palm Tree</a>
<a href="http://liferay.cignex.com" title="Liferay Portal Enterprise Intranets">
<img border="0"   src="http://liferay.cignex.com/palm_tree/PalmTree_logo.png"></img></a>
6.    Get build.xml from ext/ext-web into Ant view. Stop Tomcat server.
Double click on deploy target.
7.    Start Tomcat Server. You will see the jsp portlet in Add application>Undefined Category.
8.    Set the title in Langugate-ext.properties. Open Langugate-ext.properties file in ext/ext-impl/src/content folder.
Add the following line of code after the line javax.portlet.title.EXT_1=Reports
Javax.portlet.title.jsp_portlet= First Jsp
9.    Set the category in liferay-display.xml.   Open liferay-display.xml  file in /ext/ext-web/docroot/WEB-INF folder and open it.
Add the following line of code after the line <portlet id =”EXT_1” />  and save it.
<portlet  id=”jsp_portlet”>
10.    Stop Tomcat Server.
11.    Get build.xml from ext/ext-impl into Ant view.
Double click clean on deploy target.
12.     Get build.xml from ext/ext-web into Ant view.
Double click clean on deploy target.
13.    Start Tomcat Server.
   
---For fast deploy- for the changes made to view.jsp
            Double click the target deploy-fast.
Creating First Struts Portlet in Liferay:
1.    Create a package name com.ext.portlet.bookreports in the ext/ext-impl/src then create a portlet class name BookReportsPortlet.
package com.ext.portlet.bookreports;

import java.io.IOException;

import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import com.liferay.portlet.StrutsPortlet;

public class BookReportsPortlet extends StrutsPortlet {
    public void doView(RenderRequest renderRequest,
            RenderResponse renderResponse) throws IOException, PortletException {
        super.doView(renderRequest, renderResponse);
    }
}

2.    Locate portlet-ext.xml file in the ext/ext-web/docroot/WEB-INF. Add the following line between
</portlet> and </portlet-app>

    <portlet>
        <portlet-name>book_reports</portlet-name>
        <display-name>Book Reports </display-name>
        <portlet-class>com.ext.portlet.bookreports.BookReportsPortlet
</portlet-class>
        <init-param>
            <name>view-action</name>
            <value>/ext/book_reports/view_reports</value>
        </init-param>
        <expiration-cache>0</expiration-cache>
        <supports>
            <mime-type>text/html</mime-type>
        </supports>
        <resource-bundle>com.liferay.portlet.StrutsResourceBundle
</resource-bundle>
        <portlet-preferences>
            <preference>
                <name>Liferay Book</name>
                <value>Liferay Portal Enterprise Intranets</value>
            </preference>
        </portlet-preferences>
        <security-role-ref>
            <role-name>power-user</role-name>
        </security-role-ref>
        <security-role-ref>
            <role-name>user</role-name>
        </security-role-ref>
</portlet>
3.    Now lets configure book_reports in liferay-portlet-ext.xml in /ext/ext-web/docroot/WEB-INF as follows.
<portlet>
        <portlet-name>book_reports</portlet-name>
        <struts-path>ext/book_reports</struts-path>
        <use-default-template>false</use-default-template>
       </portlet>
4.    Create the portlet action class named ViewBookReportsAction which extends PortletAction under com.ext.portlet.bookreports.action package in /ext/ext-impl/src folder.
package com.ext.portlet.bookreports.action;

import java.util.ArrayList;
import java.util.List;

import javax.portlet.PortletConfig;
import javax.portlet.PortletPreferences;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.WindowState;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


import com.liferay.portal.struts.PortletAction;

import edu.emory.mathcs.backport.java.util.Collections;

public class ViewBookReportsAction extends PortletAction{
@SuppressWarnings("unchecked")
public ActionForward render(ActionMapping mapping,ActionForm form, PortletConfig portletConfig, RenderRequest renderRequest,RenderResponse renderResponse)throws Exception{
    if(renderRequest.getWindowState().equals(WindowState.NORMAL)){
        return mapping.findForward("portlet.ext.book_reports.view");
    }
    else{
        List<String> reports = Collections.synchronizedList(new ArrayList<String>());
        PortletPreferences prefs = renderRequest.getPreferences();
        reports.add("1: Prefrences book - " + prefs.getValue("Liferay Book", ""));
        reports.add("2: Window State - " + renderRequest.getWindowState());
        reports.add("3: Portlet Mode -" + renderRequest.getPortletMode().toString());
        reports.add("4: Portlet Session -"+ renderRequest.getPortletSession().getId());
        renderRequest.setAttribute("reports",reports);
        return mapping.findForward("portlet.ext.book_reports.view_reports");
    }
}
}

5.    Locate struts-config.xml file in /ext/ext-web/docroot/WEB-INF . Add the following lines
    <!-- Book Reports Struts -->
<action path="/ext/book_reports/view_reports" type="com.ext.portlet.bookreports.action.ViewBookReportsAction">
<forward name="portlet.ext.book_reports.view"            path="portlet.ext.book_reports.view" />
<forward name="portlet.ext.book_reports.view_reports" path="portlet.ext.book_reports.view_reports" />
        </action>
6.    Locate the tiles-defs.xml in  /ext/ext-web/docroot/WEB-INF. Add the following lines  immediately after <tiles-definitions> and save them
    <definition name="portlet.ext.book_reports.view" extends="portlet">
<put name="portlet_content" value="/portlet/ext/book_reports/view.jsp" />
    </definition>

<definition name="portlet.ext.book_reports.view_reports" extends="portlet">
<put name="portlet_content" value="/portlet/ext/book_reports/view_reports.jsp" />
    </definition>       
7.    Create the /book_reports folder under the /ext/ext-web/docroot/html/portlet/ext folder
a.    Create a init.jsp under the   /ext/ext-web/docroot/html/portlet/ext/book_reports.
<%@ include file="/html/common/init.jsp" %>
<%@ page import = "java.util.List,javax.portlet.PortletPreferences,javax.portlet.RenderRequest" %>
<portlet:defineObjects/>
<%
PortletPreferences prefs = renderRequest.getPreferences();
%>
b.    Create a view.jsp under the   /ext/ext-web/docroot/html/portlet/ext/book_reports.
<%@ include file ="/html/portlet/ext/book_reports/init.jsp" %>
<a href ="<portlet:renderURL windowState="<%=WindowState.MAXIMIZED.toString() %>" />">
Preferce : Liferay Book - <%= prefs.getValue("Liferay Book","") %>
</a>
c.    Create a view_reports.jsp under the   /ext/ext-web/docroot/html/portlet/ext/book_reports
<%@ include file ="/html/portlet/ext/book_reports/init.jsp" %>
<% List reports = (List)request.getAttribute("reports"); %>
<div> <liferay-ui:message key="view-reports" />
<center>
<a href ="http://liferay.cignex.com" title="Liferay Portal Enterprise Intranets">Palm Tree Publication</a>
</center>
<center>
<a href="http://lifreay.cignex.com" title="Liferay Portal Enterprise Intranets">
<img border="0" src ="http://liferay.cignex.com/palm_tree/PalmTree_logo.png"
</a>
</center>
<% for (int i=0; i<reports.size();i++){
String reportName=(String)reports.get(i);
%><%= reportName %>
<br><% } %>
</div>   
8.    To change the title. Locate Language-ext.properties file under /ext/ext-impl/src/content folder and open it and add the following lines
javax.portlet.title.book_reports=Book Reports
view-reports=View Reports for Books
book-reports=Reports for Books
##Category titles
category.book=Book
9.    To change the category. Locate liferay-display.xml file in the /ext/ext-web/docroot/WEB-INF and open it
a.    Add the following lines between </category> and </display> and save the file
</category name="category.book">
    <portlet id="book_reports"/>
    </category>
10.    Stop Tomcat Server.
11.    Get build.xml from ext/ext-impl into Ant view.
Double click clean on deploy target.
12.     Get build.xml from ext/ext-web into Ant view.
Double click clean on deploy target.
13.    Start Tomcat Server.
   
---For fast deploy- for the changes made to view.jsp
            Double click the target deploy-fast.
   

Summary of steps :
1.    Define portlet in portlet.xml.
2.    Inform liferay about the portlet in liferay-portlet-ext.xml.
3.    Configure struts-config.xml
4.    Configure tiles-def.xml
5.    Code for Action and jsp files.
6.    Set the display title Language-ext.properties
7.    Set the category in liferay-display.xml
8.    Redeploy all.






Advance Struts Portlet Setup
1.    Create a AddBookAction inside the package com.ext.portlet.bookreports.action of ext/ext-impl/src.
package com.ext.portlet.bookreports.action;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.struts.PortletAction;

public class AddBookAction extends PortletAction {
    public void processAction(ActionMapping mapping, ActionForm form,
            PortletConfig config, ActionRequest req, ActionResponse res)
            throws Exception {
        String title = req.getParameter("title");
        if (Validator.isNull(title)) {
            setForward(req, "portlet.ext.book_reports.error");
        } else {
            setForward(req, "portlet.ext.book_reports.success");
        }
    }

    public ActionForward render(ActionMapping mapping, ActionForm form,
            PortletConfig config, RenderRequest req, RenderResponse res)
            throws Exception {
        return mapping.findForward(getForward(req,
                "portlet.ext.book_reports.view"));

    }
}

2.    Add the below lines to struts-config.xml
<action path="/ext/book_reports/add_book" type="com.ext.portlet.bookreports.action.AddBookAction">
            <forward name="portlet.ext.book_reports.view"
                     path="portlet.ext.book_reports.view" />
            <forward name="portlet.ext.book_reports.error"
                     path="portlet.ext.book_reports.error" />
            <forward name="portlet.ext.book_reports.success"
                     path="portlet.ext.book_reports.success" />
                           
        </action>
3.    Add the below lines to tiles-def.xml
    <definition name="portlet.ext.book_reports.error" extends="portlet">
        <put name="portlet_content" value="/portlet/ext/book_reports/error.jsp" />
    </definition>

    <definition name="portlet.ext.book_reports.success" extends="portlet">
        <put name="portlet_content" value="/portlet/ext/book_reports/success.jsp" />
    </definition>
4.    Update the view.jsp in folder ext\ext-web\docroot\html\portlet\ext\book_reports
<%@ include file="/html/portlet/ext/book_reports/init.jsp"%>
<a href="<portlet:renderURL windowState="<%=WindowState.MAXIMIZED.toString() %>" />">
Preferce : Liferay Book - <%=prefs.getValue("Liferay Book", "")%> </a>
<br />
<br />
<form
    action="<portlet:actionURL windoState="<%=WindowState.MAXIMIZED.toString() %>" >
    <portlet:param name="struts_action" value="/ext/book_reports/add_book"/>
    </portlet:actionURL>"
    method="post" name="<portlet:namespace />fm">
<div style="color: #12558E">Book Title : <input
    name="<portlet:namespace />title" size="35" type="text" value="">
</input> <input onClick="submitForm(document.<portlet:namespace />fm);"
    style="margin-top: 5px;" type="button" value="Add Book"></input> <br />
</div>
</form>
5.    Create a success.jsp  file with the following content and save it. At location
\ext\ext-web\docroot\html\portlet\ext\book_reports
<%@ include file ="/html/portlet/ext/book_reports/init.jsp" %>
<%String title = request.getParameter("title"); %>
<div style="text-align: cente">
Success ! Book Title: <i> <%=title %></i>
</div>

6.    Create a error.jsp file with the following content and save it. . At location
\ext\ext-web\docroot\html\portlet\ext\book_reports
<%@ include file=”/hmtl/portlet/ext/book_reports/init.jsp” %>
<div sytle=”text-align: center”> Error! The Book Title is null!
</div>
7.    Create a database setup . Located at \ext\ext-impl\src\com\ext\portlet\bookreports
Create a service.xml file as follows
<?xml version="1.0"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 5.2.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_5_2_0.dtd">

<service-builder package-path="com.ext.portlet.bookreports">
    <namespace>BookReports</namespace>
    <entity name="BookReportsEntry" uuid="true" local-service="true" remote-service="true" persistence-class="com.ext.portlet.bookreports.service.persistence.BookReportsEntryPersistenceImpl">

        <!-- PK fields -->

        <column name="entryId" type="Long" primary="true" />

        <!-- Group instance -->
       
        <column name="groupid" type="Long"></column>
       
        <!-- Audit fields -->

        <column name="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 -->

        <column name="name" type="String" />
        <column name="title" type="String"></column>
        <!-- Order -->

        <order by="asc">
            <order-column name="title" case-sensitive="false" />
        </order>

    </entity>
    <exceptions>
        <exception>EntryName</exception>
    </exceptions>
</service-builder>
8.    Locate /ext/ext-impl/build-parent.xml and open it.
Add the following lines
<target name="build-service-portlet-bookreports">
            <antcall target="build-service">
        <param name="service.file" value="src/com/ext/portlet/bookreports/service.xml" />
            </antcall>
        </target>

9.    Get the build-parent.xml into Ant view from /ext/ext-impl and double click on target
build-service-portlet-bookreports
10.    Create a database table follow the steps:
C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql --user=lportal --password=lportal
>Use lportal;
>create table bookreportsentry(uuid_ varchar(75) null,
 entryid bigint not null primary key,
 groupid bigint,
 companyid bigint,
 userid bigint null,
username varchar(100) null,
 createDate datetime null,
 modifiedDate datetime null,
 name varchar(511) null,
 title varchar(511) null);
11.    Now create an action class named BookLocalServiceUtil under com.ext.portlet.bookreports.action
Package  of the /ext/ext-impl/src
package com.ext.portlet.bookreports.action;

import java.util.Date;
import java.util.List;

import javax.portlet.ActionRequest;

import com.ext.portlet.bookreports.model.BookReportsEntry;
import com.ext.portlet.bookreports.service.BookReportsEntryLocalServiceUtil;
import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.PortalException;
import com.liferay.portal.SystemException;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay;

public class BookLocalServiceUtil {
   
    public static BookReportsEntry addBook(ActionRequest req)
            throws PortalException, SystemException {
       
        ThemeDisplay themeDisplay = (ThemeDisplay) req
                .getAttribute(WebKeys.THEME_DISPLAY);
        long userId = themeDisplay.getUserId();
        String title = req.getParameter("title");
        User user = UserLocalServiceUtil.getUser(userId);
        Date now = new Date();
        long bookId = CounterLocalServiceUtil.increment(BookReportsEntry.class
                .getName());
        BookReportsEntry book = BookReportsEntryLocalServiceUtil.createBookReportsEntry(bookId);
        book.setTitle(title);
        book.setGroupid(themeDisplay.getScopeGroupId());
        book.setCompanyId(themeDisplay.getCompanyId());
        book.setUserId(userId);
        book.setUserName(user.getFullName());
        book.setCreateDate(now);
        book.setModifiedDate(now);
        book.setName(title);
        BookReportsEntryLocalServiceUtil.updateBookReportsEntry(book,false);
        System.out.println(book);
        return book;
       
    }

    public static List<BookReportsEntry> getAll() throws PortalException,
            SystemException {
        int end = BookReportsEntryLocalServiceUtil.getBookReportsEntriesCount();
           
        return BookReportsEntryLocalServiceUtil.getBookReportsEntries(0,end);
       
    }
}


12.    Add the following in AddBookAction  inside processAction
BookLocalServiceUtil.addBook(req); above
setForward(req, "portlet.ext.book_reports.success");
13.    Add the following in AddBookAction  inside render before return.mapping.findForward(getForward.(req,”portlet.ext.book_reports.view”));
String title = req.getParameter(“title”);
If(title==null)setForward(req,”portlet.ext.book_reports.view_books”);

14.    For ext\ext-web\docroot\WEB-INF\struts-config.xml file , add the following lines immediately after <!—Book reports -->

        <!-- Book Reports Struts -->
<action path="/ext/book_reports/view_books" type="com.ext.portlet.bookreports.action.AddBookAction">
        <forward name="portlet.ext.book_reports.view"                         path="portlet.ext.book_reports.view" />
        <forward name="portlet.ext.book_reports.view_books"                     path="portlet.ext.book_reports.view_books"/>
        </action>
15.    Similarly for ext\ext-web\docroot\WEB-INF\tiles-defs.xml add the following lines immediately after <!—Book reports -- >
<definition name ="portlet.ext.book_reports.view_books" extends="portlet">
<put name ="portlet_content" value="/portlet/ext/book_reports/view_books.jsp" />
</definition>
16.    Add the following line below <%@ include file="/html/common/init.jsp" %>
In init.jsp file  location ext\ext-web\docroot\html\portlet\ext\book_reports\init.jsp
<%@page import ="com.ext.portlet.bookreports.model.BookReportsEntry" %>
<%@ page import ="com.ext.portlet.bookreports.action.BookLocalServiceUtil" %>


17.    Add the following line below </br> </br>  \ext\ext-
web\docroot\html\portlet\ext\book_reports\view.jsp
<a href="<portlet:renderURL windowState="<%=WindowState.MAXIMIZED.toString() %>">
<portlet:param name="struts_action" value="/ext/book_reports/view_books"/>
</portlet:renderURL>">
View All Books.
</a>
18.    Now we can retrieve records using view_books.jsp. Lets create a view_books.jsp.
\ext\ext-web\docroot\html\portlet\ext\book_reports location.
<%@ include file="/html/portlet/ext/book_reports/init.jsp" %>
<% List books =(List) BookLocalServiceUtil.getAll();
BookReportsEntry book =null;%>
<table style="border: lpx solid #CCC; width; 100%;padding:5px;">
<tr>
<td style="color: #12558E;">Book ID</td>
<td style="color: #12558E;">Group ID</td>
<td style="color: #12558E;">Company ID</td>
<td style="color: #12558E;">User ID</td>
<td style="color: #12558E;">User Name</td>
<td style="color: #12558E;">Title</td>
</tr>
<c:if test="<%=books!=null %>">
<% for (int i=0; i<books.size(); i++ ){
    book=(BookReportsEntry)books.get(i);
    %>
    <tr>
    <td><%=book.getEntryId() %></td>
    <td><%=book.getGroupid() %></td>
    <td><%=book.getCompanyId() %></td>
    <td><%=book.getUserId() %></td>
    <td><%=book.getUserName() %></td>
    <td><%=book.getTitle() %></td>
    </tr>
    <%}%>
</c:if>
</table>




23 comments:

  1. This info is invaluable. Where can I find out more?
    Here is my web blog : Florida white pages directory

    ReplyDelete
  2. It is not my first time to visit this site, i
    am visiting this website dailly and get good facts from here everyday.


    my site new business directory

    ReplyDelete
  3. Hi there, I read your blog daily. Your writing
    style is witty, keep it up!

    Have a look at my web blog - vietnam war research paper

    ReplyDelete
  4. Hi to every body, it's my first visit of this weblog; this weblog carries awesome and genuinely excellent information for readers.

    Review my blog :: 80s halloween costumes

    ReplyDelete
  5. I loved as much as you will receive carried out right here.
    The sketch is tasteful, your authored material stylish.
    nonetheless, you command get bought an nervousness over that you wish be delivering the following.
    unwell unquestionably come more formerly again
    as exactly the same nearly very often inside case you shield this hike.


    Also visit my website ... how to start a research paper

    ReplyDelete
  6. Does your site have a contact page? I'm having a tough time locating it but, I'd like to send you an e-mail.
    I've got some suggestions for your blog you might be interested in hearing. Either way, great blog and I look forward to seeing it grow over time.

    my blog :: transamerica movie discussion

    ReplyDelete
  7. Excellent site. Lots of useful information here. I'm sending it to several pals ans also sharing in delicious. And obviously, thank you on your sweat!

    Have a look at my blog :: local business directory in usa

    ReplyDelete
  8. It's remarkable to pay a visit this website and reading the views of all colleagues on the topic of this paragraph, while I am also keen of getting know-how.

    Here is my blog post - biziness directory

    ReplyDelete
  9. I'll immediately seize your rss feed as I can't in finding your email
    subscription link or newsletter service. Do you have any?

    Kindly allow me understand in order that I could subscribe.
    Thanks.

    My website :: business phone number search

    ReplyDelete
  10. It's going to be finish of mine day, however before finish I am reading this fantastic paragraph to improve my knowledge.

    Stop by my page - cartoon t shirts online india

    ReplyDelete
  11. I know this site gives quality dependent posts
    and other material, is there any other web site which provides these data in quality?


    My weblog: Charlotte remote computer support

    ReplyDelete
  12. Fantastic goods from you, man. I've bear in mind your stuff prior to and you're just too excellent.
    I actually like what you've received right here, really like what you're saying and the way wherein you are saying
    it. You make it entertaining and you continue to care for to keep it wise.

    I cant wait to read far more from you. This is actually a terrific
    site.

    Here is my blog: physics research paper topics

    ReplyDelete
  13. Hello, all the time i used to check weblog posts here early in the morning, for the reason that i love to gain knowledge
    of more and more.

    Here is my blog: history essays

    ReplyDelete
  14. I rarely drop comments, but I read a few of the comments
    here "First Struts Application in Liferay".

    I do have 2 questions for you if you do not mind. Could it be just
    me or does it look like some of these responses appear as if they are left by brain dead
    people? :-P And, if you are writing on additional online social sites, I'd like to follow you. Could you list of all of your public sites like your linkedin profile, Facebook page or twitter feed?

    Here is my webpage writing a college paper

    ReplyDelete
  15. Very nice article, exactly what I needed.

    Feel free to surf to my webpage ... business directory business

    ReplyDelete
  16. Thanks a lot for sharing this with all folks you really recognize
    what you're speaking approximately! Bookmarked. Kindly additionally seek advice from my website =). We may have a link alternate contract among us

    Feel free to visit my homepage :: find a real estate agent

    ReplyDelete
  17. Greate post. Keep writing such kind of info on your site.
    Im really impressed by your site.
    Hello there, You've done an excellent job. I'll certainly digg it and individually recommend to my
    friends. I am sure they will be benefited from this web site.


    My website ... civil war research paper topics

    ReplyDelete
  18. Fine way of describing, and good article to get facts concerning my presentation subject matter, which i
    am going to present in university.

    Feel free to visit my weblog; blog writing service

    ReplyDelete
  19. I just couldn't leave your web site before suggesting that I extremely enjoyed the usual information a person supply on your guests? Is going to be again continuously to inspect new posts

    Also visit my blog; tv cartoon t shirts

    ReplyDelete
  20. Just wish to say your article is as surprising. The clarity on your put up is just great and
    that i could suppose you're an expert on this subject. Fine with your permission allow me to snatch your RSS feed to stay up to date with approaching post. Thank you one million and please carry on the gratifying work.

    Here is my blog post ... local business directories sydney

    ReplyDelete
  21. My programmer is trying to convince me to move to
    .net from PHP. I have always disliked the idea because of the costs.
    But he's tryiong none the less. I've been
    using Movable-type on several websites for
    about a year and am worried about switching to another platform.
    I have heard very good things about blogengine.net.
    Is there a way I can import all my wordpress posts into it?

    Any help would be really appreciated!

    Feel free to surf to my site :: US real estate directories

    ReplyDelete
  22. With havin so much written content do you ever run into
    any issues of plagorism or copyright infringement? My website has a lot of unique content I've either created myself or outsourced but it appears a lot of it is popping it up all over the web without my authorization. Do you know any ways to help stop content from being ripped off? I'd certainly appreciate it.



    Look into my web site; North Carolina computer repair

    ReplyDelete