Are spaces allowed in the name attribute of the Struts logic: equal tag?

I found the following markup in a JSP file in a legacy application that I maintain:

<logic:equal name="welcome memberInfoView" property="hasFoo" value="false">

      

This name attribute looks very wrong to me. Based on what I've read in the Struts docs, this space is not allowed.

Is this legal? If so, what will he do? If not, what could be the intent?

EDIT: After some searching, I found that "welcome memberInfoView" was indeed intentionally used as an attribute name (with a space).

0


source to share


1 answer


Actually, this name is legitimate, but unconventional. While legally syntactically it could be an error.

"Name" specifies the name of the attribute in some scope (defined by the optional "scope" attribute, by default "any"), not the name of a script variable. Since this is actually a key in the map, it can be any character string.

This tag will run in the context of the page and look for an attribute named "welcome memberInfoView". It will continue to span scopes until a named object is found. Then it will look at the hasFoo property of that object. If it is false, the private fragment is called.



Another thing that looks wrong is the hasphoo property. Usually the property will just be "foo" and the object must have an accessor called isFoo()

or getFoo()

. Perhaps the boolean tag is soft in this regard and will call the method successfully hasFoo()

.

You can create a simple test for this use and make sure it works as you intend.

+2


source







All Articles