3 Replies Latest reply on Mar 1, 2008 4:21 AM by ironman77

    NullPointer: Setting portlet instance preferences via Instan

    ironman77

      Hi using this development setup:


      * Version: jboss-portal-2.6.1.GA
      * Download Version
      * JBoss AS Version: 4.2.1.GA (build: SVNTag=JBoss_4_2_1_GA date=200707131605)]
      * Database: Mysql 5.0.51a-community-nt
      * JDBC Connector and Version: mysql-connector-java-5.0.5-bin.jar
      * OS Platform: Windows XP 32-Bit


      I have injected the InstanceContainer and set transaction support via jboss-portlet.xml:

       <service>
       <service-name>InstanceContainer</service-name>
       <service-class>org.jboss.portal.core.model.instance.InstanceContainer</service-class>
       <service-ref>:container=Instance</service-ref>
       </service>


      and

      <trans-attribute>Required</trans-attribute>


      Reading from the portlet instnaces does work, writing to the portlet preferences creates a nullpointer, using this example code:

      //Get the instance container
      InstanceContainer instanceContainer = (InstanceContainer) this.getPortletRequest().getPortletSession().getPortletContext().getAttribute("InstanceContainer");
      InstanceDefinition id = instanceContainer.getDefinition("startPortletInstance");
      
      // This does work!
      PropertyMap pmap = id.getProperties();
      String uuid = ((StringValue) pmap.get("uuid")).toString();
      
      List tmp = new ArrayList();
      if (pmap.containsKey("uuid")) {
       PropertyChange change = PropertyChange.newUpdate("uuid", new StringValue(documentId));
       tmp.add(change);
      }
      PropertyChange[] changes = (PropertyChange[]) tmp.toArray(new PropertyChange[tmp.size()]);
      //This doesn't work
      id.setProperties(changes);
      


      I have debugged the setProperties() method for my portlet und the admin portlet and found the problematic section:


      org.jboss.portal.core.impl.portlet.state.PersistentPortletStatePersistenceManager


      The following code line leads to the nullpointer:

      context.entries.clear();


      The problem seems to be, that the loaded (hibernate?) PersistentPortletState object is not set up correctly, most properties are empty. I have compared this to the admin-core portlet - there is the object loaded correctly.

      Some questions:

      1. Am i gettin the InstanceCotainer correctly:

      InstanceContainer instanceContainer = (InstanceContainer) this.getPortletRequest().getPortletSession().getPortletContext().getAttribute("InstanceContainer");
      


        • 1. Re: NullPointer: Setting portlet instance preferences via In
          ironman77

          2. Is the setting of portlet instance prefs via the InstanceContainer bound to the admin user?

          3. Am i missing some service?
          4. What am i doing wrong ;-) Reading seems to work ....

          Thanks in advance.

          • 2. Re: NullPointer: Setting portlet instance preferences via In
            claprun

            What are you trying to do exactly, i.e. why do you need to access the InstanceContainer? Any reason you are using 2.6.1 and not 2.6.4?

            • 3. Re: NullPointer: Setting portlet instance preferences via In
              ironman77

              Hi chris,

              we set some portlet instance parameters via the portlet-instance.xml. These parameters are visible to all user - we want a user with a defined role ("site admin") to be able to modify these settings. Setting the values via the PortletPreferences is not an option as these values are stored in connetion with the logged in user and not for all users. That is why we want to modify the portlet instance parameters via the InstanceContainer.

              There is a reason for using this version: we are devloping since mid 2007 and want to keep our developing platform and libary base stable. We have also noticed that, there a some bigger changes between the different portal versions, like a change of the underlaying jboss application server version from 2.6.0 to 2.6.1. So maybe we grade up after our portal projetk is final, but until now we want to keep the version.