2017-04-05 25 views
0

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

認沽'@ModelAttribute( 「topologie」)'您'addCouloir'方法。 – Patrick

+0

@帕特里克,感謝您的建議,但它不會改變任何內容。正如問題所述,在addCouloir方法結尾的java方面,對象很好:environnement字段用正確的值填充。 – jayjaypg22

回答

0

已被「禁用」的元素不提交其數據。由於拓撲是在會話中(@SessionAttributes(value = "topologie", types = { Topologie.class })),這意味着它將保持原始值,而不管選擇的值是什麼。

(我不完全相信你的 「價值好」 的意思)

+0

我很高估我的意思是它保持其原始價值。這就是我想要的,只是在不允許改變的情況下讓用戶回想這個值。即使當我刪除'disabled'屬性時,環境值也是空的。這是我不明白的行爲:我不知道價值在哪裏變化。 – jayjaypg22