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">
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">
supports>
portlet-info>
portlet>
portlet-app>
portlet-instances.xml:
xml version="1.0" encoding="UTF-8"?>
DOCTYPE deployments PUBLIC
"-//JBoss Portal//DTD Portlet Instances 2.6//EN"
"http://www.jboss.org/portal/dtd/portlet-instances_2_6.dtd">
instance>
deployment>
deployments>
web.xml:
xml version="1.0" encoding="UTF-8"?>
welcome-file-list>
web-app>
No comments:
Post a Comment