4 Replies Latest reply on Jan 23, 2009 1:58 AM by anbazhagan prasanna

    How to create a new Portlet Instance using API

    Yaniv Newbie

      Hi

      Since this part is not well documented( or at least I was not able to find any documentation besides the Javadocs) I have difficulty finding how to create a new portlet instance using the exisiting APIs.

      Can anyone advise.

      Thanks,


      Yaniv.

        • 1. Re: How to create a new Portlet Instance using API
          Prabhat Jha Master

          The best place would be look into jboss portal source code. Check out the code from SVN and look into core-admin.

          • 2. Re: How to create a new Portlet Instance using API
            Yaniv Newbie

            Thanks for the answer

            I did as you suggested and created the following code in order to create a new instance:

            PersistentInstanceDefinition instanceToCopy=(PersistentInstanceDefinition) instanceContainerContext.getInstanceDefinition(intanceName);
            
            Date current = new Date();
            String newInstanceId = instanceToCopy.getId() + "_" + current.getTime();
            
            PortletContext portletContext = PortletContext.createPortletContext("PortletName");
            
            Portlet portletDefinition = portletInvoker.getPortlet(portletContext);
            PersistentInstanceDefinition newInstance=(PersistentInstanceDefinition)
            instanceContainer.createDefinition(newInstanceId,portletDefinition.getContext().getId());
            
            Set constraints = Collections.singleton(new RoleSecurityBinding("view", SecurityConstants.UNCHECKED_ROLE_NAME));
            securityService.setSecurityBindings(newInstanceId,constraints);
            
            PropertyChange[] properties = duplicateInstanceProperties(instanceToCopy.getProperties());
            newInstance.setProperties(properties);
            
            




            As you can see from the code, I'm actually trying to create a new instance that will be identical to an existing instance(based on the same portlet and have the same property values). Unfortunately this code works without giving an exception or returning any null values. but the instance created is never shown in the instance list of the portal administrative panel and therefore cannot be used.

            Basically I followed the code in the CreateInstanceAction class file.

            Any suggestions?


            Many Thanks,


            Yaniv













            • 3. Re: How to create a new Portlet Instance using API
              anbazhagan prasanna Newbie

              hi
              you should create a Window and assign this newly created portlet instance into that.

              • 4. Re: How to create a new Portlet Instance using API
                anbazhagan prasanna Newbie

                Window w = currentPage.createWindow(portalWindowName,ContentType.PORTLET,instanceId);
                log.info(" window["+w+"] is assigned with portlet ["+instanceId+"] successfully");

                w.setDeclaredProperty(ThemeConstants.PORTAL_PROP_REGION,region);
                w.setDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER, "" + Integer.MAX_VALUE);