Archive

Archive for February, 2009

Liferay Portlet Development PDF’s

February 28, 2009 rajcheram Comments off

Liferay Struts Portlet Development – 2

February 28, 2009 rajcheram 2 comments

Liferay Struts Portlet Development – 2

Pre Request: Struts Fraework

Aim. Adding Action classes to library portlet and database insert

1.portlet-ext.xml entry

<portlet>
<portlet-name>addbook</portlet-name>
<struts-path>ext/library</struts-path>
<use-default-template>false</use-default-template>
</portlet>

2. addBook.jsp inside “/html/portlet/ext/library”

<%@ include file=”/html/portlet/ext/library/init.jsp”%>

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>

  1. <html>
    <head>
    <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
    <title>Library Add Book</title>
    </head>
    <body>
    <br>
    <h3>Library Add Book</h3>
    <br />
    Add a book entry to the Library:
    <br />
    <br />
    <form action=”<portlet:actionURL windowState=”<%= WindowState.MAXIMIZED.toString() %>”>
    <portlet:param name=”struts_action” value=”/ext/library/addBook” /></portlet:actionURL>”
    method=”post” name=”<portlet:namespace />fm”>
    Book Title:<input name=”<portlet:namespace />title” size=”20″ type=”text” value=”"><br />
    Book Author:<input name=”<portlet:namespace />author” size=”20″ type=”text” value=”"><br />
    Book Publisher:<input name=”<portlet:namespace />publisher” size=”20″ type=”text” value=”"><br />
    Book Pages:<input name=”<portlet:namespace />pages” size=”20″ type=”text” value=”"><br />
    Book Price:<input name=”<portlet:namespace />price” size=”20″ type=”text” value=”"><br />
    <br />

    <input type=”button” value=”Submit”
    onClick=”submitForm(document.<portlet:namespace />fm);”>
    </form>
    <br />
    </body>
    </html>

3. struts-config.xml  entry for add bok action

<action path=”/ext/library/addbook” forward=”portlet.ext.library.addbook” />

<action path=”/ext/library/addBook” type=”com.ext.portlet.library.action.AddBookAction”>
<forward name=”portlet.ext.library.adderror” path=”portlet.ext.library.adderror” />
<forward name=”portlet.ext.library.addsuccess” path=”portlet.ext.library.addsuccess” />
</action>

4.tiles-config.xml

<definition name=”portlet.ext.library.addbook” extends=”portlet.ext.library”>
<put name=”portlet_content” value=”/portlet/ext/library/addBook.jsp” />
</definition>

<definition name=”portlet.ext.library.editbook” extends=”portlet.ext.library”>
<put name=”portlet_content” value=”/portlet/ext/library/edit_book.jsp” />
</definition>

<definition name=”portlet.ext.library.adderror” extends=”portlet.ext.library”>
<put name=”portlet_content” value=”/portlet/ext/library/addError.jsp” />
</definition>

<definition name=”portlet.ext.library.addsuccess” extends=”portlet.ext.library”>
<put name=”portlet_content” value=”/portlet/ext/library/addSuccess.jsp” />
</definition>

5.Action

package com.ext.portlet.library.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.ext.portlet.library.service.*;
import com.liferay.portal.kernel.servlet.*;
import com.liferay.portal.kernel.util.*;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.*;
import com.liferay.portal.struts.PortletAction;
import com.liferay.portal.util.*;

public class AddBookAction extends PortletAction {
public void processAction(ActionMapping mapping, ActionForm form, PortletConfig config,
ActionRequest req, ActionResponse res)throws Exception {

String bookTitle = req.getParameter(“title”);
String bookAuthor = req.getParameter(“author”);
String bookPublisher = req.getParameter(“publisher”);
long bookPages = Long.valueOf(req.getParameter(“pages”)).longValue();
long bookPrice = Long.valueOf(req.getParameter(“price”)).longValue();

long userId = PortalUtil.getUserId(req);
Layout layout = (Layout)req.getAttribute(WebKeys.LAYOUT);

System.out.println(“input from JSP “+bookTitle+”  “+bookAuthor+”  “+bookPublisher+”   “+bookPages+”  “+bookPrice+”\n”);

if (Validator.isNull(bookTitle)) {
setForward(req, “portlet.ext.library.adderror”);
} else {
BookLocalServiceUtil.addBook(userId, layout.getPlid(), bookTitle,bookAuthor,bookPublisher,bookPrice,bookPages);
SessionMessages.add(req, “addbooksuccess”);
setForward(req, “portlet.ext.library.addsuccess”);
}
}

public ActionForward render(ActionMapping mapping, ActionForm form,
PortletConfig config, RenderRequest req, RenderResponse res)
throws Exception {

if (getForward(req) != null && !getForward(req).equals(“”)) {
return mapping.findForward(getForward(req));
} else {
return mapping.findForward(“portlet.ext.library.addbook”);
}

}
}

6.addSucces.jsp

<%@ include file=”/html/portlet/ext/library/init.jsp” %>
<liferay-ui:success key=”addbooksuccess”
message=”New Book Entry Has been Added to the Record Successfully” />
<%
List books = (List) BookLocalServiceUtil.getAll();
Book book = null;
%>
<table border=”1″ cellspacing=”4″ cellpadding=”4″ width=”100%”>
<tr>
<td style=”color: #12558E;”>Title</td>
<td style=”color: #12558E;”>Author</td>
<td style=”color: #12558E;”>Publisher</td>
<td style=”color: #12558E;”>Pages</td>
<td style=”color: #12558E;”>Price</td>
<td style=”color: #12558E;”>Entry By</td>
<td style=”color: #12558E;”>Created Date</td>
<td style=”color: #12558E;”>Modified Date</td>
<td style=”color: #12558E;”>Edit</td>

</tr>
<c:if test=”<%= books != null %>”>
<%
for (int i=0; i < books.size(); i++) {
book = (Book) books.get(i);
%>
<tr>
<td><%= book.getTitle() %></td>
<td><%= book.getAuthor() %></td>
<td><%= book.getPublisher() %></td>
<td><%= book.getPages() %></td>
<td><%= book.getPrice() %></td>
<td><%= book.getUserName() %></td>
<td><%= book.getCreateDate() %></td>
<td><%= book.getModifiedDate() %></td>
<td><a href=”<portlet:renderURL><portlet:param name=”struts_action”
value=”/ext/library/editbook” /></portlet:renderURL>”>EDIT</a></td>

</tr>
<%
}
%>
</c:if>
</table>
<br/>
<a href=”<portlet:renderURL><portlet:param name=”struts_action”
value=”/ext/library/addbook” /></portlet:renderURL>”>Back to Add a Book</a>

7.addError.jsp

<h1> ERROR ! </h1>

8. Now we need tocreate table book –

create service.xml inside “ext-impl”

<?xml version=”1.0″?>
<!DOCTYPE service-builder PUBLIC “-//Liferay//DTD Service Builder 4.3.3//EN” “http://www.liferay.com/dtd/liferay-servicebuilder_
4_3_3.dtd”>
<service-builder package-path=”com.ext.portlet.library”>
<namespace>Library</namespace>
<entity name=”Book” local-service=”true” remote-service=”false”>
<!– PK fields –>
<column name=”bookId” type=”long” primary=”true” />
<!– Group instance –>
<column name=”groupId” type=”long” />
<!– 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=”title” type=”String” />
<column name=”author” type=”String” />
<column name=”publisher” type=”String” />
<column name=”price” type=”long” />
<column name=”pages” type=”long” />
</entity>
</service-builder>

9. run service builder — it generates service layer classes .

ext-impl >

refer pdf documents …..





HotBits

February 28, 2009 rajcheram Comments off

Tech HitBits

Categories: hotbits

Napoleon Dynamite Dance

February 27, 2009 rajcheram Comments off

Categories: videos Tags:

Evolution of Dance

February 27, 2009 rajcheram Comments off

Categories: videos Tags:

Liferay JSP Portlet Development

February 27, 2009 rajcheram Comments off

Liferay JSP Portlet Development

[portlet-ext.xml, liferay-portlet-ext.xml, liferay-display.xml -- placed under .. "  ext/ext-web/docroot/WEB-INF  "


  1. create portlet entry in “portlet-ext.xml”

<portlet>

<portlet-name>JSPPortlet</portlet-name>

<display-name>Simple JSP Portlet</display-name>

<portlet-class>com.ext.portlet.jspportlet.SimpleJSPPortlet</portlet-class>

<expiration-cache>0</expiration-cache>

<init-param>

<name>view-jsp</name>

<value>/portlet/ext/library/view.jsp</value>

</init-param>

<supports>

<mime-type>text/html</mime-type>

</supports>

<portlet-info>

<title>Simple JSP Portlet</title>

<short-title>Simple JSP Portlet</short-title>

<keywords>Simple JSP Portlet</keywords>

</portlet-info>

<security-role-ref>

<role-name>guest</role-name>

</security-role-ref>

<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.Create liferay specific portlet entry in “liferay-portlet-ext.xml”

<portlet>

<portlet-name>JSPPortlet</portlet-name>

</portlet>

3. create a JSP file named view.jsp inside “/portlet/ext/library/”

<H1> Some Text

4. Create package for JSP portlet class

com.ext.portlet.jspportlet

Create a “Class” SimpleJSPPortlet in the created package

package com.ext.portlet.jspportlet;

import com.liferay.portal.kernel.util.ContentTypes;

import com.liferay.portal.kernel.util.ReleaseInfo;

import java.io.IOException;

import java.io.PrintWriter;

import javax.portlet.ActionRequest;

import javax.portlet.ActionResponse;

import javax.portlet.GenericPortlet;

import javax.portlet.RenderRequest;

import javax.portlet.RenderResponse;

public class SimpleJSPPortlet extends GenericPortlet {

public void processAction(

ActionRequest actionRequest, ActionResponse actionResponse) {

}

public void doView(

RenderRequest renderRequest, RenderResponse renderResponse)

throws IOException {

renderResponse.setContentType(ContentTypes.TEXT_HTML_UTF8);

PrintWriter writer = renderResponse.getWriter();

writer.print(“Simple Liferay Portal 5.2.1 JSP Portlet “);

}

}

5.Create Categoryadd add this portlet under the new one

Open Language-ext.properties iiinside directory “/ext/ext-impl/src/content”

category.extworks=My Works

add this entry to liferay-display.xml

<category name=“category.extworks”>

<portlet id=“JSPPortlet” />

</category>

Categories: liferay Tags:

Liferay Struts Portlet Development – 1

February 27, 2009 rajcheram Comments off

Liferay Simple Struts Portlet Development

  1. create portlet entry in “portlet-ext.xml”

<portlet>

<portlet-name>libraryhome</portlet-name>

<display-name>Library Home</display-name>

<portlet-class>com.liferay.portlet.StrutsPortlet</portlet-class>

<init-param>

<name>view-action</name>

<value>/ext/library/viewhome</value>

</init-param>

<expiration-cache>0</expiration-cache>

<supports>

<mime-type>text/html</mime-type>

</supports>

<portlet-info>

<title>Library Home</title>

<short-title>Library Home</short-title>

<keywords>library</keywords>

</portlet-info>

<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.Create liferay specific portlet entry in “liferay-portlet-ext.xml”

<portlet>

<portlet-name>libraryhome</portlet-name>

<struts-path>ext/library</struts-path>

<use-default-template>false</use-default-template>

</portlet>

  1. Create “/ext/library/viewhome” struts pageflow in struts-config.xml for the entry ‘<value>/ext/library/viewhome</value>’ in portlet-ext.xml

<action path=“/ext/library/viewhome” forward=“portlet.ext.library.viewhome” />

4. Create tiles pagelayout for “/ext/library/viewhome” – struts path in tiles-defs.xml

<definition name=“portlet.ext.library” extends=“portlet” />

<definition name=“portlet.ext.library.viewhome” extends=“portlet.ext.library”>

<put name=“portlet_content” value=“/portlet/ext/library/view_home.jsp” />

</definition>

  1. Create JSP file view_home for the pageto be displayed

    <%@ include file=“/html/portlet/ext/library/init.jsp” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>

<html>

<head>

<meta http-equiv=“Content-Type” content=“text/html; charset=UTF-8″>

<title>Library Home</title>

</head>

<body>

Library Home

<br> <h3>Home Page &nbsp;&nbsp;&nbsp;&nbsp; will be used entry point for Libarary Process </h3>

</body>

</html>

  1. Include init.jsp /html/portlet/ext/library/init.jsp

    This is for our portlet initialization parameter or preferences …

  1. init.jsp

// this is for liferay, xtra tags file to be used in our jsp while development .. Eg: image tag, display tag, etc …

<%@ include file=“/html/common/init.jsp” %>

<portlet:defineObjects />

<%

WindowState windowState = renderRequest.getWindowState();

%>

  1. End..

    Create a category, and add this..

    Enjoy

Struts portlet with Struts Action will be available in Next Post

-live

JavaFX

February 27, 2009 rajcheram Comments off

RIA – rich internet application api/framework from SUN. the Java Nestle

Refer :  www.javafx.com

Categories: java Tags:

Liferay 5.2 Installation

February 19, 2009 rajcheram 1 comment

Steps to Install liferay Portal

Required Softwares;

Liferay Portal, ant, mysql or any DB [ setup explained here for MySQL  and liferay bundle with tomcat 5.5.x]

1.Get JDK version greater than 1.5 and install , set JAVA_HOME

If OS Windows set in System Variables

JAVA_HOME= C:\JDK1.5; add this entry into PATH variable as %JAVA_HOME%\bin\;

For Linux .. SuseLinux

JAVA_HOME=/home/username/software/jdk1.5.0_14
ANT_HOME=/home/username/software/apache-ant-1.7.0

PATH=/home/username/software/jdk1.5.0_14/bin:/home/username/software/apache-ant-1.7.0/bin:/home/username/software/mysql-5.0.51/bin:/sbin:$PATH

export PATH JAVA_HOME ANT_HOME ANT_OPTS
2.Set ANT_HOME similar to JAVA_HOME in Windows [ for Linux follow the above]

3.Get liferayportal – now current version is 5.2.1 .

http://www.liferay.com/web/guest/downloads/portal  – Liferay Portal Standard Edition — get this

and extract to home/username/software/liferay52/

You can see data,deploy,tomcat-xxx, license folders

4.Get Portal source from

http://www.liferay.com/web/guest/downloads/additional

Bottom of the page under  grouping “Files for Developers” — Liferay Portal 5.2.1 Source

extract to  home/username/software/liferay52/portal52/

You can see some folders and properties files.

Now its time to create EXT environment and database configurations

i. copy the app.server.properties  and rename to  “app.server.username.properties”

app.server.username.properties —

1. set app.server.parent.dir=/home/username/software/liferay52

2.   ## Tomcat  ##

app.server.tomcat.version=5.5
app.server.tomcat.dir=${app.server.parent.dir}/tomcat-5.5.27
app.server.tomcat.bin.dir=${app.server.tomcat.dir}/bin
app.server.tomcat.classes.global.dir=${app.server.tomcat.dir}/common/classes
app.server.tomcat.classes.portal.dir=${app.server.tomcat.portal.dir}/WEB-INF/classes
app.server.tomcat.deploy.dir=${app.server.tomcat.dir}/webapps
app.server.tomcat.lib.endorsed.dir=${app.server.tomcat.dir}/common/endorsed
app.server.tomcat.lib.global.dir=${app.server.tomcat.dir}/common/lib/ext
app.server.tomcat.lib.portal.dir=${app.server.tomcat.portal.dir}/WEB-INF/lib
app.server.tomcat.lib.support.dir=${app.server.tomcat.dir}/server/lib
app.server.tomcat.portal.context=ROOT
app.server.tomcat.portal.dir=${app.server.tomcat.deploy.dir}/${app.server.tomcat.portal.context}
app.server.tomcat.log.dir=${app.server.tomcat.dir}/logs
app.server.tomcat.temp.dir=${app.server.tomcat.dir}/temp
app.server.tomcat.work.dir=${app.server.tomcat.dir}/work
app.server.tomcat.zip.name=liferay-portal-tomcat-5.5-${downloads.version}.zip
app.server.tomcat.zip.url=${sourceforge.mirror}/${app.server.tomcat.zip.name}

Don’t modify anything

2.similar to  app.server.username.properties copy release.properties and rename to “release.user.properties

release.user.properties — changes

lp.source.dir=/home/username/software/liferay52/portal52

lp.ext.dir=/home/username/software/liferay52/ext

ant.installer.dir=/home/username/software/apache-ant-1.7.0

// comment plugins , eclipse if u dont need .. i will gine instructions how to add this ext into eclipse as a project

3.  DB configurations

Default database name for liferay lportal … if you want change

inside folder “sql” — sql.properties –    replace the database name whatever you want

eg: database.name=lportal52 // i named to lportal52  – if u dont want leave it – donot modify other than anything in this  file

Its time to set database association with liferay tomcat … to do this ..

Modify the portal.properties inside /home/username/software/liferay52/portal52/portal-impl/classes/

Open the property file and search for MySQL \\ by default Hypersonic is be configured

uncomment mysql properties …. after look like this

” #
# MySQL
#
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal52?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=’mysqlpassword’ “

// Dont forget to comment hypersonic properties

4. Final step is to build the portal

Open a console inside portal52

$$$$$$$ /software/liferay52/portal52>  ant clean start build-ext

after some time ~ 4 minutes for [1GB RAM witk Intel Core CPU ]

You will get build successful

$$$$$$$ /software/liferay52/portal52>  ant start deploy

Now the portal server is ready …

Navigate to $$$$$$$ /software/liferay52/portal52/tomcat5.5.x/bin>./startup.sh

..

.

.after som time u will get message like this …

INFO: Server startup in 58507 ms

5.Open browser type http://localhost:8080

default username ” test@liferay.com”, password is     ” test”

login and enjoy with liferay ….

6.Final set up for ext environment …

when  u build ext using command “ant clean start build-ext”

new directory    “ext”  will be created inside ” /home/username/software/liferay52″

If you want to develop portlets using ext environment …. dont forget to paste the  “app.server.username.properties” file into ext folder — get this from portal52/app.server.username.properties

open a terminal inside ext folder …

$$$$$$$ /software/liferay52/portal52/ext>  ant  deploy

after some time u will get message like

BUILD SUCCESSFUL
Total time: 1 minute 35 seconds

7. Importing ext into Eclipse

Open Eclipse IDE , choose import from File menu .. select ” Existing Project into WorkSpace”

Choose “ext” … and click finish …………..

Now i hope everything ready to enjoy with liferay portal , development environment has been set ………

In next Post we will see how to develope portlets from liferay-plugins-sdk

-live

-rajcheram

Sources:

Liferay Quick Installation Guide for 5.1
Liferay Portal Administrator’s Guide for 5.1