Hey all,
I've posted the full question on StackOverflow.com at the following link. Since the need for a solution is urgent, I decided that I should post it on this forum as well. Thanks for taking the time to look.
http://stackoverflow.com/questions/1...ing-spring-mvc
Regardless, this is my setup...
MODEL
VIEWCode:public class UploadForm { private CommonsMultipartFile fileData; public CommonsMultipartFile getFileData() { System.out.println("REACHED GET METHOD"); return fileData; } public void setFileData(CommonsMultipartFile fileData) { System.out.println("REACHED SET METHOD"); this.fileData = fileData; } }
CONTROLLERCode:<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> <%@ page session="false" %> <html> <head> <title>Upload Document</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript"> </script> <script type="text/javascript" src="resources/rulesextractor.js"></script> <link rel="stylesheet" type="text/css" href="./resources/css/rulesextractor.css" /> </head> <body> <c:import url = "./header.jsp"> <c:param name = "title" value = "Upload Document"/> <c:param name = "region" value = "${region}"/> </c:import> <br> Please choose a Document to upload <br> <form:form method="POST" modelAttribute="uploadForm" commandName="uploadForm" name="uploadForm" id="uploadForm" enctype="multipart/form-data"> <form:input path="fileData" name="fileData" type="file"/> <br> <input type="submit" name="submit" value="Submit" id="subbtn"/> <input type="button" value="Main Menu" onclick="back();"/> </form:form> </body> </html>
The issue here is that I am in fact entering the Controller's public String create(@Valid UploadForm UploadForm, BindingResult result) method, but UploadForm is being passed as a null value and I can't, for the life of me, figure it out and it's getting quite frustrating. I do not believe that the file that the user is uploading is being passed to the model using the set method. THe reason I belive this is because the get method'sCode:@Controller public class UploadController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(FlowController.class); //@Autowired //private UserPreferences userPreferences; @Autowired GenericSearchBO genericSearchBO; @RequestMapping(value = "upload", method = RequestMethod.GET) public String getUploadPage(Model m){ logger.info("UploadController: Getting Upload page"); updateRegionOnModel(m); m.addAttribute(new UploadForm()); return "/pages/upload"; } @RequestMapping(method = RequestMethod.POST) public String create(@Valid UploadForm UploadForm, BindingResult result){ if (result.hasErrors()) { for(ObjectError error : result.getAllErrors()) { System.err.println("Error: " + error.getCode() + " - " + error.getDefaultMessage()); } return "/pages/upload"; } // Some type of file processing... System.err.println("-------------------------------------------"); //.getOriginalFilename() System.err.println("Test upload: " + UploadForm.getFileData()); System.err.println("-------------------------------------------"); return "redirect:/pages/upload"; } }is being reached, but the model's set method'sCode:System.out.println("REACHED GET METHOD");is not.Code:System.out.println("REACHED SET METHOD");


Reply With Quote
