Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts2 UI textarea tag adding "class" attribute fills it self with "class java.util.HashMap" value

Tags:

struts2

This is just a why is something weird happening question.

I made a mistake and was supposed to use "cssClass" but typed "class" instead. However "class" is not defined as a property of the textarea tag so I expected the behaviour to be the same as the cssClass value (a non defined property should be rendered as is, and it does render the property but has a strange value and that value does not seem to be alterable. Any value I feed it is ignored and defaults to the class which backs the tag).

For instance if I define a "turkey" value I would expect a turkey value to be rendered in html and it is as we can see in the following example.

Here is what I used on the JSP:

<s:textarea turkey="" class="" name="qualLine.description" value="%{description}"/>

Here is what was rendered:

<textarea name="qualLine.description" cols="" rows="" id="cows" class="class java.util.HashMap" turkey="">test</textarea>

My question isn't what should I do, because I should have used cssClass instead of class, my question is: Is this expected and why?

like image 416
Quaternion Avatar asked Aug 31 '12 04:08

Quaternion


1 Answers

Perhaps it is related to the Freemarker TemplateModel being used?

In the dynamic-attributes.ftl, which is included from the textarea.ftl to resolve the dynamic attributes, the attribute value is first evaluated against the ValueStack using a StrutsUtil.translateVariables instance, which just uses a static call to the TestParseUtil.translateVariables. But when that doesn't evaluate to anything (null or void), it then reverts to the attribute name - class.

This value, "class", is then evaluated as a Freemarker expression - ${class} - in the dynamic-attributes.ftl.

The StrutsUtil is placed in the Freemarker template model from the FreemarkerManager which calls the ContextUtil to retrieve a map of Struts2 objects to place into the template model. This map that is placed in the TemplateModel is a HashMap (perhaps the culprit map?).

So, this is obviously not a complete answer, so I don't expect the "answer" to be accepted, but it was too much to place in a comment and it may help to shed some light. If I have time later in the week, I may pull down the Struts2 source and play with it to find the real answer. But more likely, I won't take the time!

Interesting question for sure, though.

like image 75
rees Avatar answered Sep 27 '22 19:09

rees