PDA

View Full Version : Adding Portlets to existing Spring WebMVC


redfive
Apr 3rd, 2008, 12:51 PM
Hello,

Let me first state that this is my first go at portlets, so I apologize in advance for my ignorance.

I have an existing Spring 2.5.1 WebMVC webapp running in Jetspeed 2.1.3. My webapp behaves normally as if it were running under Tomcat 5.5.

I am trying to add a simple HelloWorld portlet to my existing webapp, and view it via a URL in my browser.

I added the portlet.xml, modifed web.xml. Everything compiles and the webapp deploys, I only have no way to view the portlet. In the end, I'd like my webapp to serve as a portal and portlets, as well as maintain the web-mvc structure it has now.. But right now I can't view my portlet at all.


My disconnect is - the only URL mapping I see is "/WEB-INF/servlet/view". Since this is not available to the browser - how do I access the portlet?

web.xml fragment:

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListe ner</listener-class>
</listener>

<!-- Define Spring portlet servlet -->
<servlet>
<servlet-name>ViewRendererServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.ViewRendererServle t</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>ViewRendererServlet</servlet-name>
<url-pattern>/WEB-INF/servlet/view</url-pattern>
</servlet-mapping>


portlet.xml fragment:

<portlet>
<description>HelloWorld Portlet using Spring MVC</description>
<portlet-name>HelloSpringPortletMVC</portlet-name>
<display-name>Hello World Spring Portlet MVC Framework Portlet</display-name>
<portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
</supports>

<supported-locale>en</supported-locale>
<portlet-info>
<title>Hello World Spring Portlet MVC Framework Portlet</title>
<short-title>HelloWorldSpringPortletMVC</short-title>
<keywords>spring portlet</keywords>
</portlet-info>
</portlet>


HelloWorldSpringPortletMVC-portlet.xml:

<bean id="viewController" class="mytest.ViewController"></bean>
<bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.PortletMod eHandlerMapping">
<property name="portletModeMap">
<map>
<entry key="view">
<ref bean="viewController" />
</entry>
</map>
</property>
</bean>


Thanks!

johnalewis
Apr 3rd, 2008, 01:38 PM
Take a look at this FAQ entry (http://opensource.atlassian.com/confluence/spring/x/ZAw) to get a better understanding of portlet deployment.

The quick answer is: If you are using Jetspeed as your portal, you have to configure Jetspeed to use your portlets. This will involve some minor changes in your web.xml so that the portal can issue requests into your webapp, and then you will need to register your portlets with the portal and configure them into the portal layout for your target users.

Hope that helps!

redfive
Apr 3rd, 2008, 03:19 PM
Thanks John.

I will take a look at the Jetspeed documentation to see the proper method for adding a portlet to their portal.

I was thinking a portlet container could contain multiple portal applications.