最初にページを表示すると、フィールドの値が正しく評価されます。しかし、以下のメソッド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;
}
}
あなた 'addCouloir'法に' '@ModelAttribute( "topologie")を入れてください。 – Patrick
@Patrick、提案に感謝しますが、何も変わりません。上記のように、addCouloirメソッドの最後のJava側では、オブジェクトは問題ありません: 'environnement'フィールドは正しい値で埋められます。 – jayjaypg22