Attribute spring form taglib disabled attribute should really be allowed for string?

Recently, I played with the spring formlib tag and came across a pretty troubling phenomenon.

<form:select path="whatever" disabled="${true}"> 

Will display a select element that is NOT disabled

 <form:select path="whatever" disabled="${'true'}"> 

Will display a select element that is disabled by IS.

This tells me that the tag expects a string in this attribute and refuses to force any boolean values ​​(perhaps it checks the type first).

The effect is that I cannot do something like <form:select path="whatever" disabled="${someOtherfield.selectedId != -1}" /> , which often happens on our system.

Am I just missing some of the functionality of form taglibs? Is this a legit design decision? Defect?

+6
java spring spring-mvc jsp
source share
3 answers

Well, I did a few more digging around this because the detour looked too ugly.

http://forum.springsource.org/showthread.php?t=84102

The problem was that the JSP evaluated el and blindly compared the result of that evaluation using "true .equals"

Comparing String with a boolean using this method will always return false, because the type does not match, so it is definitely a defect.

Fortunately, the failure method isDisabled is protected by one liner, so I was able to get around it by expanding 8 input tags and processing this method to make a slightly more reliable comparison.

So the answer is: yes, this is a defect, and from skaffman's comments, it looks like the problem with the old library does not update very well as the JSP EL is introduced.

Thank you guys for your answers.

+5
source share

This is a little strange enough. Spring source code shows that the disabled SelectTag property is String , not boolean . This is clearly not the case, but I suspect it is for legacy reasons (spring -form.tld pre-dates JSP EL).

This leaves it at JSP runtime to force boolean to String , and apparently it will not. I am less surprised by this, as JSP EL is known to be limited.

So, you get between two dilapidated implementations. You just need to make sure that you pass String values ​​to this attribute.

+1
source share

The reason for this design is that they have a special backup code to force the definition of an EL expression when the container does not evaluate it. For example, this code:

 <%@ page isELIgnored = "true" %> ... ${'Simple text'} <spring:message text = "${'Message text'} />" 

produces ${'Simple text'} Message text

Perhaps this is useful for some weird container configurations.

That is, the following code will not work if they make the disabled boolean attribute:

 <%@ page isELIgnored = "true" %> ... <form:select ... disabled = "${true}" /> 
0
source share

All Articles