控制器:
@RequestMapping(value="/add", method= RequestMethod.POST)
public String addVA(@ModelAttribute("va") VA va, BindingResult result){
//BindingResult result
System.out.print("VA = " +va);
if(va.getIDVA() == 0){
this.vaService.addVA(va);
}else{
this.vaService.updateVA(va);
}
return "redirect:/VA/";
}
查看:
<form:form action="${addAction}" commandName="va">
<table>
<c:if test="${!empty va.name}">
<tr>
<td>
<form:label path="IDVA">
<spring:message text="ID"/>
</form:label>
</td>
<td>
<form:input path="IDVA" readonly="true" size="8" disabled="true" />
<form:hidden path="IDVA" />
</td>
</tr>
</c:if>
<tr>
<td>
<form:label path="name">
<spring:message text="Nom du version"/>
</form:label>
</td>
<td>
<form:input path="name" />
<springForm:errors path="name" cssClass="error" />
</td>
</tr>
<tr>
<td>
<form:label path="description">
<spring:message text="Description"/>
</form:label>
</td>
<td>
<form:input path="description" />
<springForm:errors path="description" cssClass="error" />
</td>
</tr>
<tr>
<td>
<form:label path="startDate">
<spring:message text="Date début"/>
</form:label>
</td>
<td>
<springForm:input path="startDate" placeholder="MM/dd/yyyy"/>
<springForm:errors path="startDate" cssClass="error" />
</td>
</tr>
<tr>
<td>
<form:label path="endDate">
<spring:message text="Date fin"/>
</form:label>
</td>
<td>
<springForm:input path="endDate" placeholder="MM/dd/yyyy"/>
<springForm:errors path="endDate" cssClass="error" />
</td>
</tr>
<tr>
<td>
<form:label path="projetMetiers">
<spring:message text="Projets"/>
</form:label>
</td>
<td>
<form:select multiple="true" path="projetMetiers" name="projetMetiers">
<form:options items="${projets}" itemValue="IDPM" itemLabel="name"/>
</form:select>
</td>
</tr>
<tr>
<td>
<label>Application</label>
</td>
<td>
<ul>
<form:select name="application" path="application">
<form:option value="-1"> --SELECT--</form:option>
<form:options items="${applications}" itemValue="IDAPP" itemLabel="name"></form:options>
</form:select>
</ul>
</td>
</tr>
<tr>
<td colspan="2">
<c:if test="${!empty va.name}">
<input type="submit"
value="<spring:message text="Modifier"/>" />
</c:if>
<c:if test="${empty va.name}">
<input type="submit"
value="<spring:message text="Ajouter"/>" />
</c:if>
</td>
</tr>
</table>
</form:form>
对象应用程序为空!