5 Replies Latest reply on Jul 13, 2010 5:52 AM by Minh Hoang TO

    Portlet Edit mode throws NullPointer (GateIn 3.1)

    g.nuijen Newbie

      Hello,

       

      I am trying to create a portlet with an edit mode, but I am running into some troubles. It is based on PortletBridge 2.0.0.FINAL + seam and facelets.

       

      portlet.xml:

       

      <portlet>
      <portlet-name>chartPortlet</portlet-name>
      <portlet-class>javax.portlet.faces.GenericFacesPortlet</portlet-class>
       
      <init-param>
      <name>javax.portlet.faces.defaultViewId.view</name>
      <value>/chart.xhtml</value>
      </init-param>
      <init-param>
      <name>javax.portlet.faces.defaultViewId.edit</name>
      <value>/chart_config.xhtml</value>
      </init-param>
      <init-param>
      <name>javax.portlet.faces.preserveActionParams</name>
      <value>true</value>
      </init-param>
      <init-param>
      <name>javax.portlet.faces.autoDispatchEvents</name>
      <value>true</value>
      </init-param>
      <expiration-cache>-0</expiration-cache>
      <supports>
      <mime-type>text/html</mime-type>
      <portlet-mode>VIEW</portlet-mode>
      <portlet-mode>EDIT</portlet-mode>
      </supports>
      <portlet-info>
      <title>Chart portlet</title>
      </portlet-info>
      <portlet-preferences>
      <preference>
      <name>chartXml</name>
      <value>/charts/chart1.xml</value>
      </preference>
      </portlet-preferences>
      </portlet>
      

       

       

      /chart_config.xhtml:

       

       

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

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <f:view xmlns:f="http://java.sun.com/jsf/core"

           xmlns:h="http://java.sun.com/jsf/html">

       

           <p>Simple message</p>

       

      </f:view>

       

       

      As you can see, there is nothing special in the page. It should just display a simple message.

       

      Exception:

       

       

      java.lang.NullPointerException

           at java.lang.String.<init>(String.java:515)

           at org.exoplatform.portal.webui.application.UIPortletForm.getEditModeContent(UIPortletForm.java:221)

           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

           at java.lang.reflect.Method.invoke(Method.java:597)

           at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)

       

       

      I traced it in the sourcecode to:

       

               String content;
               if (portletResponse instanceof FragmentResponse)
               {
                  FragmentResponse fragmentResponse = (FragmentResponse)portletResponse;
                  content = new String(fragmentResponse.getBytes(), "UTF-8");
               }
      

       

      The result of getBytes() seems to be null.

       

      What am I doing wrong?

        • 1. Re: Portlet Edit mode throws NullPointer (GateIn 3.1)
          g.nuijen Newbie

          I have just tested with the jsfhouser gatein example and it gives the exact same error + stacktrace.

           

          So I think I am not doing anything wrong. I will retest with gatein 3.0 FINAL, maybe it is a problem with 3.1.

           

          update:

          It works in 3.0, but not in 3.1.

           

           

          Ok, I figured it out. The problem was introduced with the bug fix of https://jira.jboss.org/browse/GTNPORTAL-1228.

           

          The root cause was the lack of Charset while processing FragmentResponse in getEditModeContent method ( in UIPortletForm class)

           

              
                  String content;
                   if (portletResponse instanceof FragmentResponse)
                   {
                      FragmentResponse fragmentResponse = (FragmentResponse)portletResponse;
                      content = fragmentResponse.getContent();
                   }

           

          A slight change was enough to fix the display error

           


                   String content;
                   if (portletResponse instanceof FragmentResponse)
                   {
                      FragmentResponse fragmentResponse = (FragmentResponse)portletResponse;
                      content = new String(fragmentResponse.getBytes(), Charset.forName("UTF-8"));
                   }

           

          The problem is that FragmentResponse has either chars or bytes:

           

             public int getType()
             {
                if (bytes == null)
                {
                   if (chars == null)
                   {
                      return TYPE_EMPTY;
                   }
                   else
                   {
                      return TYPE_CHARS;
                   }
                }
                else
                {
                   return TYPE_BYTES;
                }
             }
             /**
              * Return the content as a string.
              *
              * @return the content
              */
             public String getContent()
             {
                switch (getType())
                {
                   case TYPE_CHARS:
                      return getChars();
                   case TYPE_BYTES:
                      return new String(bytes);
                   case TYPE_EMPTY:
                      return "";
                   default:
                      throw new AssertionError();
                }
             }

           

          Update:

           

          I created a patch and that works. I will try to submit a patch.

           

                      FragmentResponse fragmentResponse = (FragmentResponse)portletResponse;

                      if (fragmentResponse.getType() == FragmentResponse.TYPE_BYTES) {

                           content = new String(fragmentResponse.getBytes(), "UTF-8");

                      } else {

                          content = fragmentResponse.getContent();

                      }

          • 3. Re: Portlet Edit mode throws NullPointer (GateIn 3.1)
            Trong Tran Master

            Yes, this is definitely a bug in 3.1

             

            Thanks for your perfect investigation and the patch, Gerbert

            • 4. Re: Portlet Edit mode throws NullPointer (GateIn 3.1)
              Minh Hoang TO Novice

              It is a bug introduced by my fix for GTNPORTAL-1288. Thanks for the patch, it seems to be the proper fix

              • 5. Re: Portlet Edit mode throws NullPointer (GateIn 3.1)
                Minh Hoang TO Novice

                  The types of FragmentResponse returned on invoking a portlet depends on what portlet developer does to generate  response: Writes characters to PortletResponse.getWriter() , writes bytes to PortletResponse.getPortletOutputStream() or do nothing.