This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
In the tutorial, setOptionsList() is called by the container, because the attribute called "optionsList" is defined in the TLD. If you declare an attribute in the TLD, you must make the equivalent setter method so that the container can set the attribute's value in the tag handler.
But i dont see the list of tagAttributes ever be set.
In the tutorial, the FormSelectTagHandler implements the DynamicAttributes interface. This interface has only one method :
setDynamicAttribute(String uri, String localName, Object value).
This method will be called by the container to set any attribute which is not declared in the TLD. For the formTags:select tag, you can see that only the "optionsList" attribute is declared in the TLD. What about "name" and "tabindex" ? If your handler implements DynamicAttributes, the container will call the setDynamicAttribute method twice. Once to tell the handler that there is an extra attribute called "name" whose value is "colorField", and another to time to tell the handler that there is also an attribute called "tabindex" whose value is "2".
In the tag handler, you can store these attributes in a Map. In the tutorial, the dynamic attributes are set into the tagAttributes map.
Joined: Mar 18, 2009
so you call setDynamicAttribute multiple times? for each attribute you want to set?