4 Replies Latest reply on Mar 5, 2008 9:06 AM by Viet

    Missing windowId for portlets events test

    rpa_rio Novice

      Hi!

      I'm trying to develop some portlets to test events on portletcontainer 2.0, when I try to perform an action on my sender portlet I get exception below:

      java.lang.NullPointerException
      at org.jboss.portal.portlet.controller.PortletRequestHandler.invoke(PortletRequestHandler.java:219)
      at org.jboss.portal.portlet.controller.PortletRequestHandler.invoke(PortletRequestHandler.java:61)

        • 1. Re: Missing windowId for portlets events test
          Viet Master

          it looks like a bug. can you describe the interactions you do ?

          the controller package has been improved since the beta1 and is more robust, you could try SVN or wait for the next release.

          • 2. Re: Missing windowId for portlets events test
            rpa_rio Novice

            I wrote two pages publisher-view.jsp and listener-view.jsp, in publisher-view.jsp I used portlet tags to generate the actionURL, exactly like we have below:

            <%@ page contentType="text/html"%>
            <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
            <portlet:defineObjects />
            <portlet:actionURL var="submitUrl" portletMode="view" />
            <div>
             <br />
             <br />
             <center>
             <form action="<%=submitUrl%>" method="post">
             <label for="input">Type your text:</label>
             <input type="text" id="input" name="input" value="" />
             <input type="submit" value="Send" />
             </form>
             </center>
            </div>
            


            When the submit button is clicked the processAction on PublisherPortlet must be invoked and then the event is set:

            package br.eti.faces.portlet.publisher;
            
            import java.io.IOException;
            
            import javax.portlet.ActionRequest;
            import javax.portlet.ActionResponse;
            import javax.portlet.GenericPortlet;
            import javax.portlet.PortletContext;
            import javax.portlet.PortletException;
            import javax.portlet.PortletRequestDispatcher;
            import javax.portlet.RenderRequest;
            import javax.portlet.RenderResponse;
            
            import br.eti.faces.portlet.events.Literal;
            
            public class PublisherPortlet extends GenericPortlet {
            
             @Override
             protected void doView(RenderRequest renderRequest,
             RenderResponse renderResponse) throws PortletException, IOException {
            
             renderResponse.setContentType("text/html");
            
             PortletContext ctx = getPortletContext();
             PortletRequestDispatcher dispatcher = ctx
             .getRequestDispatcher("/publisher-view.jsp");
            
             dispatcher.include(renderRequest, renderResponse);
             }
            
             @Override
             public void processAction(ActionRequest actionRequest,
             ActionResponse actionResponse) throws PortletException, IOException {
             String value = actionRequest.getParameter("input");
             actionResponse.setEvent(Literal.QNAME, new Literal(value));
             }
            
            }
            


            I defined this class as my event class:

            package br.eti.faces.portlet.events;
            
            import java.io.Serializable;
            
            import javax.xml.bind.annotation.XmlRootElement;
            import javax.xml.namespace.QName;
            
            @XmlRootElement
            public class Literal implements Serializable {
            
             public static final QName QNAME = new QName("urn:jboss:portal:samples:event" , "Literal");
            
             private String data;
            
             public Literal(String data) {
             this.data = data;
             }
            
             public String getData() {
             return data;
             }
            
             public void setData(String data) {
             this.data = data;
             }
            }
            


            Finally, I registered both (porlet and event) on portlet.xml:

            <?xml version="1.0" encoding="UTF-8"?>
            <portlet-app
             xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
             id="portlet-event" version="2.0">
            
             <event-definition>
             <qname xmlns:jbp="urn:jboss:portal:samples:event">jbp:Literal</qname>
             <value-type>br.eti.faces.portlet.events.Literal</value-type>
             </event-definition>
            
             <portlet id="publisher">
             <init-param>
             <name>default-view</name>
             <value>/publisher-view.jsp</value>
             </init-param>
             <init-param>
             <name>ViewPage</name>
             <value>/publisher-view.jsp</value>
             </init-param>
             <description>Event Publisher JSP Portlet</description>
             <portlet-name>publisher</portlet-name>
             <display-name>Event Publisher JSP Portlet</display-name>
             <portlet-class>
             br.eti.faces.portlet.publisher.PublisherPortlet
             </portlet-class>
             <supports>
             <mime-type>text/html</mime-type>
             <portlet-mode>VIEW</portlet-mode>
             </supports>
             <portlet-info>
             <title>Event Publisher JSP Portlet</title>
             <short-title>Event Publisher JSP Portlet</short-title>
             </portlet-info>
            
             <supported-publishing-event>
             <qname xmlns:jbp="urn:jboss:portal:samples:event">jbp:Literal</qname>
             </supported-publishing-event>
             </portlet>
            
             <portlet id="listener">
             <init-param>
             <name>default-view</name>
             <value>/listener-view.jsp</value>
             </init-param>
             <init-param>
             <name>ViewPage</name>
             <value>/listener-view.jsp</value>
             </init-param>
             <description>Event Listener JSP Portlet</description>
             <portlet-name>listener</portlet-name>
             <display-name>Event Listener JSP Portlet</display-name>
             <portlet-class>
             br.eti.faces.portlet.listener.ListenerPortlet
             </portlet-class>
             <supports>
             <mime-type>text/html</mime-type>
             <portlet-mode>VIEW</portlet-mode>
             </supports>
             <portlet-info>
             <title>Event Listener JSP Portlet</title>
             <short-title>Event Listener JSP Portlet</short-title>
             </portlet-info>
            
             <supported-processing-event>
             <qname xmlns:jbp="urn:jboss:portal:samples:event">jbp:Literal</qname>
             </supported-processing-event>
             </portlet>
            </portlet-app>
            


            • 3. Re: Missing windowId for portlets events test
              rpa_rio Novice

              I used the demo3.jsp code and made minimal changes, now everything works ok.

              • 4. Re: Missing windowId for portlets events test
                Viet Master

                 

                "rpa_rio" wrote:
                I used the demo3.jsp code and made minimal changes, now everything works ok.


                thanks