tags:

views:

171

answers:

1

I came across the following markup in a JSP file in a legacy app I maintain:

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

That name attribute looks very wrong to me. Based on what I've read in the Struts docs, that space isn't allowed.

Is this legal? If so, what would it be doing? If not, what might the intent have been?

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

+2  A: 

Actually, this name is legal, but unconventional. While legal syntactically, it may indeed be a bug.

The "name" specifies an attribute name in some scope (determined by the optional "scope" attribute, which defaults to "any"), not a scripting variable name. Since it is effectively a key into a map, it can be any character string.

This tag will start in the page context and look for an attribute named "welcome memberInfoView". It will continue to enclosing scopes until the named object is found. Then it will look at the "hasFoo" property of that object. If it is "false", the enclosed fragment will be invoked.

Another thing that looks wrong is the property, "hasFoo". Normally, the property would just be "foo", and the object should have an accessor called isFoo() or getFoo(). Perhaps the logic tag is lenient in this respect, and will successfully invoke the hasFoo() method.

You might create a simple test for this usage, and make sure it works as you intend.

erickson