7 Replies Latest reply on Oct 6, 2007 5:02 AM by arunprasathav

    2 or more portlets in 1 page

    silicio

      Hello to all. I'm using JBoss 2.2 with Application Server.
      I've to make a page with two or more portlet (one per window).

      Is this syntax correct (it seems doesn't work properly)?

      file: portlet.xml

      <portlet-app>
       <portlet>
       ...
       <portlet-name>SimplePortlet</portlet-name>
       ...
       </portlet>
       <portlet>
       ...
       <portlet-name>TestHelloWorld</portlet-name>
       ...
       </portlet>
      </portlet-app>


      file: portlet-instances.xml (is it required?)
      <?xml version="1.0" standalone="yes"?>
      <instances>
       <instance>
       <instance-id>SimplePortletInstance</instance-id>
       <portlet-ref>SimplePortlet</portlet-ref>
       </instance>
       <instance>
       <instance-id>TestHelloWorldInstance</instance-id>
       <portlet-ref>TestHelloWorld</portlet-ref>
       </instance>
      </instances>


      file: simpleportlet-object.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <deployments>
       <deployment>
       <if-exists>overwrite</if-exists>
       <parent-ref>default</parent-ref>
       <page>
       <page-name>SimplePortlet</page-name>
       <properties/>
       <window>
       <window-name>SimplePortletWindow</window-name>
       <instance-ref>SimplePortletInstance</instance-ref>
       <region>center</region>
       <height>0</height>
       </window>
       </page>
       </deployment>
       <deployment>
       <if-exists>overwrite</if-exists>
       <instance>
       <instance-name>SimplePortletInstance</instance-name>
       <component-ref>simpleportlet.SimplePortlet</component-ref>
       </instance>
       </deployment>
      </deployments>


      file: class1-object.xml (class1 is the class name of TestHelloWorld portlet)
      <?xml version="1.0" encoding="UTF-8"?>
      <deployments>
       <deployment>
       <if-exists>overwrite</if-exists>
       <parent-ref>default</parent-ref>
       <page>
       <page-name>SimplePortlet</page-name>
       <properties/>
       <window>
       <window-name>TestHelloWorldWindow</window-name>
       <instance-ref>TestHelloWorldInstance</instance-ref>
       <region>left</region>
       <height>0</height>
       </window>
       </page>
       </deployment>
       <deployment>
       <if-exists>overwrite</if-exists>
       <instance>
       <instance-name>TestHelloWorldInstance</instance-name>
       <component-ref>simpleportlet.TestHelloWorld</component-ref>
       </instance>
       </deployment>
      </deployments>


        • 1. Re: 2 or more portlets in 1 page
          silicio

          I made some step ahead. After many attempts, in JBoss management GUI, I see the page SimplePortlet, the two portlets SimplePortlet and TestHelloWorldPortlet, and two porltet instances SimplePortletInstance and TestHelloWorldPortletInstance. But I always see only one portlet in the page. The problem is that I see only one window named SimplePortletWindow

          When I try to deploy my application I get a DeploymentException: "Too may children for element deployment" for the file simpleportlet-object.xml.

          Last version of file simpleportlet-object.xml:

          <?xml version="1.0" encoding="UTF-8"?>
          <deployments>
           <deployment>
           <if-exists>overwrite</if-exists>
           <parent-ref>default</parent-ref>
           <page>
           <page-name>SimplePortlet</page-name>
           <properties/>
           <window>
           <window-name>SimplePortletWindow</window-name>
           <instance-ref>SimplePortletInstance</instance-ref>
           <region>left</region>
           <height>0</height>
           </window>
           <window>
           <window-name>TestHelloWorldWindow</window-name>
           <instance-ref>TestHelloWorldInstance</instance-ref>
           <region>right</region>
           <height>0</height>
           </window>
           </page>
           </deployment>
           <deployment>
           <if-exists>overwrite</if-exists>
           <instance>
           <instance-name>TestHelloWorldInstance</instance-name>
           <component-ref>simpleportlet.TestHelloWorldPortlet</component-ref>
           </instance>
           <instance>
           <instance-name>SimplePortletInstance</instance-name>
           <component-ref>simpleportlet.SimplePortlet</component-ref>
           </instance>
           </deployment>
          </deployments>
          


          Where is the problem?

          The file class1-object.xml was deleted becase it was useless.

          • 2. Re: 2 or more portlets in 1 page
            silicio

            Ok, I've resolved. Now work correctly.

            Last version of simpleportlet-object.xml file:

            <?xml version="1.0" encoding="UTF-8"?>
            <deployments>
             <deployment>
             <if-exists>overwrite</if-exists>
             <parent-ref>default</parent-ref>
             <page>
             <page-name>SimplePortlet</page-name>
             <properties/>
             <window>
             <window-name>SimplePortletWindow</window-name>
             <instance-ref>SimplePortletInstance</instance-ref>
             <region>left</region>
             <height>0</height>
             </window>
             <window>
             <window-name>TestHelloWorldPortletWindow</window-name>
             <instance-ref>TestHelloWorldPortletInstance</instance-ref>
             <region>center</region>
             <height>0</height>
             </window>
             </page>
             </deployment>
            
             <deployment>
             <if-exists>overwrite</if-exists>
             <instance>
             <instance-name>SimplePortletInstance</instance-name>
             <component-ref>simpleportlet.SimplePortlet</component-ref>
             </instance>
             </deployment>
            
             <deployment>
             <if-exists>overwrite</if-exists>
             <instance>
             <instance-name>TestHelloWorldPortletInstance</instance-name>
             <component-ref>simpleportlet.TestHelloWorldPortlet</component-ref>
             </instance>
             </deployment>
            </deployments>


            I hope this thread can result helpful to someone...

            Bye

            • 3. Re: 2 or more portlets in 1 page
              silicio

              If interested anyone can download and deploy this example.

              http://www.overmodding.org/files/SimplePortlet.war

              MD5: 823467D14B2E45E1D2EAC21ECE031EF5

              • 4. Re: 2 or more portlets in 1 page
                aleee

                Thank you!
                It was very usefull for me!

                Bye

                • 5. Re: 2 or more portlets in 1 page
                  silicio

                  I copy and past sources here so I eventually can delete file on my site.
                  Example valid for JBoss 2.2.x
                  For put 2 portlets in 1 page we need:
                  - portlet.xml
                  - simpleportlet-object.xml (*-object.xml where * is the name of your portal application)

                  \ <-- Our Portal Root folder
                  |
                  |--\WEB-INF
                   |
                   |-- jboss-web.xml
                   |-- jboss-app.xml
                   |-- web.xml
                   |-- portal.xml
                   |-- simpleportlet-object.xml
                   |
                   |--\lib <-- this is the folder where to put libreries
                   |--\classes <-- this is the folder where put copiled java classes
                   |
                   |--\com <-- this is the folder for the package
                   |
                   |--\portalbook <-- this is the folder for the package
                   |
                   |--\crawler <-- this is the folder for the package
                   |
                   |--Class1.class
                   |--SimplePortlet.class
                  


                  jboss-web.xml:
                  <?xml version="1.0"?>
                  <jboss-web>
                  </jboss-web>
                  


                  jboss-app.xml:
                  <jboss-app>
                   <app-name>simpleportlet</app-name>
                  </jboss-app
                  


                  portlet.xml:
                  <portlet-app
                  xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
                  version="1.0"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
                  http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
                   <portlet>
                   <description xml:lang="en">PortletBook Simple Portlet</description>
                   <description xml:lang="it">LibroPortlet Portlet Semplice</description>
                   <portlet-name>SimplePortlet</portlet-name>
                   <portlet-class>com.portalbook.crawler.SimplePortlet</portlet-class>
                   <expiration-cache>-1</expiration-cache>
                   <supports>
                   <mime-type>text/html</mime-type>
                   <portlet-mode>VIEW</portlet-mode>
                   <portlet-mode>EDIT</portlet-mode>
                   <portlet-mode>HELP</portlet-mode>
                   </supports>
                   <supported-locale>en</supported-locale>
                   <portlet-info>
                   <title>Simple Portlet</title>
                   <short-title>Simple</short-title>
                   <keywords>Simple, Example</keywords>
                   </portlet-info>
                   </portlet>
                  
                   <portlet>
                   <description xml:lang="en">Only Hello World</description>
                   <description xml:lang="it">Solo Hello World</description>
                   <portlet-name>TestHelloWorldPortlet</portlet-name>
                   <portlet-class>com.portalbook.crawler.Class1</portlet-class>
                   <expiration-cache>-1</expiration-cache>
                   <supports>
                   <mime-type>text/html</mime-type>
                   <portlet-mode>VIEW</portlet-mode>
                   </supports>
                   <supported-locale>en</supported-locale>
                   <portlet-info>
                   <title>Test Hello World</title>
                   <short-title>THW</short-title>
                   <keywords>test, hello, world</keywords>
                   </portlet-info>
                   </portlet>
                  </portlet-app>
                  


                  simpleportlet-object.xml:
                  <?xml version="1.0" encoding="UTF-8"?>
                  <deployments>
                   <deployment>
                   <if-exists>overwrite</if-exists>
                   <parent-ref>default</parent-ref>
                   <page>
                   <page-name>SimplePortlet</page-name>
                   <properties/>
                   <window>
                   <window-name>SimplePortletWindow</window-name>
                   <instance-ref>SimplePortletInstance</instance-ref>
                   <region>left</region>
                   <height>0</height>
                   </window>
                   <window>
                   <window-name>TestHelloWorldPortletWindow</window-name>
                   <instance-ref>TestHelloWorldPortletInstance</instance-ref>
                   <region>center</region>
                   <height>0</height>
                   </window>
                   </page>
                   </deployment>
                  
                   <deployment>
                   <if-exists>overwrite</if-exists>
                   <instance>
                   <instance-name>SimplePortletInstance</instance-name>
                   <component-ref>simpleportlet.SimplePortlet</component-ref>
                   </instance>
                   </deployment>
                  
                   <deployment>
                   <if-exists>overwrite</if-exists>
                   <instance>
                   <instance-name>TestHelloWorldPortletInstance</instance-name>
                   <component-ref>simpleportlet.TestHelloWorldPortlet</component-ref>
                   </instance>
                   </deployment>
                  </deployments>
                  


                  web.xml:
                  <?xml version="1.0" encoding="UTF-8"?>
                  <web-app>
                  
                   <welcome-file-list>
                   <welcome-file>index.jsp</welcome-file>
                   </welcome-file-list>
                  
                  </web-app>
                  


                  Class1.java source:
                  package com.portalbook.crawler;
                  
                  import java.io.IOException;
                  
                  import javax.portlet.GenericPortlet;
                  import javax.portlet.PortletException;
                  import javax.portlet.RenderRequest;
                  import javax.portlet.RenderResponse;
                  
                  public class Class1 extends GenericPortlet {
                  
                   public static void Class1(){
                   }
                  
                   protected void doView(RenderRequest request, RenderResponse response) throws
                   PortletException, IOException {
                   response.setContentType("text/html");
                   response.getWriter().println("Hello Portlet");
                   }
                  }
                  


                  SimplePortlet.java source:
                  package com.portalbook.crawler;
                  
                  import java.io.*;
                  import javax.portlet.*;
                  
                  public class SimplePortlet implements Portlet {
                  
                   public SimplePortlet() {
                   }
                  
                   public void destroy() {
                   portletCounter--;
                   }
                  
                   public void init(PortletConfig config) throws PortletException {
                   portletCounter++;
                   }
                  
                   public void processAction(ActionRequest request, ActionResponse response)
                   throws PortletException, IOException{
                   actionCounter++;
                   }
                  
                   public void render(RenderRequest request,RenderResponse response)
                   throws PortletException, IOException{
                   renderCounter++;
                   response.setTitle("Simple Portlet");
                   response.setContentType("text/html");
                   PrintWriter out = response.getWriter();
                   out.write("The server has instantiated " +
                   portletCounter +" copies of the portlet<br>");
                   out.write("This portlet has been rendered " +
                   renderCounter +" times (including this one)<br>");
                   out.write("This portlet has received " +
                   actionCounter +" action requests<br>");
                   PortletURL action = response.createActionURL();
                   out.write("Click <a href=\"");
                   out.write(action.toString());
                   out.write("\">here</a> to trigger an action.<br>");
                   }
                  
                   private static int portletCounter = 0;
                   private int renderCounter = 0;
                   private int actionCounter = 0;
                  }
                  


                  • 6. Re: 2 or more portlets in 1 page
                    chandanmohanty

                    The output of this portlet "SimplePortlet" is being shown in the default page. How can we create our own Portal page.

                    Chandan Kumar Mohanty

                    • 7. Re: 2 or more portlets in 1 page
                      arunprasathav

                      hi,
                      I understood the basic struts flow.
                      Now i want to do Struts portlet application.
                      can anyone tell me how to do and tell me which online document.

                      could u please send me the .war of sample struts portlet app to aruncollections@gmail.com.
                      So that i can go through it and understand.