1 16 17 package org.springframework.web.portlet.mvc; 18 19 import java.util.Map ; 20 21 import javax.portlet.ActionRequest; 22 import javax.portlet.ActionResponse; 23 import javax.portlet.PortletException; 24 import javax.portlet.PortletRequest; 25 import javax.portlet.RenderRequest; 26 import javax.portlet.RenderResponse; 27 28 import org.springframework.validation.BindException; 29 import org.springframework.validation.Errors; 30 import org.springframework.web.portlet.ModelAndView; 31 32 136 public class SimpleFormController extends AbstractFormController { 137 138 private String formView; 139 140 private String successView; 141 142 143 156 public SimpleFormController() { 157 super(); 159 } 160 161 164 public final void setFormView(String formView) { 165 this.formView = formView; 166 } 167 168 171 public final String getFormView() { 172 return this.formView; 173 } 174 175 178 public final void setSuccessView(String successView) { 179 this.successView = successView; 180 } 181 182 185 public final String getSuccessView() { 186 return this.successView; 187 } 188 189 190 203 protected ModelAndView showForm(RenderRequest request, RenderResponse response, BindException errors) 204 throws Exception { 205 206 return showForm(request, response, errors, null); 207 } 208 209 223 protected ModelAndView showForm(RenderRequest request, RenderResponse response, BindException errors, Map controlModel) 224 throws Exception { 225 226 return showForm(request, errors, getFormView(), controlModel); 227 } 228 229 241 protected Map referenceData(PortletRequest request, Object command, Errors errors) throws Exception { 242 return referenceData(request); 243 } 244 245 256 protected Map referenceData(PortletRequest request) throws Exception { 257 return null; 258 } 259 260 261 274 protected ModelAndView renderFormSubmission(RenderRequest request, RenderResponse response, Object command, BindException errors) 275 throws Exception { 276 277 if (errors.hasErrors() || isFormChangeRequest(request)) { 278 return showForm(request, response, errors); 279 } 280 else { 281 return onSubmitRender(request, response, command, errors); 282 } 283 } 284 285 299 protected void processFormSubmission( 300 ActionRequest request, ActionResponse response, Object command, BindException errors) 301 throws Exception { 302 303 if (errors.hasErrors()) { 304 if (logger.isDebugEnabled()) { 305 logger.debug("Data binding errors: " + errors.getErrorCount()); 306 } 307 if (isRedirectAction()) { 308 setFormSubmit(response); 309 } 310 passRenderParameters(request, response); 311 } 312 else if (isFormChangeRequest(request)) { 313 logger.debug("Detected form change request -> routing request to onFormChange"); 314 if (isRedirectAction()) { 315 setFormSubmit(response); 316 } 317 passRenderParameters(request, response); 318 onFormChange(request, response, command, errors); 319 } 320 else { 321 logger.debug("No errors - processing submit"); 322 onSubmitAction(request, response, command, errors); 323 } 324 } 325 326 332 protected boolean suppressValidation(PortletRequest request) { 333 return isFormChangeRequest(request); 334 } 335 336 348 protected boolean isFormChangeRequest(PortletRequest request) { 349 return false; 350 } 351 352 368 protected void onFormChange(ActionRequest request, ActionResponse response, Object command, BindException errors) 369 throws Exception { 370 371 onFormChange(request, response, command); 372 } 373 374 384 protected void onFormChange(ActionRequest request, ActionResponse response, Object command) 385 throws Exception { 386 } 387 388 389 416 protected ModelAndView onSubmitRender(RenderRequest request, RenderResponse response, Object command, BindException errors) 417 throws Exception { 418 419 return onSubmitRender(command, errors); 420 } 421 422 443 protected void onSubmitAction(ActionRequest request, ActionResponse response, Object command, BindException errors) 444 throws Exception { 445 446 onSubmitAction(command, errors); 447 } 448 449 472 protected ModelAndView onSubmitRender(Object command, BindException errors) throws Exception { 473 ModelAndView mv = onSubmitRender(command); 474 if (mv != null) { 475 return mv; 477 } 478 else { 479 if (getSuccessView() == null) { 481 throw new PortletException("successView isn't set"); 482 } 483 return new ModelAndView(getSuccessView(), errors.getModel()); 484 } 485 } 486 487 501 protected void onSubmitAction(Object command, BindException errors) throws Exception { 502 onSubmitAction(command); 503 } 504 505 520 protected ModelAndView onSubmitRender(Object command) throws Exception { 521 return null; 522 } 523 524 536 protected void onSubmitAction(Object command) throws Exception { 537 doSubmitAction(command); 538 } 539 540 552 protected void doSubmitAction(Object command) throws Exception { 553 } 554 555 } 556 | Popular Tags |