当我第一次显示我的页面时,该字段的值得正确。但是当我在下面的addCouloir
方法中提交表单时,该字段显示为空。然而,topologie实例在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;
}
}
答案 0 :(得分:0)
已被禁用的元素&#34;不要提交他们的数据。由于拓扑结构在会话中(@SessionAttributes(value = "topologie", types = { Topologie.class })
),这意味着无论选择的值是什么,它都会保留原始值。
(我不完全确定你的意思&#34;很有价值&#34;)