![](/img/trans.png)
[英]Difference between modelAttribute and commandName attributes in form tag in spring?
[英]How to dynamically assign a value to the commandName attribute in <form:form> tag of spring
我想使用以下JSTL代碼將字符串值動態添加到commandName屬性。
<c:choose>
<c:when test='${catalogueEntry==null}'>
add_item
</c:when>
<c:otherwise>
update_item
</c:otherwise>
</c:choose>
看起來像春天正在將整個代碼解釋為字符串值,而不是分配值“ add_item”或“ update_item”。 我也嘗試使用javascript代碼,但發現它給出的錯誤與客戶端技術相同。 誰能告訴我我的問題在哪里?
只需使用EL三元運算符 。 在您的情況下,代碼可以寫成:
<form:form method="post" commandName="${(catalogueEntry==null) ? 'add_item' : 'update_item'}">
...
</form:form>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.