This article introduces spring's Portlet MVC framework through a simple example.
Spring Portlet MVC is exactly the same as its web MVC, but dispatcherservlet, which is at the core of Web MVC, is replaced with dispatcherportlet in Portlet MVC. For example, it describes how the Portlet request is processed. for spring web MVC, see http://blog.csdn.net/kkdelta/article/details/7274708
The image is from portlets inaction.
The dispatcherportlet is configured in the Portlet. in the XML file, it inherits the genericportlet In the Portlet standard, so it is essentially a Portlet that can send the Portlet Request dispatch to other MVC components in the Spring framework. the configuration is as follows:
<portlet><portlet-name>helloWorld</portlet-name><portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class><supports><mime-type>text/html</mime-type><portlet-mode>view</portlet-mode></supports><resource-bundle>content.Language-ext</resource-bundle><portlet-info><title>Hello World</title></portlet-info></portlet>
Here, the render request processing is used as an example. When the dispatcherportlet receives the request, it finds the corresponding controler Based on the configuration of handermapping to process the request. after the controler completes processing, a modelandview is returned.
MVC is similar. I will not introduce it here.
<?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/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"><bean id="helloWorldController"class="chapter07.code.listing.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.JstlView" /><property name="prefix" value="/WEB-INF/jsp/" /><property name="suffix" value=".jsp" /></bean></beans>public class HelloWorldController implements Controller { public void handleActionRequest(ActionRequest request, ActionResponse response) throws Exception { //-- do nothing the Hello World portlet doesn't receive //-- action requests. } public ModelAndView handleRenderRequest(RenderRequest request, RenderResponse response) throws Exception { Map<String, Object> model = new HashMap<String, Object>(); model.put("helloWorldMessage", "Hello World"); return new ModelAndView("helloWorld", model); }}
The example in this article references portlets in action. The complete code can be downloaded from http://download.csdn.net/detail/kkdelta/4125924.
This example can run on the liferay Portal Server, the introduction of the Portlet and liferay can refer to the http://blog.csdn.net/kkdelta/article/category/1082877
Spring's Controller provides a method to process render request and action request. For requests that process event and resource types, eventawarecontroller and resourceawarecontroller can be implemented respectively.
At the same time, through the annotation method, you can also process the request in the mapping response to a specific method. Spring provides @ controller, @ rendermapping, @ actionmapping, and so on.