Tuesday, July 06, 2010

Integration of Portal with GWT.

MyGWTPortal : This example give you the simple way of integrating GWT with Portal Technology.

Refer this site for reference http://xantorohara.blogspot.com/2007/07/portlets-and-gwt.html for more info.

MyGWTPortal:

package myGWTPortal;

import javax.portlet.GenericPortlet;

import javax.portlet.PortletException;

import javax.portlet.PortletSecurityException;

import javax.portlet.RenderRequest;

import javax.portlet.RenderResponse;

import java.io.IOException;

import java.io.PrintWriter;

/*

*Refer this site for reference http://xantorohara.blogspot.com/2007/07/portlets-and-gwt.html

*/

public class MyGWTPortal extends GenericPortlet

{

protected void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, PortletSecurityException, IOException

{

renderResponse.setContentType("text/html");

PrintWriter writer = renderResponse.getWriter();

System.out.println("value of renderRequest.getContextPath()>>>>>"+renderRequest.getContextPath());

writer.println("");

writer.println("GWT time:");

writer.println("

");

writer.close();

}

protected void doHelp(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, PortletSecurityException, IOException

{

renderResponse.setContentType("text/html");

PrintWriter writer = renderResponse.getWriter();

writer.write("Help");

writer.close();

}

protected void doEdit(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, PortletSecurityException, IOException

{

renderResponse.setContentType("text/html");

PrintWriter writer = renderResponse.getWriter();

writer.println("Edit");

writer.close();

}

}

MyGWTPortal.gwt.xml:

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

<module rename-to='mygwtportal'>

<inherits name='com.google.gwt.user.User' />

<inherits name='com.google.gwt.user.theme.standard.Standard' />

<entry-point class='myGWTPortal.client.MyGWTPortalClient' />

<servlet path="/MyGWTPortalService" class="myGWTPortal.server.GreetingServiceImpl" />

<source path='client' />

<source path='shared' />

module>

GreetingService:

package myGWTPortal.client;

import com.google.gwt.core.client.GWT;

import com.google.gwt.user.client.rpc.RemoteService;

import com.google.gwt.user.client.rpc.ServiceDefTarget;

import myGWTPortal.client.Time;

/**

* The client side stub for the RPC service.

*/

//@RemoteServiceRelativePath("MyGWTPortalService")

public interface GreetingService extends RemoteService {

//String greetServer(String name) throws IllegalArgumentException;

Time getTime();

public static class App {

private static myGWTPortal.client.GreetingServiceAsync ourInstance = null;

public static synchronized myGWTPortal.client.GreetingServiceAsync getInstance() {

if (ourInstance == null) {

ourInstance = (myGWTPortal.client.GreetingServiceAsync) GWT.create(GreetingService.class);

((ServiceDefTarget) ourInstance).setServiceEntryPoint(GWT.getModuleBaseURL() + "GreetingService");

}

return ourInstance;

}

}

}

GreetingServiceAsync:

package myGWTPortal.client;

import com.google.gwt.user.client.rpc.AsyncCallback;

/**

* The async counterpart of GreetingService.

*/

public interface GreetingServiceAsync {

//void greetServer(String input, AsyncCallback callback)throws IllegalArgumentException;

void getTime(AsyncCallback callback);

}

MyGWTPortalClient:

package myGWTPortal.client;

import com.google.gwt.core.client.EntryPoint;

import com.google.gwt.user.client.Timer;

import com.google.gwt.user.client.Window;

import com.google.gwt.user.client.rpc.AsyncCallback;

import com.google.gwt.user.client.ui.Label;

import com.google.gwt.user.client.ui.RootPanel;

/**

* Entry point classes define onModuleLoad().

*/

public class MyGWTPortalClient implements EntryPoint {

/*

private static final String SERVER_ERROR = "An error occurred while "

+ "attempting to contact the server. Please check your network "

+ "connection and try again.";

private final GreetingServiceAsync greetingService = GWT

.create(GreetingService.class);

public void onModuleLoad() {

greetingService.greetServer("Called",

new AsyncCallback() {

public void onFailure(Throwable caught) {

// Show the RPC error message to the user

RootPanel.get().add(new HTML("RPC call failed. :-("));

}

public void onSuccess(String result) {

System.out.println("Vaule of result is:"+result);

RootPanel.get().add(new HTML("RPC call Success:"));

}

});

}

*/

private Timer timer;

private Label label = new Label("Wait...");

private class CallBack implements AsyncCallback

{

public void onFailure(Throwable caught)

{

timer.cancel();

Window.alert(caught.getMessage());

}

public void onSuccess(Object result)

{

label.setText(((Time) result).getTime());

}

}

private CallBack callBack = new CallBack();

public void onModuleLoad()

{

RootPanel.get("uid").add(label);

timer = new Timer()

{

public void run()

{

GreetingService.App.getInstance().getTime(callBack);

}

};

timer.scheduleRepeating(1000);

}

}


Time:

package myGWTPortal.client;

import com.google.gwt.user.client.rpc.IsSerializable;

public class Time implements IsSerializable

{

private String time;

public String getTime() { return time; }

public Time(String message) { this.time = message; }

public Time() { }

}

GreetingServiceImpl:

package myGWTPortal.server;

import java.text.DateFormat;

import java.util.Date;

import myGWTPortal.client.GreetingService;

import myGWTPortal.client.Time;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**

* The server side implementation of the RPC service.

*/

//@SuppressWarnings("serial")

public class GreetingServiceImpl extends RemoteServiceServlet implements

GreetingService {

/*

public String greetServer(String input) throws IllegalArgumentException {

System.out.println("Here reached at GreetingServiceImpl:");

return "hi";

}

*/

public Time getTime()

{

String out = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.FULL).format(new Date());

return new Time(out);

}

}

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">

<deployments>

<deployment>

<parent-ref>default.defaultparent-ref>

<if-exists>overwriteif-exists>

<window>

<window-name>

MyGWTPortalWindow

window-name>

<instance-ref>

MyGWTPortalInstance

instance-ref>

<region>centerregion>

<height>1height>

<initial-window-state>maximizedinitial-window-state>

window>

deployment>

deployments>

MyGWTPortal-object.xml:

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

<deployments>

<deployment>

<if-exists>overwriteif-exists>

<parent-ref>defaultparent-ref>

<page>

<page-name>XLampage-name>

<window>

<window-name>MyGWTPortalWindowwindow-name>

<instance-ref>MyGWTPortalInstanceinstance-ref>

<region>leftregion>

<height>0height>

window>

page>

deployment>

deployments>

portlet.xml:

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

<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"

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

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

http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"

version="1.0">

<portlet>

<portlet-name>MyGWTPortalportlet-name>

<portlet-class>myGWTPortal.MyGWTPortalportlet-class>

<supports>

<mime-type>text/htmlmime-type>

<portlet-mode>VIEWportlet-mode>

<portlet-mode>EDITportlet-mode>

<portlet-mode>HELPportlet-mode>

supports>

<portlet-info>

<title>MyGWTPortal Portaltitle>

portlet-info>

portlet>

portlet-app>

portlet-instances.xml:

xml version="1.0" standalone="yes"?>

<deployments>

<deployment>

<instance>

<instance-id>MyGWTPortalInstanceinstance-id>

<portlet-ref>MyGWTPortalportlet-ref>

instance>

deployment>

deployments>

web.xml:

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

DOCTYPE web-app

PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<servlet>

<servlet-name>MyGWTPortalServiceservlet-name>

<servlet-class>

myGWTPortal.server.GreetingServiceImpl

servlet-class>

servlet>

<servlet-mapping>

<servlet-name>MyGWTPortalServiceservlet-name>

<url-pattern>/MyGWTPortalServiceurl-pattern>

servlet-mapping>

<servlet-mapping>

<servlet-name>MyGWTPortalServiceservlet-name>

<url-pattern>/mygwtportal/GreetingServiceurl-pattern>

servlet-mapping>

web-app>

MyGWTPortal.html:

<html>

<head>

<title>MyGWTPortaltitle>

head>

<body>

<script language='javascript' src="mygwtportal/mygwtportal.nocache.js">script>

<div id='uid'>div>

body>

html>

No comments: