当我第一次显示我的页面时,字段被正确评估。但是当我在下面的方法addCouloir
中提交表单时,该字段显示为空。然而拓扑实例在addCouloir方法的最后一行仍然非常有价值(我在调试模式下检查了对象)。字段被清空,但控制器端填充了对象
拓扑对象的同一个实例的其他字段可以很好地显示在同一个对象上。因此,它可能涉及到select/disabled
领域的一种
@Controller
@SessionAttributes(value = "topologie", types = { Topologie.class })
@RequestMapping("/bus/topologieInstanceCouloir")
public class TopologieInstanceCouloirController {
...
@RequestMapping(method = RequestMethod.POST, params = { "addCouloir" })
public String addCouloir(final Topologie topologie, final Model model,
final HttpServletRequest req) throws IOException {
final String param = req.getParameter("addCouloir");
logger.info("REST request to add Couloir : {}", param);
final Matcher matcher = patternPartitionInstance.matcher(param);
if (matcher.find()) {
final Integer partitionId = Integer.valueOf(matcher.group(1));
final Integer instanceId = Integer.valueOf(matcher.group(2));
logger.info("Add a new Couloir on Instance {} on partition {}",
instanceId, partitionId);
topologie.getPartitions().get(partitionId.intValue())
.getInstances().get(instanceId).getCouloirs()
.add(new Couloir());
}
return VIEW_TOPOLOGIE_INSTANCECOULOIR;
}
的HTML/thymeleaf topologieInstanceCouloir.html相应的代码:
<form action="#" th:action="@{/bus/topologieInstanceCouloir}"
th:object="${topologie}" method="post" class="form-horizontal">
...
<div class="form-group"
th:if="${#bools.isFalse(topologie.isPassageCvs)}">
<label th:for="*{environnement}" class="col-sm-2 control-label">Environnement</label>
<div class="col-sm-10">
<select th:field="*{environnement}" class="form-control"
th:disabled="disabled">
<option th:each="environnement : ${allEnvironnement}"
th:value="${environnement}" th:text="${environnement}">...</option>
</select>
</div>
</div>
按钮:
<div class="col-sm-10">
<button type="submit" class="btn btn-default"
name="addCouloir"
th:value="'partitions[' + ${rowPartitionStat.index} + '].instances[' + ${rowInstanceStat.index} + ']'">Ajouter
couloir</button>
</div>
相关Topologie对象:
public class Topologie {
private String environnement;
...
public String getEnvironnement() {
return environnement;
}
public void setEnvironnement(String environnement) {
this.environnement = environnement;
}
}
认沽'@ModelAttribute( “topologie”)'您'addCouloir'方法。 – Patrick
@帕特里克,感谢您的建议,但它不会改变任何内容。正如问题所述,在addCouloir方法结尾的java方面,对象很好:environnement字段用正确的值填充。 – jayjaypg22