Spring MVC portlet. Check before @ResourceMapping. @ResourceMapping & # 8594; @RenderMapping

My case: the user can upload files. There is a list of files that he can select. There is a spring mapping:

@ResourceMapping(DOWNLOAD)
public void downloadSelected(ResourceRequest request, ResourceResponse response, AuditView auditView, BindingResult bindingResult) {
}

auditView has a list of files.

If the user has not selected any item, I need to check and display the same page with the error displayed.

I can check: validator.validate(auditView, bindingResult);

The question is, how do I forward the Render phase in case of errors?

+3
source share
3 answers

It may be too late for you to answer, but it may be helpful to others.

You can not send Requestin RenderPhasefrom ResourcePhase.

, .

0

WebSphere Liberty Profile, , :

@ResourceMapping
public void downloadSelected(@Valid @ModelAttribute("entity") Entity entity, BindingResult bindingResult, ResourceResponse response)
{
   if (bindingResult.hasErrors()) {
      response.setProperty(ResourceResponse.HTTP_STATUS_CODE, "302");
      response.setProperty("Location", response.createRenderURL().toString());
   } else {
      response.setContentType("application/pdf");
      response.setProperty("Content-disposition", "attachment; filename=\"mydownload.pdf\"");
      /* ... */
   }
}

, , , , Spring MVC <form:errors /> JSP.

0

AuditView @Valid @ModelAttribute. @Valid . @ModelAttribute AuditView .

@ResourceMapping(DOWNLOAD)
public void downloadSelected(ResourceRequest request, ResourceResponse response,@Valid @ModelAttribute("auditView") AuditView auditView, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
        return "thedownloadpage";
    } 
-1

All Articles