Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

The follow snippet might be useful during debugging to list the properties inside an
arbitary bean. Or for handing to a UI developer that use unaware of the getters/setters inside an object.

Code Block
languagetext

## prints out the property names for a bean
#macro (describeBean $name) 
#set($bu = $webwork$struts.bean("com.opensymphony.util.BeanUtils"))
	#foreach($propName in $bu.getPropertyNames($name))
		<li>$propName</li>
	#end
#end

i.e. assuming $obj is a PersonObject that has properties(firstName, lastName, and zip).

Code Block
languagetext
#describeBean($obj)

would print

Code Block
languagexml
<li>firstName</li>

...


<li>lastName</li>

...


<li>zip</li>

One might also expand upon this to build a dynamic interface with via reflection. e.g.

Code Block
languagetext
$struts
$webwork.evalute("$obj.${propName}")