Problem with Cewolf in portlet

Help
Juan
2005-11-25
2013-01-13
  • Juan
    Juan
    2005-11-25

    Hi.... I'm new to Cewolf, so forgive me if my problem is a stupid one. I've searched the forums and found no answer, so here it goes:

    I'm trying to develop a WebSphere Portal Server portlet that shows a Cewolf pie chart. After dealing with a lot of minor issues, I've gotten to the point  where I got a NullPointerException while executing the cewolf:img tag.

    This is the beginning of the stack trace:

    java.lang.NullPointerException
    at de.laures.cewolf.storage.AbstractSessionStorage.contains(AbstractSessionStorage.java:75)
    at de.laures.cewolf.storage.AbstractSessionStorage.storeChartImage(AbstractSessionStorage.java:53)
    at de.laures.cewolf.taglib.tags.ChartImgTag.doStartTag(ChartImgTag.java:79)

    Any ideas / help?

    Thanks a lot

     
    • SYKGEEK
      SYKGEEK
      2005-11-30

      Hi,
        I am having pretty much the same problem with Portlet. If you had any luck please let me know.

      I tried it on web app as well and i get the same error. Ia m wondering what it means.

      Thanks

       
    • Brian Fox
      Brian Fox
      2005-12-01

      This is the line crashing:
        public boolean contains( ChartImage cid, PageContext pageContext )
        {
          return pageContext.getSession().getAttribute(getKey(cid)) != null;
        }

      Does your portlet have a session? I'm not real familiar with portlets but it could be either the session or the pageContext.

       
    • SYKGEEK
      SYKGEEK
      2005-12-01

      Brian,
        Thanks for your reply. I am having the same problem when I run it on Web application containing only a JSP.  Please find my JSP below. I am just trying to make the code in example work.

      <%@ page session="false" contentType="text/html"%>
      <%@ page import ="org.jfree.data.category.DefaultCategoryDataset"%>

      <%@page import="de.laures.cewolf.*,org.jfree.data.category.CategoryDataset,org.jfree.data.category.DefaultIntervalCategoryDataset"%>
      <%@page import="org.jfree.data.category.*"%>
      <%@page import="de.laures.cewolf.tooltips.*"%>
      <%@page import="java.util.*"%>

      <%@taglib uri='/WEB-INF/cewolf.tld' prefix='cewolf' %>

      <%
      if (pageContext.getAttribute("initFlag") == null) {
         DatasetProducer categoryData = new DatasetProducer() {
        
          public Object produceDataset(Map params) {
            final String[] categories = { "apples", "pies", "bananas", "oranges" };
            final String[] seriesNames = { "Peter", "Helga", "Franz", "Olga" };
            final Integer[][] startValues = new Integer[seriesNames.length][categories.length];
            final Integer[][] endValues = new Integer[seriesNames.length][categories.length];
            for (int series = 0; series < seriesNames.length; series++) {
              for (int i = 0; i < categories.length; i++) {
                int y = (int) (Math.random() * 10 + 1);
                startValues[series][i] = new Integer(y);
                endValues[series][i] = new Integer(y + (int) (Math.random() * 10));
              }
            }
            DefaultIntervalCategoryDataset ds =
              new DefaultIntervalCategoryDataset(seriesNames, categories, startValues, endValues);
            return ds;
          }
          public String getProducerId() {
            return "CategoryDataProducer";
          }
          public boolean hasExpired(Map params, Date since) {
            return false;
          }
        };
        pageContext.setAttribute("categoryData", categoryData);
       
        CategoryToolTipGenerator catTG = new CategoryToolTipGenerator() {
          public String generateToolTip(CategoryDataset dataset, int series, int index) {
            return String.valueOf(dataset.getValue(series, index));
          }
        };
        pageContext.setAttribute("categoryToolTipGenerator", catTG);
       
      }
      %>

      <html>
      <head>
      <link href="cewolf.css" rel="stylesheet" type="text/css"></head>
      <BODY bgcolor="#DDE8F2">
      <H1>Domestic Sales Statistics</H1>
      <HR>
      <table border=0>
      <TR>
          <TD>

          <cewolf:chart id="horizontalBarChart" title="HorizontalBar" type="horizontalBar" xaxislabel="Fruit" yaxislabel="favorite">
              <cewolf:data>
                  <cewolf:producer id="categoryData" />
              </cewolf:data>
          </cewolf:chart>
         
          <cewolf:img chartid="horizontalBarChart" renderer="/cewolf" width="300" height="300">
              <cewolf:map tooltipgeneratorid="categoryToolTipGenerator"/>
          </cewolf:img>
          </TD>

          <TD>
          <cewolf:chart id="horizontalBarChart3D" title="HorizontalBar3D" type="horizontalBar3D" xaxislabel="Fruit" yaxislabel="favorite">
              <cewolf:data>
                  <cewolf:producer id="categoryData" />
              </cewolf:data>
          </cewolf:chart>
          <cewolf:img chartid="horizontalBarChart3D" renderer="/cewolf" width="300" height="300"/>
          </TD>
      </TR>

      </table>
      </BODY>
      </html>

       
    • Juan
      Juan
      2005-12-01

      Hi everyone.... It seems the NullPointerException is related to this piece of code

          <%@ page session="false" .... %>

      if you change it to

          <%@ page session="true" .... %>

      The exception goes, and it does a lot of sense, as the line that's causing the exception is trying to get the page context's session.

      Nevertheless, I still don't get my chart. Now it ALWAYS shows an image saying "The Chart has Expired. Please Reload". I've changed storage class from TransientSessionStorage to LongTermSessionStorage, I've added the "timeout=" in the <cewolf:img> tag, I've set "hasExpired()" to return always "true" and always "false", and nothing has change......

      Does anyone has any clue to what's happening?

      Thanks.....

       
    • Juan
      Juan
      2005-12-07

      Hi everyone.... I finally understand what's going on. Both TransientSessionStorage and LongTermSessionStorage use pageContext's session to store the image, and HttpServletRequest's session to retrieve the image.

      I don't know if these two sessions are the same on normal J2EE applications (I guess they are), but I think they're not the same on portlet environment. As far as I've gotten, it seems that WebSphere Portal Server creates a page context PER PORTLET in the page.

      This way, when the redering servlet access the session, it's accessing a different name space, and it doesn't find the stored image. That's why I always got the "Expired message".

      I've tried using FileStorage as the storage class, and it works perfectly.

      If I ever get to construct something called PortletSessionStorage, I'll post it here for further use.

      Thanks....

       
      • Brian Fox
        Brian Fox
        2005-12-08

        Thanks for the update. If you do get a storage working for portlets, I will certainly include it.

         
        • Hello Pablo,

          Was you successful with the problem?
          I try the framework with portlet jsr168 and have the same trouble.

          Many thanks!

          Best Regards,
          Dmitry Kirzhner

           
    • Hello Brian,

      Was you successful with the problem?
      I try the framework with portlet jsr168 and have the same trouble.

      Many thanks!

      Best Regards,
      Dmitry Kirzhner