70
70
import org .springframework .validation .Errors ;
71
71
import org .springframework .web .bind .WebDataBinder ;
72
72
import org .springframework .web .bind .annotation .CookieValue ;
73
+ import org .springframework .web .bind .annotation .ExceptionHandler ;
73
74
import org .springframework .web .bind .annotation .InitBinder ;
74
75
import org .springframework .web .bind .annotation .ModelAttribute ;
75
76
import org .springframework .web .bind .annotation .RequestHeader ;
76
77
import org .springframework .web .bind .annotation .RequestMapping ;
77
78
import org .springframework .web .bind .annotation .RequestParam ;
79
+ import org .springframework .web .bind .annotation .SessionAttributes ;
80
+ import org .springframework .web .bind .support .SessionStatus ;
78
81
import org .springframework .web .bind .support .WebArgumentResolver ;
79
82
import org .springframework .web .bind .support .WebBindingInitializer ;
80
83
import org .springframework .web .context .WebApplicationContext ;
83
86
import org .springframework .web .context .support .GenericWebApplicationContext ;
84
87
import org .springframework .web .portlet .DispatcherPortlet ;
85
88
import org .springframework .web .portlet .ModelAndView ;
89
+ import org .springframework .web .portlet .bind .MissingPortletRequestParameterException ;
86
90
import org .springframework .web .portlet .bind .annotation .ActionMapping ;
87
91
import org .springframework .web .portlet .bind .annotation .EventMapping ;
88
92
import org .springframework .web .portlet .bind .annotation .RenderMapping ;
@@ -129,6 +133,11 @@ public void adaptedHandleMethods3() throws Exception {
129
133
doTestAdaptedHandleMethods (MyAdaptedController3 .class );
130
134
}
131
135
136
+ @ Test
137
+ public void adaptedHandleMethods4 () throws Exception {
138
+ doTestAdaptedHandleMethods (MyAdaptedController4 .class );
139
+ }
140
+
132
141
private void doTestAdaptedHandleMethods (final Class controllerClass ) throws Exception {
133
142
DispatcherPortlet portlet = new DispatcherPortlet () {
134
143
protected ApplicationContext createPortletApplicationContext (ApplicationContext parent ) throws BeansException {
@@ -145,12 +154,22 @@ protected ApplicationContext createPortletApplicationContext(ApplicationContext
145
154
portlet .processAction (actionRequest , actionResponse );
146
155
assertEquals ("value" , actionResponse .getRenderParameter ("test" ));
147
156
148
- MockRenderRequest request = new MockRenderRequest (PortletMode .EDIT );
157
+ MockRenderRequest request = new MockRenderRequest (PortletMode .VIEW );
158
+ request .setSession (actionRequest .getPortletSession ());
159
+ request .setParameters (actionResponse .getRenderParameterMap ());
160
+ request .addParameter ("name" , "name1" );
161
+ request .addParameter ("age" , "value2" );
162
+ MockRenderResponse response = new MockRenderResponse ();
163
+ portlet .render (request , response );
164
+ assertEquals ("test-name1-typeMismatch" , response .getContentAsString ());
165
+ assertNull (request .getPortletSession ().getAttribute ("testBean" ));
166
+
167
+ request = new MockRenderRequest (PortletMode .EDIT );
149
168
request .addParameter ("param1" , "value1" );
150
169
request .addParameter ("param2" , "2" );
151
170
request .addProperty ("header1" , "10" );
152
171
request .setCookies (new Cookie ("cookie1" , "3" ));
153
- MockRenderResponse response = new MockRenderResponse ();
172
+ response = new MockRenderResponse ();
154
173
portlet .render (request , response );
155
174
assertEquals ("test-value1-2-10-3" , response .getContentAsString ());
156
175
@@ -160,13 +179,6 @@ protected ApplicationContext createPortletApplicationContext(ApplicationContext
160
179
response = new MockRenderResponse ();
161
180
portlet .render (request , response );
162
181
assertEquals ("test-name1-2" , response .getContentAsString ());
163
-
164
- request = new MockRenderRequest (PortletMode .VIEW );
165
- request .addParameter ("name" , "name1" );
166
- request .addParameter ("age" , "value2" );
167
- response = new MockRenderResponse ();
168
- portlet .render (request , response );
169
- assertEquals ("test-name1-typeMismatch" , response .getContentAsString ());
170
182
}
171
183
172
184
@ Test
@@ -572,6 +584,7 @@ protected ApplicationContext createPortletApplicationContext(ApplicationContext
572
584
573
585
request = new MockRenderRequest (PortletMode .VIEW , WindowState .MAXIMIZED );
574
586
request .setParameters (actionResponse .getRenderParameterMap ());
587
+ request .setSession (actionRequest .getPortletSession ());
575
588
response = new MockRenderResponse ();
576
589
portlet .render (request , response );
577
590
assertEquals ("myLargeView-value" , response .getContentAsString ());
@@ -583,6 +596,7 @@ protected ApplicationContext createPortletApplicationContext(ApplicationContext
583
596
584
597
request = new MockRenderRequest (PortletMode .VIEW , WindowState .MAXIMIZED );
585
598
request .setParameters (actionResponse .getRenderParameterMap ());
599
+ request .setSession (actionRequest .getPortletSession ());
586
600
response = new MockRenderResponse ();
587
601
portlet .render (request , response );
588
602
assertEquals ("myLargeView-details" , response .getContentAsString ());
@@ -731,6 +745,43 @@ public void myHandle(TestBean tb, Errors errors, RenderResponse response) throws
731
745
}
732
746
733
747
748
+ @ Controller
749
+ @ SessionAttributes ("testBean" )
750
+ private static class MyAdaptedController4 {
751
+
752
+ @ RequestMapping ("VIEW" )
753
+ @ ActionMapping
754
+ public void myHandle (Model model , ActionResponse response , SessionStatus status ) {
755
+ TestBean tb = new TestBean ();
756
+ tb .setJedi (true );
757
+ model .addAttribute ("testBean" , tb );
758
+ status .setComplete ();
759
+ response .setRenderParameter ("test" , "value" );
760
+ }
761
+
762
+ @ RequestMapping ("EDIT" )
763
+ @ RenderMapping
764
+ public void myHandle (@ RequestParam ("param1" ) String p1 , int param2 , RenderResponse response ,
765
+ @ RequestHeader ("header1" ) String h1 , @ CookieValue ("cookie1" ) String c1 ) throws IOException {
766
+ response .getWriter ().write ("test-" + p1 + "-" + param2 + "-" + h1 + "-" + c1 );
767
+ }
768
+
769
+ @ RequestMapping ("HELP" )
770
+ @ RenderMapping
771
+ public void myHandle (@ ModelAttribute ("tb" ) TestBean tb , RenderResponse response ) throws IOException {
772
+ response .getWriter ().write ("test-" + tb .getName () + "-" + tb .getAge ());
773
+ }
774
+
775
+ @ RequestMapping ("VIEW" )
776
+ @ RenderMapping
777
+ public void myHandle (@ ModelAttribute ("testBean" ) TestBean tb , Errors errors , RenderResponse response , PortletSession session ) throws IOException {
778
+ assertTrue (tb .isJedi ());
779
+ assertNull (session .getAttribute ("testBean" ));
780
+ response .getWriter ().write ("test-" + tb .getName () + "-" + errors .getFieldError ("age" ).getCode ());
781
+ }
782
+ }
783
+
784
+
734
785
@ Controller
735
786
private static class MyFormController {
736
787
0 commit comments