web butcher

Sharing my knowledge to persuade you to share yours

articles

Posts Tagged ‘websphere portal’

Building a portlet with Google Maps on Websphere Portal

Wednesday, April 1st, 2009

There’s a link on the right to download the project files so you can import it to your RAD and run. Import as a Project Interchange file. If your RAD is greater than 7.0 do the migration. Also if you prefer follow the steps below and understand how I did.

The Google Maps API license is free, the only important rule is: Everything you develop using Google Maps API have to be for public use in the web. They have also a limit of showings per day, it’s a big number, something like 200,000. You have to read the terms if you want to know more. Google has an excellent documentation about that. It’s under http://code.google.com/apis/maps/documentation/.

For using Google Maps API you also have to get an API Key here: http://code.google.com/apis/maps/signup.html. The key is nothing more than a hash code of your server’s address, so you have to create a key for each site you use that.

Using Google Maps under Websphere Portal is nothing so different from using anywhere else. First of all, lets create a Portlet Project.



Create now a simple Web Diagram with an initial action and a jsp page. We will use the initial action to simulate something like reading point coordinates from database. This is our Web Diagram:



The file index.jsp will tell struts to go to initial action through the welcome forward. For this, just put the following in the end of the file:

<logic:forward name="welcome"/>

I’ve created a Point Bean Obejct. So, lets create an ArrayList of some of these points and store it in the session. For that, in the initial action try block, put this:

// Read points from database here.
ArrayList points = new ArrayList();
points.add(new Point("-11.95908", "-51.855469"));
points.add(new Point("-23.816841","-45.365124"));
points.add(new Point("-27.586999","-48.423014"));
// Store them on session
request.getPortletSession().setAttribute("points", points);

Create a bean for the points. You can use this point object to store any data from the point such as a html code with the description that will be showed when the user click the point.

package googlemapshelloworld.beans;
 
public class Point {
	private String latitude;
	private String longitude;
 
	public Point(String latitude, String longitude){
		this.latitude = latitude;
		this.longitude = longitude;
	}
 
	public String getLatitude() {
		return latitude;
	}
 
	public void setLatitude(String latitude) {
		this.latitude = latitude;
	}
 
	public String getLongitude() {
		return longitude;
	}
 
	public void setLongitude(String longitude) {
		this.longitude = longitude;
	}
 
}

The first time I used Maps in Portal I had a strange issue. In ie I got a gray screen over my map and I couldn“t see the entire map:



After doing some research I found that`s because ie has an issue about png transparency, something that Google Maps API makes use of. After navigating for a while, I found this: http://jquery.andreaseberhard.de/pngFix/

Download the pngFix.zip file and include the files on a js folder within your WebContent folder. Also load these files in your map.jsp file.

Project Explorer

<script type="text/javascript" src="<%= request.getContextPath() %>/js/jquery-1.3.2.min.js"></script> 
<script type="text/javascript" src="<%= request.getContextPath() %>/js/jquery.pngFix.js"></script>
 
<script type="text/javascript"> 
    $(document).ready(function(){ 
        $(document).pngFix(); 
    }); 
</script>

Also include the js for Maps API and create a div tag with the size you want with the id=”map”.

<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true_or_false&amp;key=[YOUR KEY HERE]" type="text/javascript"></script>
 
<script type="text/javascript">
setTimeout("loadMap()",1000);
 
var map;
function loadMap(){
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(-11.959, -51.8554), 4);
		map.setUIToDefault();
		loadPoints();
	}
}
 
//Function loadPoints goes here.
 
</script>
 
<div id="map" style="height:500px; width:500px"></div>

Let`s create a method to plot the points in the map. It sort of print javascript code with jsp:

function loadPoints(){ <%
	out.print("\nvar point;\nvar marker;");
	ArrayList points = (ArrayList) session.getAttribute("points");
	for (int i=0; i<points.size(); i++){
		out.println("		point = new GLatLng(" + ((Point)points.get(i)).getLatitude() + ", " + ((Point)points.get(i)).getLongitude() + ");");
		out.println("		marker = createMarker(point, 'We are here!');");
		out.println("		map.addOverlay(marker);");
	} %>
}
 
function createMarker(point, html){
	var marker = new GMarker(point);
	GEvent.addListener(marker, "click", function() { 
		marker.openInfoWindowHtml(html);
	});
	return marker;
}

Done.

WebSphere Portal 6 with RAD 7 Installation

Friday, March 20th, 2009

Installing WebSphere Portal can be very simple, you just have to remember some details.

In my example, we will need Portal Setup Disks, Rad Setup Disks, Rad Fix (7.0.0.4) and Rad Activation Kit (license).

Open the first cd from Portal installation and run install.bat there.



In the three initial screens, just click Next, Accept and Next again. Just select Typical installation and proceed.

In the next screen, choose your directory installation, it`s recommended that you create an IBM directory and put everything on it. In my case, I`ve chosen C:\IBM\WebSphere\AppServer. It will install Application Server.



Proceed clicking Next until you come to this screen. Here you can use your preferred names.



In the next screen, choose the administrative user and password, by default, I use “wpsadmin” for user and password.



Don’t install the Business Process Support, we will not need that.



Now, let’s install the WebSphere Portal Server. It’s recommended that you put it in the same IBM directory, like that: C:\IBM\WebSphere\PortalServer



In the next screen, you will be asked for administrative user and password for Portal, it’s recommended that you use the same that you used on Application Server.



Now, you have the option of using server as a Windows service, it’s not recommended, don’t mark nothing here. Click Next again and wait, it will start installing and will take long time.



In the end, unmark “Launch First Steps” and click Finish. Your WebSphere Application Server and WebSphere Portal Server are now installed.



Let’s now install Rational Application Developer 7 (RAD). At first, install the installation manager. Go to the radfix4 folder and run install on im.installer.win32-1.1.0 folder, it will be installed the IBM Installation Manager 1.1.



Run the Installation Manager now. Go to file/preferences and click repositories/add repositories. Locate the file diskTag.inf on disk 1 of RAD Installation to add the repository. Now go to “Install Packages”. Don’t forget changing the directories to your IBM directory.

(C:\IBM\SDP70Shared):



(C:\IBM\SDP70):



Keep going until you see the screen below. You must mark the options “Portal Tools” and “Struts Tools” here. Click Next, Install and go on.



Now, we must install the Rad fixes. Go to the installation manager in your Windows start menu. Go to file/preferences and click repositories/add repositories. Find the diskTag.inf on the radfix4 dir disk1.

It’s recommended that, in this step, you disconnected your internet to avoid Installation Manager to look for sources on the web.



Click OK. Click Update Packages and go on. Your RAD will be update to version 7.0.0.4.

We are almost done. Now, install the License. On the Installation Manager, click “Manage Licenses”, “Import Product Activation Kit”. Find the file RADLic.jar on your RAD Activation Kit directory.



Now, you have all done. You can now open your RAD by the Windows start menu. To add Websphere Portal control inside your RAD, go to Servers Tab, right-click, then click New Server. Select “Websphere Portal Server V6.0 Server”. Click Next.



Use the password you’ve created at Portal installation. Click Finish. Now you’re ready to develop struts portlets using your RAD and WebSphere Portal. Any questions, feel free to post. No login necessary.