Pages

Tuesday, December 22, 2009

Struts Action internal mechanism

An Action is an adapter between the contents of an incoming HTTP request and the corresponding business logic that should be executed to process this request. The controller (RequestProcessor) will select an appropriate Action for each request, create an instance (if necessary), and call the execute method.

Actions must be programmed in a thread-safe manner, because the controller will share the same instance for multiple simultaneous requests. This means you should design with the following items in mind:

* Instance and static variables MUST NOT be used to store information related to the state of a particular request. They MAY be used to share global resources across requests for the same action.

* Access to other resources (JavaBeans, session variables, etc.) MUST be synchronized if those resources require protection. (Generally, however, resource classes should be designed to provide their own protection where necessary.

When an Action instance is first created, the controller will call setServlet with a non-null argument to identify the servlet instance to which this Action is attached. When the servlet is to be shut down (or restarted), the setServlet method will be called with a null argument, which can be used to clean up any allocated resources in use by this Action.

Sunday, November 8, 2009

Liferay Extension Environment

1) Download the liferay source from liferay.com
2) Now you need to create two property files those are
release.< computerName > .proerties
app.server.< computeName > .properties
3) Add following content to newly created relese. < computeName > .property file

lp.ext.dir= -- location where to create extension folder--

Eg: lp.ext.dir=D:/hytv/source/ext-env
(Note: Remember this ext-env directory should not be existed physically in specified location)

Now add the below content to newly created file app.server. < computerName > . property file.

app.server.tomcat.dir= < Specify the Tomcat location >

Eg:

##
## Server Type
##

app.server.type=tomcat
app.server.tomcat.version=5.5
app.server.tomcat.dir=D:/hytv/source/apache-tomcat-5.5.27
app.server.tomcat.classes.global.dir=${app.server.tomcat.dir}/lib
app.server.tomcat.lib.endorsed.dir=${app.server.tomcat.dir}/lib/ext
app.server.tomcat.lib.global.dir=${app.server.tomcat.dir}/lib/ext
app.server.tomcat.lib.support.dir=${app.server.tomcat.dir}/lib/ext
app.server.tomcat.zip.name=liferay-portal-tomcat-5.5-${downloads.version}.zip


Note: this file is useful to creates the total tomcat environment of Tomcat and replaces those in specified tomcat server files.


4) Now create a project in Netbeans
NewProject --> Java --> Java-freeform-Project.



5) Now specify the location of liferay source code folder, and build.xml location.




6) Here you can customize the ant build as per your requirement.



7) Now you can choose jdk source levels, and encoding technique.



8) Now click on finish button to get the src project. Here you can see the created project will be shown on netbeans IDE.



9) Ignore the errors if you got in Net beans project. Now expand the build.xml file by clicking on + button.

10) Right click on deploy option and then click on Run target.
11) Now Right click on build-ext option then click on Run target.
12) You have successfully created the liferay extension environment.
13) Now you can open the ext-env folder as netbeans project.
14) Here you need to copy the app.server. < computerName > . properties
and release. < computerName > . properties files from liferay source to ext-env folders.

15) Now if you want to change database, or any other related things then you can just add the necessary changes in portal-ext.properties file of ext-env file.

Eg: Adding new database specification.

# MySQL
#
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal234?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=kmipl


16) Click on build.xml, run the deploy option for every modification.
17) Now Start the tomcat server. (which is specified in app.server. < computerName > . properties file).

Monday, November 2, 2009

Modes available on liferay portlet

Portlet will contains the following modes

PortletMode
VIEW
EDIT
HELP

Third party services can implements their own modes including the above portlet modes. for example liferay provides the following modes.

LiferayPortletMode
ABOUT
CONFIG
EDIT_DEFAULTS
EDIT_GUEST
PREVIEW
PRINT

Monday, October 12, 2009

Blog - Liferay

Steps to Create Blogs in liferay

-->After login choose Add application button from the welcome menu.


--> Now choose Blogs from collaboration menu.

--> Now click on Add Blog Entry button for adding blog content




--> Enter the title and content details as you want. Then click on publish button.

--> You can give tags also to your posted blog content. After publishing you will get the blog list as follows. As a posted user you will have edit option to modify the content.


--> Now get the bloggers details, who are blogging on our site.

Add Applications >> Collaboration >> Recent Bloggers -- Add

--> Now you have completed the blog creation successfully.

--> best example of liferay Blog is














Liferay - Dynamic Virtual Hosting

Steps to use Virtual Hosting feature from Life ray

  1. Create virtual hosts in /windows/system32/drivers/etc/hosts file

127.0.0.1 localhost

127.0.0.1 localhost1

127.0.0.1 raj.com

  1. open control panel >> server >> Portal Instances

Add virtual hosts here



























Now open http://www.raj.com:8080/

Database Sharding:

To create database for each virtual Hosting:

Create three database schemas,Run minimal sql script for each database.

Restart liferay server, nowu are able to use three applications in same liferay server.

At present, sharding exists in Liferay from version 5.2.3+ for handling data across multiple portal instances. Here's what you do to get it up.

After you have a normally working development environment, make sure your hosts file is setup to allow virtual hosting (for our convenience, I will call the hosts abc1.com, abc2.com, abc3.com, etc.).

Use the create-minimal SQL script (from our Downloads section) to create three database schemas: lportal, lportal1, and lportal2.

Be careful and use the scripts for your liferay portal version, otherwise, it won't work. By default, the configuration files are setup for three schemas called default, one and two, but you can configure it for more.

All this configuration is set up in the file portal-impl/src/META-INF/shard-data-source-spring.xml .

As you will see, we will include this file in the property spring.configs in the next step. In case we want to modify it we just should write our own file in the Extension Environment and include it in this property instead of the default one.

In your portal-ext.properties, you will need to set the following:

Enable META-INF/shard-data-source-spring.xml under spring.configs.

Configure the jdbc schema settings for jdbc.default.*, jdbc.one.*, and jdbc.two.*.

Enable the shard names: shard.available.names=default,one,two

Don't forget to set the appropriate username and password for each schema.

Startup the server and create several (2-3) portal instances (e.g., abc1.com, abc2.com, abc3.com).

Using your favorite database browser, do a query on each of your schemas for the User_ table, and you will notice that the data is now distributed across different schemas. That's it!

Additional Settings

Remember that default, one, and two are default values defined in portal-impl/src/META-INF/shard-data-source-spring.xml and portal-ext.properties. If you want to change it, make sure to propagate the changes to the spring XML file as well as portal-ext.properties.

If you want to manually select the shard (via the GUI when creating portal instances), you need to enable in your portal-ext.properties file: shard.selector=com.liferay.portal.dao.shard.ManualShardSelector. Otherwise, the shard for the data will be chosen using a round robin technique.

Sunday, September 6, 2009

Struts - DownloadAction

Every struts starter is facing the problem while writing the code for uploading a file. Especially to reduce the burden of writing long code for uploading struts introduced DownloadAction as an added feature from 1.2.6 version onwards. Using this action very easy like eating banana.

i am giving small example on how to use DownloadAction

=======================================================================

public class downloadFileAction extends org.apache.struts.actions.DownloadAction {

protected StreamInfo getStreamInfo(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {

// File Name
String fileName = "c:\\WriteSelectedRows.pdf";

/*
* To open up in the browser: "inline; filename=myFile.pdf"
* To download: "attachment; filename=myFile.pdf"
* URL for reference: http://wiki.apache.org/struts/StrutsFileDownload
*/

// Set the content disposition
response.setHeader("Content-disposition",
"attachment; filename=" + fileName);

// Download a "pdf" file - gets the file name from the
// Action Mapping's parameter
String contentType = "application/pdf";
File file = new File(fileName);

return new FileStreamInfo(contentType, file);

}
}

=======================================================================

if you want to know more about the Download Action Please go through the URL specified in the above example.

Tuesday, September 1, 2009

Encrypt URL

We have a major problem while calling some hyperlinks which will carry sensitive data, to avoid showing the parameters data while calling hyperlinks we have one beautiful concept in java is encryption we can do the encryption of total data and can decrypt the data while using.
But how to write the encryption code and decryption code, dont worry we no need to write the long lines code, we can use open source code for encryption and decryption given by Query Crypt.

Just follow the sample to encrypt the data.


                        <%@ page import="com.guhesan.querycrypt.QueryCrypt" %>
<%
String plainString = "BankID=1234&AccountID=J5678&TrasactionID=25";
String encryptedS = QueryCrypt.getInstance().encrypt(request, plainString);
%>
A HREF="<%=request.getContextPath()%>/URL_U_WANT_TO_GO.jsp?<%=encryptedS%>">Click here for the secure transaction /A
To do the decryption just go through the below code.

Suppose you had a encrypted string such as the following:
someURL.jsp?_tq=c95a29f62075cf63028be5ec6ba48be0
To decrypt in JSP:
  <%@ page import="com.guhesan.querycrypt.QueryCrypt" %>
<%@ page import="com.guhesan.querycrypt.beans.RequestParameterObject" %>
<%
RequestParameterObject rpo = QueryCrypt.getInstance().decrypt(request);
%>
You can now use the methods available in the RequestParameterObject to get the name value pairs.
The following methods are available for RequestParameterObject:
    java.util.Map RequestParameterObject.getParameterMap();
java.lang.String RequestParameterObject.getParameter(java.lang.String name);
java.util.Enumeration RequestParameterObject.getParameterNames();
java.lang.String[] RequestParameterObject.getParameterValues(java.lang.String name);
String RequestParameterObject.toString();


Source URL: http://www.avedatech.com/Products/QueryCrypt/index.jsp
you can download source files, jar files related to query crypt.

Monday, August 31, 2009

Get Current Language Id - Liferay

to get current selected language we can use the following code

String languageId = LanguageUtil.getLanguageId( renderRequest );

Which will resides in portal-kernal.jar file.

Open popup window in liferay

I have a situation - where i need to display the playlists of videos in a portlet, whenever the user clicks on the playlist it should open the popup, in that we need to run the video.

For this i used the Add application window as it is.

after login we will use add application option for adding our own portlets, yes That POP UP only.

To use this we need to use liferay theme objects

Step 1- <%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
-lt- liferay-theme:defineObjects / -gt-

Step 2 - script type="text/javascript"
src="<%=themeDisplay.getPathJavaScript()%>/jquery/ui.dialog.js"

Step 3 -jQuery.noConflict();
jQuery(document).ready(
function()
{
// jQuery("#ayudaCertificados").dialog({ width: 450, height: 400, modal: true,
autoOpen: true});
}
);

Step 4 - Write the following javascript functions in script tag

buttonClicked(title,content) {
// alert(" om sai ram 1");
var playerText="content";
title = ""+title+"";
callAjax(playerText);
jQuery("#myDiv").dialog({
width: 830,
height:470,
modal: true,
autoOpen: true,
closeOnEscape:true,
title:title,
resizable:false
});
// alert(" om sai ram 2");
}
function callAjax(content){
document.getElementById("myDiv").innerHTML = content;
}


Step 5 - Now difine one empty div tag in your jsp file with ID name "myDiv"( you can change
it).
eg: -lt- div id="myDiv"-gt- -lt- /div -gt-

Step 6 - Now the important code which shows pop up window.
write an anchor tag and call the above defined function ( buttonClicked(title,content) )
on onclick function like...

a href="#" onclick="buttonClicked(title,content) "

supply the necessary parameters title and content as per your requirement.

change default language in custom portlets

our own portlets defaultly doesnt changes the data as per selected language even the database contains the related language stuff. To Get that respective language data we need to use

JournalContentUtil.getContent(groupId, articleId, viewMode, languageId, themeDisplay);

It will returns the Content in String format.
To work with this we need to import base file

<%@ page import="com.liferay.portlet.journalcontent.util.JournalContentUtil" %>

It will be available in portal-service.jar file.

Packages used by Liferay

liferay uses N no of packages as per the different situations, where they are existed, how they are importing in to the liferay, how the liferay portlets are getting the portlet objects, liferay theme objects....etc is a big question for every liferay starters.

Answer for this question is Liferay defines all the necessary package classes in one jsp file called init.jsp which is available at

--liferay tomcat home-- /webapps/ROOT/html/common

So please go through the to know how many important classes are needed for liferay and think about how can we utilize them in our real time applications?

Get Current Portlet ID

Way 1- liferay Theme objects will give us the current portlet Id. (To know about liferay theme
objects please go through my previous post)

portletDisplay.getId();


Way 2- we can directly get the current portlet id using webkeys. To get WebKeys reference we
need to import

com.liferay.portal.kernel.util.WebKeys which is available in portal-kernal.jar file.

request.getAttribute(WebKeys.PORTLET_ID)

Liferay theme objects

To get Liferay Theme object please follow the below code.


--><%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
-lt-portlet:defineObjects /-gt-

To get the portlet related objects.

<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
-lt- liferay-theme:defineObjects -gt-

To get the theme related Objects.
Example: To get selected theme folder path.
script type="text/javascript"
src="-lt-%=themeDisplay.getPathJavaScript ()%-gt-/jquery/ui.dialog.js"

--> The objects that are injected into the pageContext by the
-lt- liferay-theme:defineObjects /-gt- tag are:

* themeDisplay - com.liferay.portal.theme.ThemeDisplay
* company - com.liferay.portal.model.Company
* account - com.liferay.portal.model.Account (deprecated)
* user - com.liferay.portal.model.User
* realUser - com.liferay.portal.model.User
* contact - com.liferay.portal.model.Contact
* ?layout - com.liferay.portal.model.Layout
* ?layouts - List
* plid - java.lang.Long
* ?layoutTypePortlet - com.liferay.portal.model.LayoutTypePortlet
* portletGroupId - java.lang.Long
* permissionChecker - com.liferay.portal.security.permission.PermissionChecker
* locale - java.util.Locale
* timeZone - java.util.TimeZone
* theme - com.liferay.portal.model.Theme
* colorScheme - com.liferay.portal.model.ColorScheme
* portletDisplay - com.liferay.portal.theme.PortletDisplay



Note: -lt- with lessthan symbol
-gt- with greaterthan symbol

Liferay-Connecting to the Database in the way of liferay

We can directly use the Liferay Database connection while writing our own portlets. By following the below procedure.

step 1- import com.liferay.portal.kernel.util.InfrastructureUtil;
which will available under portlet-kernal jar file.

Step 2- import javax.sql.DataSource;
liferay uses DataSource mechanism for maintaining the database connections.

step 3- Connection connection = null;
DataSource dataSource = null;

create above variable for getting and storing datasource and connection to the database.

step 4- dataSource = InfrastructureUtil.getDataSource();
connection = dataSource.getConnection();

This is it here we are having the liferay datasource and from that datasource object we
will get the connection object.

Note: In general way it will raises sql exceptions so dont forget to handle the exceptions. ;)

Thursday, July 23, 2009

Bulk mailing with Bulk attachment

Hi i think - sending bulk mails with bulk attachments problem- is faced by every java programmer in real time projects, I got small solution from my friend, i thought this will be help full for some one who needs the solution for this problem.

please copy and paste the following java code in your mail handler action class,

Note: 1) Multiple Emails are taking with comma[,] seperated.
2) If attachments are more then also we can send mails -- Need to get attachment paths with comma[,] separated.
3) To work with the following code please import javax.mail.*, javax.mail.internet.*, javax.activation.DataHandler, javax.activation.FileDataSource packages.


Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");
javax.mail.Session session = Session.getDefaultInstance(props, null);
session.setDebug(sessionDebug);


MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(fromMailId));
InternetAddress[] address = {new InternetAddress(spiltEmail[i].trim())};
message.setRecipients(Message.RecipientType.TO, address);
message.setSubject(acknowledgementSubject);

message.setText(acknowledgementContent);
message.setSentDate(new Date());
Multipart multiPart = new MimeMultipart();

MimeBodyPart con = new MimeBodyPart();
con.setText(acknowledgementContent);
multiPart.addBodyPart(con);

// Take the below code for multiple attachments also
// Need to copy the same code and change the path to new attachment path

MimeBodyPart bodyPart = new MimeBodyPart();
FileDataSource fds = new FileDataSource(path);
bodyPart.setDataHandler(new DataHandler(fds));
bodyPart.setFileName(fds.getName());
//mbp.setText(acknowledgementContent);

multiPart.addBodyPart(bodyPart);
message.setContent(multiPart);

Transport.send(message); //to send the mail successfully

Thursday, July 16, 2009

Maintaining database connection in Context.xml

Meta-inf folder -> context.xml

in this write the following code
--&lt-- ?xml version="1.0" encoding="UTF-8"? --&gt--
--&lt-- Context antiJARLocking="true" path="/search" --&gt--
--&lt-- !-- Default set of monitored resources -- --&gt--
--&lt-- WatchedResource --&gt-- WEB-INF/web.xml --&lt-- /WatchedResource --&gt--
--&lt-- !-- Uncomment this to disable session persistence across Tomcat restarts -- --&gt--
--&lt-- !--
--&lt-- Manager pathname="" / --&gt--
-- --&gt--
--&lt-- Resource auth="Container"
driverClassName="com.mysql.jdbc.Driver"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
logAbandoned="true" maxActive="30"
maxIdle="10"
maxWait="1000"
name="jdbc/POS"
removeAbandoned="true"
removeAbandonedTimeout="60"
type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/POC?autoReconnect=true"
username="root"
password="kmipl"/ --&gt--
--&lt-- /Context --&gt--

Note : replace all --&lt-- with '<' --&gt-- with '>'


______________________________________________________________


to get the connection from context.xml file just use the following method

public Connection dbConnectionCheck()
{
try
{
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/POS");
connection = ds.getConnection();
}
catch(Exception e1)
{
System.out.println(e1);
}
return connection;

}

_______________________________________________________

by this we can change the database with out redeploying or rebuilding the war file.

Tuesday, June 23, 2009

Multiple Uploads

Note: what ever the code is given totally worked
replace all -&lt- with < -&gt- with >

To upload multiple images, videos we can use the following code..........

-------------------------------------------------------------------------------------------
HTML Code:
-------------------------------------------------------------------------------------------
-&lt- input type="file" name="Flash_Path" onkeypress="return false" / -&gt-
-&lt- input type="file" name="Image_Path" onkeypress="return false" / -&gt-
-&lt- input type="text" name="name" / -&gt-

-------------------------------------------------------------------------------------------
JAVA Code:
-------------------------------------------------------------------------------------------

use IMPORTS:

import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.fileupload.DiskFileUpload;
import org.apache.commons.fileupload.FileItem;


public static Map UploadCategoryImage(HttpServletRequest request) {

// System.out.println(" UploadFile() ");
String flashPath = "";
// Map object is used store form fields names[ key ] and their values [ values ].
Map hMap = new HashMap();
// diskFile object is used to store uploaded file into server.
DiskFileUpload diskFile = new DiskFileUpload();

// items list object is used to store form fields which are of type File.
List items = new ArrayList();

// Part One: to parse input file and other input form fields
try {
items = diskFile.parseRequest(request);
} catch (Exception e) {
e.printStackTrace();
}
if(items.size() > 0 ) {
Iterator itr = items.iterator();
StringBuilder directory=new StringBuilder();
directory.append("./../webapps/HMTV/videos/archieves/category");
File directoryFile=new File(directory.toString());
directoryFile.mkdirs();


/**
* Purpose is to store all parameters from uploadPortlet_view.jsp into HashMap object.
*/
while (itr.hasNext()) {
FileItem item = (FileItem) itr.next();
if (item.isFormField()) {
System.out.println(" form field name : " + item.getFieldName());
System.out.println(" form field value : " + item.getString());

hMap.put(item.getFieldName(), item.getString());

} else {
try {
String itemName = item.getName();

System.out.println("categoryName 1 >--------> " + itemName);
if (itemName.indexOf("\\") != -1) {
itemName = itemName.substring(itemName.lastIndexOf("\\") + 1);
} else if (itemName.indexOf("/") != -1) {
itemName = itemName.substring(itemName.lastIndexOf("/") + 1);
}

// System.out.println("itemName 2 >--------> " + itemName);

flashPath = directory.append("/").toString()+itemName;
System.out.println("flashPath 2 >--------> " + flashPath);
// File nFile = new File(flashPath);
// nFile.mkdirs(); // create directory if does not exists initially.
hMap.put(item.getFieldName(), flashPath);
File savedFile = new File("../webapps"+flashPath);
item.write(savedFile);
} catch (Exception e) {
System.out.println(" errrrrrrr ");
e.printStackTrace();
hMap=null;
}

} // else
} // while
}
// System.out.println("hMap ::::::::::::::: " + hMap);

return hMap;
}

------------------------------------------------------------------
Use this method to retrieve all files and store files in specified path.
Change necessary paths as per your requirement.


The above method gives hash map for above HTML we can retrieve the input fields in the following way

in ActionServlet or action handling class use

Map hMap = -&lt- classname -&gt-.UploadCategoryImage(httpRequest);

imagePath = (String) hMap.get("Image_Path"); ---- form field(file)
flashPath = (String) hMap.get("Flash_Path"); ---- form field(file)
name= (String) hmap.get("name"); -- form field(general)

now we can store these values to store in database or for some logical usage.

Run videos in web page

To run flv videos in your web site -- use the following code

NOTE: -&lt- represents < -&gt- represents >



-&lt-object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="800" height="420"
name="aaa" id="aaa"-&gt-
-&lt-param name="movie" value="/VideoArchieves/js/flvplayer.swf" /-&gt-
-&lt-param name="quality" value="high" /-&gt-
-&lt-param name="allowfullscreen" value="true" /-&gt-
-&lt-param name="uimode" value="true"/-&gt-
-&lt-param name="loop" value="9999"/-&gt-
-&lt-param name="flashvars" value="file=/HMTV/videos/archieves/<%=content%>&image=/HMTV/videos/archieves/preview.jpg&shuffle=false&showdownload=false&frontcolor=0xFFFFFF&repeat=true&autostart=false&showicons=true&showvolume=true&thumbsinplaylist=true&linktarget=_blank&backcolor=0x3E2B00&lightcolor=0xFFFFFF&bufferlength=10" /-&gt-
-&lt-param name="wmode" value="opaque" /-&gt-
-&lt-embed id="aaa" src="/VideoArchieves/js/flvplayer.swf" loop="9999" allowfullscreen="true" uimode="true" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="800" height="420" wmode="opaque" flashvars="file=/HMTV/videos/archieves/<%=content%>&image=/HMTV/videos/archieves/preview.jpg&shuffle=false&showdownload=false&frontcolor=0xFFFFFF&repeat=true&autostart=false&showicons=true&showvolume=true&thumbsinplaylist=true&linktarget=_blank&backcolor=0x3E2B00&lightcolor=0xFFFFFF&bufferlength=10"-&gt--&lt-/embed-&gt-
-&lt-/object-&gt-

Thursday, May 7, 2009

Ajax loader

we will use ajax loader in the case of where we need the page loading with out browser refresh.

just copy this code in your page. and call getpage LocationAds() function in your action button or anchor tag.

specify which page has to load

and specify the loading image path

(if you wanna get new loading images then visit http://www.ajaxload.info/ site and make your own loading images with different colors)

<------------------ code goes here--------------------------->

function getPageLocationAds(frm){

xmlhttp = false;
if (window.XMLHttpRequest) {// code for Firefox, Opera, IE7, etc.
xmlhttp=new XMLHttpRequest();
} else if (window.ActiveXObject) {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

if (xmlhttp!=null) {
//url="addAdvertise.do?logic=pageLocAdsList&pageId="+pageId+"&pageLocation="+pageLocation;
url="addAdvertise.do?logic=pageLocAdsList&pageId="+pageId+"&pageLocation="+pageLocation+"&sDate="+sDate+"&eDate="+eDate;
xmlhttp.onreadystatechange= function () { state_Change1(xmlhttp); };
//alert("Url : "+url);
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Cache-Control","no-cache, private, max-age=0");
xmlhttp.send(null);
//refresh();
} else {
alert("Your browser does not support XMLHTTP.");
}

}

function state_Change1(httpRequest1)
{
//alert('test');

if(httpRequest1.readyState==4)
{
if(httpRequest1.status==200)
{
//alert(httpRequest1.responseText);

document.getElementById('avail').innerHTML=httpRequest1.responseText;
}
else
{
alert("Error loading page\n"+ httpRequest1.status +":"+ httpRequest1.statusText);
}
}
else
{
document.getElementById('avail').innerHTML = '&ltimg src="http://www.blogger.com/flash/ajax-loader2.gif" /> Loading Content...';
}
}

replace &lt <>

'avail' is the div tag id of present page and we are just replacing the total response content in this div tag only.

Wednesday, April 8, 2009

calling procedures in java

to use proecedures in the database we need to use the following code

need to register the out parameters to the callable statements.

st.registerOutParameter(8, java.sql.Types.INTEGER);

8 is the parameter position name
java.sql.Types.INTEGER is type of the parameter

st.execute();
st.getInt(8); --- this statement returns the out parameter values

Tuesday, March 24, 2009

Getting POPUP in Liferay application

Using Pop-up in Liferay

When developing portlets in Liferay there are two ways to implement pop-ups. We can use a Floating Div or the traditional new browser Window without the toolbars. Each of them has got their advantages so we will have to decide which one fits us better. For example, if you are using a pop up with a form, you won't be able to send files attached to the form if you are using a floating div.

In this article there are some tips to develop both types of pop-ups.

Floating Div Pop-Up

Liferay provides a class called Expanse.Popup to implement this type of pop ups. Here is how this type of pop up would look like:

One advantage of this type of pop up is that they are invisible to pop up blockers (although that could change as they get smarter). This javascript code will make an asynchronous call to the url we give it and will place the content in our page. Below there is an example which will load the url 'url' in a pop up called 'our title':

var popup = new Expanse.Popup(
{
header: 'our title',
position:[150,150],
modal:true,
width:500,
height:300,
xy: ['center', 100],
url: 'url',
urlData: {
parameter1: 'value1',
parameter2: 'value2'
}
}
);
It's important to note that if the url is a portlet url it must have the windowState parameter set to LiferayWindowstate.EXCLUSIVE, because we just want the content produced by the portlet and not the extra portlet decoration produced by the portal.

To implement a button or link to close the pop up use the following code:

Expanse.Popup.close(this);

This type of pop-up is used in several Liferay core portlets like the image gallery (show pictures), journal (edit template) or my communities (publish to live). Look at them for further examples of usage.

Window Pop up

This type of pop ups will load in a new window. In order to do that we must set the windowState parameter in the portlet url to LiferayWindowState.POP_UP. This windowState will produce that the result of calling a portlet url will be shown in another window, like a real pop up. There are no visual effects asociated, it's a different window.

However, from this window we can still make javascript calls to the parent page javascript functions as the javascript object opener refers to the parent window. There is an example below:

--lt--input value="select" onclick="  var organizationWindow = window.open('    <%= LiferayWindowState.POP_UP.toString() %>">


',
'title',
'directories=no, height=640, location=no, menubar=no, resizable=yes,
scrollbars=yes, status=no, toolbar=no, width=680');

organizationWindow.focus();" / --gt--

If we want to close the pop up we just need to do the following:

 window.close(); 

If we want to close the parent page we can do the following:

opener.close(); 

This is used in several portlets like the image gallery (show slideShow), enterprse admin (select organizations for users...)

Friday, March 20, 2009

To run videos in your web page

Here i am using window media player plug-in as to play videos.

you need to just copy the below object code in your html file.

- lt-object id="mediaPlayer" width="320" height="260" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject"-gt-
- lt-param name="url" value="/hmtv.wpl"-gt-
- lt-param name="uiMode" value="full"-gt-
- lt-param name="autoStart" value="true"-gt-
- lt-param name="playCount" value="9999"-gt-
- lt-param name="wmode" value="transparent"-gt-
- lt-embed type="application/x-mplayer2" pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" showcontrols="1" uimode="full" wmode="transparent" width="320" height="260" src="/hmtv.wpl" autostart="1" playcount="9999"-gt-
- lt-/object-gt-


here i am using .wpl(window play list) which contains the list of wma files.
the .wpl file is looks like this..

- lt-?wpl version="1.0"?-gt-
- lt-smil-gt-
- lt-head-gt-
- lt-meta name="Generator" /-gt-
- lt-author/-gt-
- lt-title-gt-Playlist4- lt-/title-gt-
- lt-/head-gt-
- lt-body-gt-
- lt-seq-gt-
- lt-media src="AVSEQ01_3_clip0.wmv" /-gt-
- lt-media src="Griffey_Ken_WMV.wmv" /-gt-
- lt-media src="AVSEQ01_5_clip0.wmv" /-gt-
- lt-media src="AVSEQ01_7_clip0.wmv" /-gt-
- lt-media src="AVSEQ01_6_clip0.wmv" /-gt-
- lt-media src="AVSEQ01_8_clip0.wmv" /-gt-
- lt-/seq-gt-
- lt-/body-gt-
- lt-/smil-gt-

( plz replace -lt- with '< ' and -gt- '>')


thats it you can run your own video's using simple object script in html pages itself.

I hope this will be helpfull post for the people.

Wednesday, March 18, 2009

You do not have the roles required to access this portlet.

"You do not have the roles required to access this portlet." if you are getting this error while showing the portlets in your pages. You can hide them by setting

layout.show.portlet.access.denied=false in portal.properties file.

by default its value is true.

Struts Portlet example

If you want to develop portlets using Struts with existing liferay Struts action servlet then please go through this URL.


http://docs.liferay.com/portal/4.2/official/liferay-portlet-development-guide-4.2/multipage/ch03s02.html

PortletURL

This tutorial demonstrates how to get a Portlet to link back to itself within a JSP or even with the HTML code spit out within the doView method of a Portlet. The key is the PortletURL object... T...

URL :http://www.youtube.com/watch?v=SUlgKvWaZwo



Tuesday, March 10, 2009

Liferay

Liferay Portal provides jQuery as the default javascript library. This tutorial demonstrates how to build Standard tabbed page for your portlet using the jQuery library's tabs() method.

URL: http://www.youtube.com/watch?v=QBeomic29uc