HelloWorldController:
package helloWorld;
import java.util.HashMap;
import java.util.Map;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.springframework.web.portlet.ModelAndView;
import org.springframework.web.portlet.mvc.Controller;
/**
* Spring controller which implements the Controller interface.
*
* @author asarin
*
*/
public class HelloWorldController implements Controller {
/**
* action method.
*/
public void handleActionRequest(ActionRequest request,
ActionResponse response) throws Exception {
//-- do nothing the Hello World portlet doesn't receive
//-- action requests.
}
/**
* render method.
*/
public ModelAndView handleRenderRequest(RenderRequest request,
RenderResponse response) throws Exception {
Map
model.put("helloWorldMessage", "Hello World HelloWorldController");
return new ModelAndView("helloWorld", model);
}
}
applicationContext.xml:
xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
beans>
default-object.xml:
xml version="1.0" encoding="UTF-8"?>
DOCTYPE deployments PUBLIC
"-//JBoss Portal//DTD Portal Object 2.6//EN"
"http://www.jboss.org/portal/dtd/portal-object_2_6.dtd">
<deployments>
<deployment>
<parent-ref>default.defaultparent-ref>
<if-exists>overwriteif-exists>
<window>
<window-name>HelloWorldControllerWindowwindow-name>
<instance-ref>HelloWorldControllerInstanceinstance-ref>
<region>centerregion>
<height>1height>
<initial-window-state>maximizedinitial-window-state>
window>
deployment>
deployments>
HelloWorldController-portlet.xml:
xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="HelloWorldController"
class="helloWorld.HelloWorldController"/>
<bean id="portletModeHandlerMapping"
class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
<property name="portletModeMap">
<map>
<entry key="view">
<ref bean="HelloWorldController" />
entry>
map>
property>
bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.InternalResourceView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
bean>
beans>
helloWorld.jsp:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html" isELIgnored="false" %>
<c:out value="${helloWorldMessage}"/>
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"
version="2.0">
<portlet>
<portlet-name>HelloWorldControllerportlet-name>
<portlet-class>org.springframework.web.portlet.DispatcherPortletportlet-class>
<supports>
<mime-type>text/htmlmime-type>
<portlet-mode>viewportlet-mode>
supports>
<portlet-info>
<title>HelloWorldControllertitle>
portlet-info>
portlet>
portlet-app>
portlet-instances.xml:
xml version="1.0" encoding="UTF-8"?>
DOCTYPE deployments PUBLIC
"-//JBoss Portal//DTD Portlet Instances 2.6//EN"
"http://www.jboss.org/portal/dtd/portlet-instances_2_6.dtd">
<deployments>
<deployment>
<instance>
<instance-id>HelloWorldControllerInstanceinstance-id>
<portlet-ref>HelloWorldControllerportlet-ref>
instance>
deployment>
deployments>
Web.xml:
xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>HelloWorldSpringPortletdisplay-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
listener>
<servlet>
<servlet-name>view-servletservlet-name>
<servlet-class>org.springframework.web.servlet.ViewRendererServletservlet-class>
<load-on-startup>1load-on-startup>
servlet>
<servlet-mapping>
<servlet-name>view-servletservlet-name>
<url-pattern>/WEB-INF/servlet/viewurl-pattern>
servlet-mapping>
No comments:
Post a Comment