In this code:
<html:text property="txtItem5" disabled="disTxtItem5">
I can see that “txtItem5” comes from a getTxtItem5() in the ActionForm, but searching the project for other substrings of “disTxtItem5” seemingly reveals nothing remotely related, though clearly somehow the framework is pulling a boolean from this string, which clearly means that it’s more complicated than my current understanding.
Could someone give a good explanation of how these expressions are evaluated, or point me in the direction of one?
EDIT: In my original response (see below) I said that Struts manages the conversion, but I was wrong. I didn’t remember exactly what was going so I pulled out Struts’s sources and took a look. It turns out that the conversion is made by the server. The JSP is converted to a servlet before execution and it is here that false is used for non boolean values.
For example, I used the following tag:
Which was translated to the following html (no disabled):
This happened in the servlet. Here is what my servlet contains for the above tag:
As it can be seen, the disabled value is generated with false, directly. I did some more digging into the Jasper compiler (I used Tomcat) and I think that it is the org.apache.jasper.compiler.JspUtil class that is responsible for the conversion, with the following code:
Since I inserted BlaBla in the disabled field this should fallback to
Boolean.valueOf(s).booleanValue();which does the following:This way, BlaBla results in false.
ORIG: The following was my original response, but was incorrect. What I was describing was in fact what happens when request parameters are binded to the action form.
The disabled attribute is of type boolean, so it should receive only values that map to a boolean.
disabled="disTxtItem5"would throw a ConversionException because the textdisTxtItem5does not map to a boolean.Struts uses CommonBeanUtils to make conversions, so a BooleanConverter will be used, with code like the following:
At this point I don’t remember if Struts just logs the exception and fails silently setting false as the value of the parameter or, the exception is propagated (it’s been a while since I used Struts 😀 but I’m more inclined to think that it just sets false and continues).
The logs should point out the exception even if it is ignored. Setting a logger for
org.apache.commons.beanutilsororg.apache.strutsshould indicate any conversion errors.