當我第一次顯示我的頁面時,字段被正確評估。但是當我在下面的方法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