Showing posts with label JSR286. Show all posts
Showing posts with label JSR286. Show all posts

Wednesday, April 30, 2014

Portlets deployed with EAR file are not available in portal server

We usually deploying portlets on portal server and we know portal server always takes WAR file. Now we are working on business applications where we do not have only portlets. We have EJBs, JSP components, WCM plugins, custom workflows along with portlets.

So keeping WAR file separate with other components is not a better idea. It is better to keep EAR file on WAS which will help us to deploy everything at one go.

Now we have some observations that deployment with EAR file is not reflecting portlets on portal environment. We got one thing that deployment of WAR file with portlets are reflecting portlets on portal environment but EAR with portlets and other components are not reflecting portlets on portal environment.

This is happening since WAR deployment store portlets entry in portal DB but EAR deployment is not storing that entry.

So applying this entry, we need to apply XML file on portal server. This will make available portlets on portal server.

You will find reference links with following links,
http://publib.boulder.ibm.com/infocenter/wpdoc/v6r0/index.jsp?topic=/com.ibm.wp.ent.doc/wps/adprdplt.html

http://wpcertification.blogspot.in/2009/03/installing-portlet.html

There is one more thing which I would like to share,
when we apply XML on portal server, immediately WAR file [part of EAR] is available in portal server environment.
In case, you want to update any specific portlet, you can delete WAR file in portal environment and apply XML file again otherwise use 'update' [instead of 'create'] in XML file and apply on portal server.

Monday, August 23, 2010

Serving resource using JSR 286

In JSR 286, one more method is getting introduced in portlet life cycle that is serveResource, the advantage of this method is, we can get resource in portlet response which is not possible in JSR 168.

Let's take an example for better understanding the use of serveResource method. Suppose, you have a collection of images and you need to display different images according to the selection. What you will do is?
First, you need to create a resource URL as mentioned below,

ResourceURL resourceURL = renderResponse.createResourceURL();

Now, you need to make a hiperlink through which you call the serveResource method. The code for reference is,
<a href="<%=resourceURL.toString() %>">Resource</a>

When you click on this link, it makes an Ajax call using resourceURL and call the serveResource method. Once it is called you can set the response for images (which is not effected in JSR 168) and write this byte format of image in XML format. Now response is ready which is called using Ajax callback methods. The reference code lines are,

public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {   
 response.setContentType("image/jpeg");
 // Image in byte stream
 byte[] b = getImage(); //Returns image bytes
 // writing image byte stream on portlet response
 response.getPortletOutputStream().write(b);
}

Also, you can use different types of resources. What you need to do is?
you have to add the following code with resourceURL,
resourceURL.setResourceID("image");

Through this ID you can perform your logic according to the image resource ID. You can get Id in serveResource method using code below,

request.getResourceID().

Wednesday, July 7, 2010

How portlet modes work in portal environment?

I have one JSR-168 based portlet in which I am using all kinds of modes. These are,

1) View Mode
2) Edit Mode
3) Help Mode
4) Edit-Default Mode
5) Config Mode

Now, I have one question in my mind. What is the use of these modes? If we take an example of any web-based application which is deployed on web container and this application does not have any kind of mode. Here I am going to describe a brief description of portlet modes which are helpful to understand the benefits of portlet application over web-based J2EE application.

View Mode -
This is the landing page of the portlet.

Edit Mode -
This is the different page of the portlet for storing personalized settings. These settings allowed for a particular instance of the portlet for particular portal user. If we make another instance of portlet in another page, personalized variable is not allowed to accessible.

Edit - Default Mode -
This is also different page of the portlet. We are using this mode for storing the configuration parameters of the portlet which are accessible for all portal users for the same portlet instances. For Example. An admin stores some parameters in edit-default mode of portlet and check the availability of these parameters in other portal users. These parameters are available for all portal users for a particular instance of the portlet suppose you add same portlet in different page, you will not allowed to see stored parameters for different instances of portlet.

Config Mode -
This is also different page of the portlet. We are using this mode for storing the configuration parameters of portlets which is accessible for all portal users for all portlet instances.

Now we have a big picture, how these modes are working in portal environment? We have tested this procedure for IBM Web Sphere portal server 6.0 using RAD 7.0 and JSR 168 specification.

Monday, June 7, 2010

Event Handling in JSR - 286

As we all know about event handing. We perform some action on a source which is targeted to other source. When we talk about in an application, this task is very easy for us since we have certain methods through which we can pass data from one source to another source. In other way, you can pass your data from one source to another source of same application. Along with we talk about different applications (different WAR’s) which are running on same container. Can we pass data from one application to another application?

Yes, this is possible in JSR-286 where we can pass the data from one application to another application. In this process, we perform an action from one application which passes the data to another application.

There are some steps which describe how we can do it in Portlet applications. The steps are,

1) Let us take two portlet applications. Sender portlet application generates the event and receiver portlet application receives the event data from sender application.

2) Firstly, you need to add some configuration on portlet.xml file. What you need to do is you have to add event-definition information in sender application's portlet.xml file and receiver application's portlet.xml file. This is as,

<event-definition>
<qname xmlns:x="http://ndilip.com/events">x:ndilipevent</qname>
<value-type>java.lang.String</value-type>
</event-definition>

3) Now, you need to add 'supported-publishing-event' tag information under portlet tag of portlet.xml file for sender application. This is as,

<supported-publishing-event>
<qname xmlns:x="http://ndilip.com/events">x:ndilipevent</qname>
</supported-publishing-event>

These are the steps which are required in sender portlet application.

4) Now, you need to know, how to create event from sender application. The codes are,

QName qName = new QName("http://ndilip.com/events", "ndilipevent");
response.setEvent(qName, paramStr);

You have to add this code at processAction method.

5) Now you need to understand how you can handle this event on receiver portlet application.

6) You need to add 'supported-processing-event' tag information under portlet tag of portlet.xml file for receiver application. This is as,

<supported-processing-event>
<qname xmlns:x="http://ndilip.com/events">x:ndilipevent</qname>
</supported-processing-event>

7) Now, you need to know how you can utilize the event which is created by sender portlet application. You have to add processEvent method which handles the event created by sender. The codes are,

public void processEvent(EventRequest request, EventResponse response) {
Event event = request.getEvent();
String value = (String) event.getValue();
String valueString=value.toString();
}

valueString is the event string value comes from sender application.