I´m developing a WebApp with Spring MVC. The Problem is that my model which I pass through with @ModelAttribute, in my POST Method of my Controller seems to be empty, despite I have filled out the form on the web page.
This is the GET Method of my Controller:
@RequestMapping(value = "/CircleUp", method = RequestMethod.GET)
public ModelAndView circleUpGet(Model _model) {
ModelAndView modelAndView = new ModelAndView("CircleUp");
CircleUpModel circleUpModel = new CircleUpModel();
_model.addAttribute("circleUpModel", circleUpModel);
return modelAndView;
}
This is the POST Method of my Controller:
@RequestMapping(value = "/CircleUp", method = RequestMethod.POST)
public ModelAndView circleUpPost(HttpServletRequest _request, Model _model, @ModelAttribute("circleUpModel") CircleUpModel _circleUpModel) {
return this.doCircleUp(_request, _model, _circleUpModel);
}
Here the "_circleUpModel" does not have any values.
This is my form in the related .jsp File with the needed script:
<form:form method="post" modelAttribute="circleUpModel" id="circle_form" action="" enctype="multipart/form-data" >
<form:input path="file" id="upload" type="file" />
<form:checkbox path="mergeSameTickmarks" checked="true" />
<form:checkbox path="deleteHighlights" checked="true" />
<form:checkbox path="generateFigureLog" checked="true" />
...
<input type="button" onclick="javascript:submitForm()"
value="Start Circle Up">
function submitForm() {
if (checkIfPdf() && checkSettings()) {
$("#circle_form").submit()
setTimeout(progress, 100);
}
}
Of course the default values of the CircleUpModel are presented but if I enter some other values in the form of the web page this entrys are not considered in the POST Method, despite I added the modelAttribute="circleUpForm"
in my form.
CircleUpModel:
import org.pdfclown.files.File;
public class CircleUpModel {
// File
private File file;
// FileName
private String fileName;
private boolean mergeSameTickmarks;
private boolean deleteHighlights;
private boolean generateFigureLog;
// Settings
private double circleBorderWidth;
private double customizeCircleUp;
private double customizeCircleDown;
private double gapLeft;
private double gapRight;
private double maxGap;
private boolean tickmarkAlwaysUpperCase;
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public boolean isMergeSameTickmarks() {
return mergeSameTickmarks;
}
public void setMergeSameTickmarks(boolean mergeSameTickmarks) {
this.mergeSameTickmarks = mergeSameTickmarks;
}
public boolean isDeleteHighlights() {
return deleteHighlights;
}
public void setDeleteHighlights(boolean deleteHighlights) {
this.deleteHighlights = deleteHighlights;
}
public boolean isGenerateFigureLog() {
return generateFigureLog;
}
public void setGenerateFigureLog(boolean generateFigureLog) {
this.generateFigureLog = generateFigureLog;
}
public double getCircleBorderWidth() {
return circleBorderWidth;
}
public void setCircleBorderWidth(double circleBorderWidth) {
this.circleBorderWidth = circleBorderWidth;
}
public double getCustomizeCircleUp() {
return customizeCircleUp;
}
public void setCustomizeCircleUp(double customizeCircleUp) {
this.customizeCircleUp = customizeCircleUp;
}
public double getCustomizeCircleDown() {
return customizeCircleDown;
}
public void setCustomizeCircleDown(double customizeCircleDown) {
this.customizeCircleDown = customizeCircleDown;
}
public boolean isTickmarkAlwaysUpperCase() {
return tickmarkAlwaysUpperCase;
}
public void setTickmarkAlwaysUpperCase(boolean tickmarkAlwaysUpperCase) {
this.tickmarkAlwaysUpperCase = tickmarkAlwaysUpperCase;
}
public double getGapLeft() {
return gapLeft;
}
public void setGapLeft(double gapLeft) {
this.gapLeft = gapLeft;
}
public double getGapRight() {
return gapRight;
}
public void setGapRight(double gapRight) {
this.gapRight = gapRight;
}
public double getMaxGap() {
return maxGap;
}
public void setMaxGap(double maxGap) {
this.maxGap = maxGap;
}
}
This problem could be resolved by changing the type of the file in the model.
Previously it was a pdfclown file and now I have changed it into a MultipartFile. In my POST Method I have converted the file from MultipartFile into pdfclown File to be able to work with it like before.