Hello,
Sorry about the mistake with the code tags, here is the complete method (it is quite long as it does a bunch of stuff with storing uploaded binary files):
Code:
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.POST)
public Object onSubmit(
@ModelAttribute("transformationExperiment") TransformationExperiment transformationExperiment,
BindingResult result,
HttpServletRequest request,
@RequestParam(value = "transformationId", required = true) String transformationId,
@RequestParam(value = "cancel", required = false) String cancel,
@RequestParam(value = "delete", required = false) String delete)
throws IOException {
List<StoredImage> imgsToRemove = new ArrayList<StoredImage>();
// only process the inputs if the user has not clicked cancel or delete
if (StringUtils.isBlank(cancel) && StringUtils.isBlank(delete)) {
logger.debug("params");
String[] paramValues = request.getParameterValues("removeFile");
if (paramValues != null) {
// remove files named by the parameter
for (String name : request.getParameterValues("removeFile")) {
StoredImage toRemove = null;
for (StoredImage img : transformationExperiment
.getStoredImages()) {
if (img.getSourceBaseName().equals(name)) {
toRemove = img;
break;
}
}
if (toRemove == null) {
throw new IllegalArgumentException("image with name"
+ name + " not found");
} else {
transformationExperiment.getStoredImages().remove(
toRemove);
logger.debug("removed " + toRemove.getSourceBaseName());
imgsToRemove.add(toRemove);
toRemove = null;
}
}
}
Set<StoredImage> imgs = new HashSet<StoredImage>();
MultipartHttpServletRequest mulReq = (MultipartHttpServletRequest) request;
Iterator<?> oIt = mulReq.getFileNames();
while (oIt.hasNext()) {
String fileName = (String) oIt.next();
MultipartFile mpf = mulReq.getFile(fileName);
if (mpf.getSize() == 0) {
continue;
}
StoredImage si = multipartToStoredImage(mpf);
imgs.add(si);
logger.debug("file name = " + fileName);
}
transformationExperiment.getStoredImages().addAll(imgs);
logger.debug("transformation files "
+ transformationExperiment.getStoredImages());
transformationExperiment.setTransformation(transformationService
.getByTransformationId(transformationId));
}
Object returnVal = super.onSubmit(transformationExperiment, result,
cancel, delete);
// if there was no name then fill in a default, note that a default
// name is specified and mentioned in the validator. This is hardcoded
// for now
if (returnVal instanceof BindingResult) {
logger.debug("super returned a binding result");
BindingResult br = (BindingResult) returnVal;
if (br.getFieldError("name") != null) {
ModelAndView mav = new ModelAndView();
mav.getModel().putAll(br.getModel());
logger.debug("error in name");
TransformationExperiment mavTE = (TransformationExperiment) mav
.getModel().get("transformationExperiment");
if (mavTE.getTransformation() != null) {
mavTE.setName("EXP-"
+ mavTE.getTransformation().getTransformationId());
} else {
mavTE.setName("EXP");
}
logger.debug("name set to - " + ((TransformationExperiment) mav
.getModel().get("transformationExperiment")).getName());
returnVal = mav;
}
}
if (imgsToRemove.size() > 0) {
for (StoredImage si : imgsToRemove) {
try {
this.storedImageService.deleteData(si);
} catch (Exception e) {
logger.warn("failed to remove file");
}
}
}
return returnVal;
}
I did some further investigation, what is interesting is that the corrected transformationExperiment object with the correct name actually _does_ appear in the jsp page. I checked this out by logging the object, here is the jsp page:
Code:
<%@ include file="../common/include.jsp"%>
<script type="text/javascript" language="javascript" src="<c:url value='/js/addFile.js'/>"></script>
<script type="text/javascript" language="javascript" src="<c:url value='/js/modifyFile.js'/>"></script>
<title><fmt:message key="editTransExp.title" /></title>
<content tag="heading">
<fmt:message key="editTransExp.edit" />
</content>
<log:debug category="de.mpicbg.sweng.jsp">
${transformationExperiment}
</log:debug>
<form:form name="formEditTransformationExperiment"
commandName="transformationExperiment" enctype="multipart/form-data">
<form:errors path="*" cssClass="errorBox" />
<div class="contentelement">
<table class="edit">
<tr>
<th><fmt:message key="transexp.name" /></th>
<td><form:input path="name" cssClass="text"/></td>
</tr>
<tr>
<th><fmt:message key="transexp.color" /></th>
<td><form:select path="color" cssClass="input" items="${options.color}"/></td>
</tr>
--cutting out a load of superfluous stuff--
<tr>
<th><fmt:message key="generic.text.description" /></th>
<td><form:textarea path="description" cssClass="text" rows="8" /></td>
</tr>
--cutting out a load of superfluous stuff--
</form:form>
If I replace the line :
Code:
<td><form:input path="name" cssClass="text"/></td>
with
[code]
<td><input class="text" type="text" name="name" value="${transformationExperiment.name}"></td>
[/cpde]
it works fine. In addition, if I try and set a different parameter in my onSubmit method, such as description this also gets propagated when the page is resent to the client. Only name does not.
For now I have the <em>raw</em> html in there which is a bit of a dirty hack but I'd like to get to the bottom of what is going wrong here.
Well, that was a rather long message - sorry for that. If anyone has any ideas I'd be v. grateful.
Cheers,
Neil