spring form taglib disable属性是否真的必须解析为字符串? [英] Does spring form taglib disabled attribute really have to resolve to a string?
问题描述
我最近一直在使用spring形式的taglib,遇到了一个相当令人不安的现象.
I've been playing around with the spring form taglib lately and came across a fairly disturbing phenomenon.
<form:select path="whatever" disabled="${true}">
将呈现未禁用的选择元素
Will render a select element that is NOT disabled
<form:select path="whatever" disabled="${'true'}">
将呈现被禁用的选择元素.
Will render a select element that IS disabled.
这向我表明,标记在该属性中需要一个字符串,并且拒绝强制使用任何布尔值(可能首先检查类型).
This indicates to me that the tag expects a string in that attribute and is refusing to coerce any boolean values (possibly checking the type first).
影响是我无法执行<form:select path="whatever" disabled="${someOtherfield.selectedId != -1}" />
之类的事情,而这在我们的系统中经常发生.
The impact is that I'm unable to do something like <form:select path="whatever" disabled="${someOtherfield.selectedId != -1}" />
which is something that happens fairly often in our system.
我只是缺少表单标签库功能的某些部分吗?这是一个合理的设计决定吗?有缺陷吗?
Am I simply missing some part of the form taglibs functionality? Is this a legitimate design decision? A defect?
推荐答案
好吧,我对此做了更多的挖掘,因为这种解决方法看起来太难看了.
Ok, I did some more digging around this one, because the work-arounds were looking too ugly.
http://forum.springsource.org/showthread.php?t=84102
问题是JSP正在评估el,并使用"true"盲目比较评估结果.等于
The problem was that the JSP was evaluating the el, and blindly comparing the result of that evaluation using "true".equals
使用该方法将字符串与布尔值进行比较将始终返回false,因为类型不匹配,因此肯定是缺陷.
Comparing a String to a Boolean using that method will always return false because the type's don't match so it's definitely a defect.
幸运的是,有问题的isDisabled方法是一个受保护的衬套,因此我能够通过扩展8个输入标签的作用并覆盖该方法以进行更稳健的比较来解决该问题.
Fortunately the isDisabled method at fault is a protected one liner, so I have been able to work around it by extending the 8 input tag's effected and overriding that method to do a slightly more robust comparison.
所以答案是,是的,这是一个缺陷,从skaffman的评论看来,随着JSP EL的实现,旧库没有得到很好的更新,这似乎是一个问题.
So the answer is, yes, it is a defect, and from skaffman's comments it looks like it's a bit of a problem with an old library not being very well updated as JSP EL was implemented.
感谢您的回答
这篇关于spring form taglib disable属性是否真的必须解析为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!