5 Replies Latest reply on Jan 4, 2011 4:21 AM by jssteux

    Dynamically adding / removing portlets programmatically

    shaipai

      I need to display or not display  a specific portlet based on certain criteria using a code. How do I do that ?.

        • 1. Re: Dynamically adding / removing portlets programmatically
          ranai

          I am also stuck with similar problem any solution to this would be great.

          • 2. Re: Dynamically adding / removing portlets programmatically
            jssteux

            The ony solution I have found is to redefine the PortalObjectContainer and to overload getChidren. It works but it needs to know how jboss portal manages Page and Windows

            • 3. Re: Dynamically adding / removing portlets programmatically
              jssteux

              I have a simpler solution ; In an older projet (jbp 2.6), we also had developped a Specific Interceptor (extends ControllerInterceptor) to add a window like this :

               

               

                      RenderPageCommand rCmd = (RenderPageCommand) cmd;
                      PortalObjectPath pagePath = rCmd.getTargetId().getPath();

               

                      // Set path for dynamic window
                      String[] names = new String[pagePath.getLength() + 1];
                      for (int i = 0; i < pagePath.getLength(); i++) {
                          names[i] = pagePath.getName(i);
                      }

               

                      names[pagePath.getLength()] = "dynamic_" + windowName;
                      PortalObjectId id = new PortalObjectId(rCmd.getTargetId().getNamespace(), new PortalObjectPath(names));
                      PortalObject po = getPortalObjectContainer().getObject(id);
                      rCmd.getWindows().add(po);

               

               

               

              I hope it can help you.

              • 4. Re: Dynamically adding / removing portlets programmatically
                shaipai

                Thanks for responding. But I am new to portlets. The code snippet you provided , is bit hard to digest. Is there any reference which can explain what are different objects such as PortalObjectPath,RenderPageCommand that you have used ?.

                • 5. Re: Dynamically adding / removing portlets programmatically
                  jssteux

                  I'm afraid that if you want custom displays inside the portal, you will have to consider the portal as a framework. JBoss Portal is based on a service architecture (MBeans which are defined in jboss-service.xml), so each service can be overloaded by your own component. It is also based on the Command Pattern which allows you to add Interceptors to default command chains (by defining services). As you see, JBP is more a framework to build custom portals than a ready-to-run solution. The advantage is that you can do whatever you want (such as dynamic windows, multithreading between portlets, specific securities rules ...) The drawback is that you have to understand how it works.

                   

                  RenderPageCommand, RenderWindowCommand are the internal commands to display  pages and portlets

                  Page and Window are interfaces for browsing the content of the portal

                   

                  Another way to do what you want without understanding all the structure would also be fo fork JBP (for example, by modifying RenderPageCommand to add specific windows in your case).

                   

                  All that depends on the time you can spend on you project.