You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by b_prajesh <pb...@lbl.gov> on 2010/08/24 18:42:56 UTC
Trouble showing graph in portlet
Hello All,
I am very new to portlet development. I have no experience with servlet
development either. I am trying to show a graph in a portlet. I am using
JFreeChart library for charting.
My portlet container is JetSpeed2 (2.2.1). As a test case, first I tested my
code with a line of text. It worked. Then I tried to move on to graphics,
but my graphics never showed up in the portlet. I decided to test if my
portlet could show a static image stored on the disk. I did not have any
luck even with that. I have followed methodology/code provided at
http://blogs.sun.com/satya/entry/new_feature_resource_serving_in
Can someone please point out the problem here? If you need more information,
please let me know. I really appreciate your help.
Thanks.
Prajesh
Following is my portlet code. Please note that I have tested the line
ChartUtilities.writeChartAsJPEG(image_out, quality, demo.chart, 400,300);
inside a stand-alone app in which image_out was a FileOutputStream.
********************************************************
import java.io.IOException;
import java.io.OutputStream;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.portlet.ResourceURL;
import java.io.PrintWriter;
import org.jfree.chart.ChartUtilities;
// import org.jfree.ui.RefineryUtilities;
// import org.jfree.util.Log;
// import org.jfree.util.PrintStreamLogTarget;
public class ScatterPlot extends GenericPortlet {
public void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
// Log.getInstance().addTarget(new PrintStreamLogTarget());
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
ResourceURL resURL = response.createResourceURL();
resURL.setResourceID("image");
writer.println(" \"" ");
}
public void serveResource(ResourceRequest resRequest, ResourceResponse
resResp)
throws PortletException, IOException {
resResp.setContentType("image/jpeg");
OutputStream image_out = resResp.getPortletOutputStream();
TimeSeriesDemo demo = new TimeSeriesDemo("Time Series");
float quality = (float)(0.75);
ChartUtilities.writeChartAsJPEG(image_out, quality, demo.chart, 400,300);
image_out.flush();
image_out.close();
}
} // end of class
**********************************************************************
Following is my portlet.xml.
*********************************************************************
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app id="ScatterPlot" version="1.0">
<portlet id="ScatterPlot_ID">
<description>Plot as many variables on the Y axis against the ONLY
variable on the X axis</description>
<portlet-name>ScatterPlot_Name</portlet-name>
<display-name>Scatter Plot</display-name>
<portlet-class>ScatterPlot</portlet-class>
<expiration-cache>-1</expiration-cache>
<supports>
<mime-type>*/*</mime-type>
<portlet-mode>VIEW</portlet-mode>
<portlet-mode>HELP</portlet-mode>
<portlet-mode>EDIT</portlet-mode>
<!-- support custom about mode -->
<portlet-mode>about</portlet-mode>
<!-- support custom edit_defaults mode -->
<portlet-mode>edit_defaults</portlet-mode>
<!-- support custom preview mode -->
<portlet-mode>preview</portlet-mode>
<!-- support custom print mode -->
<portlet-mode>print</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<portlet-info>
<title>Scatter Plot</title>
</portlet-info>
</portlet>
</portlet-app>
*********************************************************************
Following is my 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>
<display-name>ScatterPlot</display-name>
<description>Scatter Plot Portlet</description>
</web-app>
***********************************************************************
--
View this message in context: http://old.nabble.com/Trouble-showing-graph-in-portlet-tp29524013p29524013.html
Sent from the Jetspeed - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org
Re: Trouble showing graph in portlet
Posted by b_prajesh <pb...@lbl.gov>.
The following link has all the files.
http://www.4shared.com/dir/4QG57zFE/ScatterPlot.html
Thanks.
Prajesh
David Sean Taylor-3 wrote:
>
> On Tue, Aug 24, 2010 at 9:42 AM, b_prajesh <pb...@lbl.gov> wrote:
>>
>> Hello All,
>>
>> I am very new to portlet development. I have no experience with servlet
>> development either. I am trying to show a graph in a portlet. I am using
>> JFreeChart library for charting.
>>
>> My portlet container is JetSpeed2 (2.2.1). As a test case, first I tested
>> my
>> code with a line of text. It worked. Then I tried to move on to graphics,
>> but my graphics never showed up in the portlet. I decided to test if my
>> portlet could show a static image stored on the disk. I did not have any
>> luck even with that. I have followed methodology/code provided at
>> http://blogs.sun.com/satya/entry/new_feature_resource_serving_in
>>
>> Can someone please point out the problem here? If you need more
>> information,
>> please let me know. I really appreciate your help.
>>
> Could you make your entire war file + source code available so we can
> debug it? It would be easier since we don't know what dependencies you
> have with JFreeChart and its dependencies
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>
>
--
View this message in context: http://old.nabble.com/Trouble-showing-graph-in-portlet-tp29524013p29528697.html
Sent from the Jetspeed - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org
Re: Trouble showing graph in portlet
Posted by David Sean Taylor <d....@onehippo.com>.
On Tue, Aug 24, 2010 at 9:42 AM, b_prajesh <pb...@lbl.gov> wrote:
>
> Hello All,
>
> I am very new to portlet development. I have no experience with servlet
> development either. I am trying to show a graph in a portlet. I am using
> JFreeChart library for charting.
>
> My portlet container is JetSpeed2 (2.2.1). As a test case, first I tested my
> code with a line of text. It worked. Then I tried to move on to graphics,
> but my graphics never showed up in the portlet. I decided to test if my
> portlet could show a static image stored on the disk. I did not have any
> luck even with that. I have followed methodology/code provided at
> http://blogs.sun.com/satya/entry/new_feature_resource_serving_in
>
> Can someone please point out the problem here? If you need more information,
> please let me know. I really appreciate your help.
>
Could you make your entire war file + source code available so we can
debug it? It would be easier since we don't know what dependencies you
have with JFreeChart and its dependencies
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org
Re: Trouble showing graph in portlet
Posted by b_prajesh <pb...@lbl.gov>.
I was busy with other stuff in the last 2 days. I just tried it and there it
was! Awesome! Thanks a lot!
Prajesh
David Sean Taylor-3 wrote:
>
> On Wed, Aug 25, 2010 at 11:11 AM, Woonsan Ko <wo...@yahoo.com> wrote:
>> I think you should use "2.0" for the portlet app version in the portlet
>> descriptor.
>> Jetspeed-2 does not invoke resource serving operation when the portlet
>> application is "1.0".
>>
>> <portlet-app id="ScatterPlot" version="2.0">
>
> I downloaded the war, and it failed to display the scatter plot. I
> then changed the version to "2.0", and that fixed it. Thanks Woonsan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>
>
--
View this message in context: http://old.nabble.com/Trouble-showing-graph-in-portlet-tp29524013p29552960.html
Sent from the Jetspeed - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org
Re: Trouble showing graph in portlet
Posted by David Sean Taylor <d....@onehippo.com>.
On Wed, Aug 25, 2010 at 11:11 AM, Woonsan Ko <wo...@yahoo.com> wrote:
> I think you should use "2.0" for the portlet app version in the portlet descriptor.
> Jetspeed-2 does not invoke resource serving operation when the portlet application is "1.0".
>
> <portlet-app id="ScatterPlot" version="2.0">
I downloaded the war, and it failed to display the scatter plot. I
then changed the version to "2.0", and that fixed it. Thanks Woonsan
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org
Re: Trouble showing graph in portlet
Posted by Woonsan Ko <wo...@yahoo.com>.
I think you should use "2.0" for the portlet app version in the portlet descriptor.
Jetspeed-2 does not invoke resource serving operation when the portlet application is "1.0".
<portlet-app id="ScatterPlot" version="2.0">
-Woonsan
--- On Tue, 8/24/10, b_prajesh <pb...@lbl.gov> wrote:
> From: b_prajesh <pb...@lbl.gov>
> Subject: Trouble showing graph in portlet
> To: jetspeed-user@portals.apache.org
> Date: Tuesday, August 24, 2010, 6:42 PM
>
> Hello All,
>
> I am very new to portlet development. I have no experience
> with servlet
> development either. I am trying to show a graph in a
> portlet. I am using
> JFreeChart library for charting.
>
> My portlet container is JetSpeed2 (2.2.1). As a test case,
> first I tested my
> code with a line of text. It worked. Then I tried to move
> on to graphics,
> but my graphics never showed up in the portlet. I decided
> to test if my
> portlet could show a static image stored on the disk. I did
> not have any
> luck even with that. I have followed methodology/code
> provided at
> http://blogs.sun.com/satya/entry/new_feature_resource_serving_in
>
> Can someone please point out the problem here? If you need
> more information,
> please let me know. I really appreciate your help.
>
> Thanks.
> Prajesh
>
> Following is my portlet code. Please note that I have
> tested the line
> ChartUtilities.writeChartAsJPEG(image_out, quality,
> demo.chart, 400,300);
> inside a stand-alone app in which image_out was a
> FileOutputStream.
>
> ********************************************************
> import java.io.IOException;
> import java.io.OutputStream;
> import javax.portlet.GenericPortlet;
> import javax.portlet.PortletException;
> import javax.portlet.RenderRequest;
> import javax.portlet.RenderResponse;
> import javax.portlet.ResourceRequest;
> import javax.portlet.ResourceResponse;
> import javax.portlet.ResourceURL;
> import java.io.PrintWriter;
>
> import org.jfree.chart.ChartUtilities;
> // import org.jfree.ui.RefineryUtilities;
> // import org.jfree.util.Log;
> // import org.jfree.util.PrintStreamLogTarget;
>
>
> public class ScatterPlot extends GenericPortlet {
>
>
> public void doView(RenderRequest request, RenderResponse
> response)
>
> throws PortletException,
> IOException {
>
> //
> Log.getInstance().addTarget(new PrintStreamLogTarget());
>
> response.setContentType("text/html");
> PrintWriter writer =
> response.getWriter();
>
> ResourceURL resURL =
> response.createResourceURL();
> resURL.setResourceID("image");
> writer.println(" \"" ");
>
> }
>
>
>
>
> public void serveResource(ResourceRequest resRequest,
> ResourceResponse
> resResp)
>
> throws PortletException, IOException {
>
> resResp.setContentType("image/jpeg");
> OutputStream image_out =
> resResp.getPortletOutputStream();
>
> TimeSeriesDemo demo = new
> TimeSeriesDemo("Time Series");
> float quality = (float)(0.75);
>
> ChartUtilities.writeChartAsJPEG(image_out, quality,
> demo.chart, 400,300);
> image_out.flush();
> image_out.close();
> }
>
> } // end of class
> **********************************************************************
>
>
> Following is my portlet.xml.
> *********************************************************************
> <?xml version="1.0" encoding="UTF-8"?>
>
> <portlet-app id="ScatterPlot" version="1.0">
>
> <portlet id="ScatterPlot_ID">
> <description>Plot as many variables on
> the Y axis against the ONLY
> variable on the X axis</description>
>
> <portlet-name>ScatterPlot_Name</portlet-name>
> <display-name>Scatter
> Plot</display-name>
>
> <portlet-class>ScatterPlot</portlet-class>
>
>
> <expiration-cache>-1</expiration-cache>
> <supports>
>
> <mime-type>*/*</mime-type>
>
> <portlet-mode>VIEW</portlet-mode>
>
> <portlet-mode>HELP</portlet-mode>
>
> <portlet-mode>EDIT</portlet-mode>
> <!-- support custom about
> mode -->
>
> <portlet-mode>about</portlet-mode>
> <!-- support custom
> edit_defaults mode -->
>
> <portlet-mode>edit_defaults</portlet-mode>
> <!-- support custom preview
> mode -->
>
> <portlet-mode>preview</portlet-mode>
> <!-- support custom print
> mode -->
>
> <portlet-mode>print</portlet-mode>
> </supports>
>
> <supported-locale>en</supported-locale>
>
> <portlet-info>
> <title>Scatter
> Plot</title>
> </portlet-info>
>
> </portlet>
>
> </portlet-app>
> *********************************************************************
>
>
> Following is my 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>
>
>
> <display-name>ScatterPlot</display-name>
> <description>Scatter Plot
> Portlet</description>
>
> </web-app>
> ***********************************************************************
> --
> View this message in context: http://old.nabble.com/Trouble-showing-graph-in-portlet-tp29524013p29524013.html
> Sent from the Jetspeed - User mailing list archive at
> Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org