[英]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.