Tuesday, July 06, 2010

Portal Example - Showing Addition of Two value Sample.


Helloworld:

package com.mastertheboss;

import java.io.IOException;

import java.io.PrintWriter;

import javax.portlet.ActionRequest;

import javax.portlet.ActionResponse;

import javax.portlet.GenericPortlet;

import javax.portlet.PortletException;

import javax.portlet.PortletMode;

import javax.portlet.PortletPreferences;

import javax.portlet.PortletURL;

import javax.portlet.RenderRequest;

import javax.portlet.RenderResponse;

import javax.portlet.UnavailableException;

import javax.portlet.WindowState;


public class Helloworld extends GenericPortlet {


/**

* Default constructor.

*/

public Helloworld() {

// TODO Auto-generated constructor stub

}


/* (non-Javadoc)


* @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest, javax.portlet.RenderResponse)


*/


@Override

protected void doView(RenderRequest request, RenderResponse response)

throws PortletException, IOException, UnavailableException {

/*

response.setContentType("text/html");

PrintWriter writer = response.getWriter();

writer.write("Hello World!");

writer.close();

*/


PortletPreferences pref = request.getPreferences();

String firstValue = pref.getValue("firstValue","");

String secondValue = pref.getValue("secondValue","");

int f = 0;

int s = 0;

if(!firstValue.equals("") && firstValue != null)

{

f = Integer.parseInt(firstValue);

}

if(!secondValue.equals("") && secondValue != null)

{

s = Integer.parseInt(secondValue);

}

int ans = f + s;

response.setContentType(request.getResponseContentType());

PrintWriter writer = response.getWriter();

writer.write("Hello value of addition of two values is:" + ans);

}

public void processAction(ActionRequest request, ActionResponse response) throws PortletException {

String firstValue = request.getParameter("FIRSTVAUE");

String secondValue = request.getParameter("SECONDVALUE");

try {

PortletPreferences pref = request.getPreferences();

pref.setValue("firstValue", firstValue);

pref.setValue("secondValue", secondValue);

pref.store();

} catch (Exception e) {

throw new PortletException(e.getMessage());

}

response.setPortletMode(PortletMode.VIEW);

response.setWindowState(WindowState.NORMAL);

}


public void doEdit(RenderRequest request,RenderResponse response) throws PortletException,IOException {

PortletURL actionURL = response.createActionURL();

response.setContentType(request.getResponseContentType());

PrintWriter writer = response.getWriter();

writer.write("

writer.write("'>

firstValue:

secondValue:

");

}

public void doHelp(RenderRequest request, RenderResponse response) throws PortletException {

response.setContentType(request.getResponseContentType());

try {

response.setContentType(request.getResponseContentType());

PrintWriter writer = response.getWriter();

writer.write("Pref Portlet Help

");


} catch (IOException e) {


throw new PortletException("PrefPortlet.doHelp exception", e);


}


}


}

default-object.xml:

xml version="1.0" encoding="UTF-8"?>

DOCTYPE deployments PUBLIC

"-//JBoss Portal//DTD Portal Object 2.6//EN"

"http://www.jboss.org/portal/dtd/portal-object_2_6.dtd">

default.defaultparent-ref>

overwriteif-exists>

HelloworldWindowwindow-name>

HelloworldInstanceinstance-ref>

centerregion>

1height>

maximizedinitial-window-state>

window>

deployment>

deployments>

portlet.xml:


xml version="1.0" encoding="UTF-8"?>

xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"

version="2.0">

Helloworldportlet-name>

Helloworlddisplay-name>

com.mastertheboss.Helloworldportlet-class>

text/htmlmime-type>

VIEWportlet-mode>

EDITportlet-mode>

HELPportlet-mode>

supports>

Helloworldtitle></p><p class="MsoNormal">portlet-info></p><p class="MsoNormal">portlet></p><p class="MsoNormal">portlet-app></p><p class="MsoNormal"><br /></p><p class="MsoNormal"><br /></p><p class="MsoNormal">portlet-instances.xml:</p><p class="MsoNormal"><br /></p><p class="MsoNormal">xml version="1.0" encoding="UTF-8"?></p><p class="MsoNormal">DOCTYPE deployments PUBLIC</p><p class="MsoNormal">"-//JBoss Portal//DTD Portlet Instances 2.6//EN"</p><p class="MsoNormal">"http://www.jboss.org/portal/dtd/portlet-instances_2_6.dtd"></p><p class="MsoNormal"><deployments></p><p class="MsoNormal"><deployment></p><p class="MsoNormal"><instance></p><p class="MsoNormal"><instance-id>HelloworldInstanceinstance-id></p><p class="MsoNormal"><portlet-ref>Helloworldportlet-ref></p><p class="MsoNormal">instance></p><p class="MsoNormal">deployment></p><p class="MsoNormal">deployments></p><p class="MsoNormal"><br /></p><p class="MsoNormal"><br /></p><p class="MsoNormal">web.xml:</p><p class="MsoNormal"><br /></p><p class="MsoNormal">xml version="1.0" encoding="UTF-8"?></p><p class="MsoNormal"><web-app xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"></p><p class="MsoNormal"><display-name>MyTestPortaldisplay-name></p><p class="MsoNormal"><welcome-file-list></p><p class="MsoNormal"><welcome-file>index.htmlwelcome-file></p><p class="MsoNormal"><welcome-file>index.htmwelcome-file></p><p class="MsoNormal"><welcome-file>index.jspwelcome-file></p><p class="MsoNormal"><welcome-file>default.htmlwelcome-file></p><p class="MsoNormal"><welcome-file>default.htmwelcome-file></p><p class="MsoNormal"><welcome-file>default.jspwelcome-file></p><p class="MsoNormal">welcome-file-list></p><p class="MsoNormal">web-app></p><p class="MsoNormal"><br /></p><p class="MsoNormal"></code></p><p class="MsoNormal"><br /></p><p class="MsoNormal"><br /></p><p class="MsoNormal"><br /></p><p></p>

No comments: