File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Really confused about how Dynamic Attributes work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Really confused about how Dynamic Attributes work" Watch "Really confused about how Dynamic Attributes work" New topic
Author

Really confused about how Dynamic Attributes work

Jim So
Greenhorn

Joined: Mar 18, 2009
Posts: 28
Hi guys. This forum is the best. Thanks everyone for your contributions.
I love this head first book its so awesome to read.

But im stuck on Dynamic Attributes.

I read the pages 550-560 on v2 of Head First Servlets & JSP book.

I also read http://www.coderanch.com/t/170429/Web-Component-Certification-SCWCD/certification/Tutorial-Dynamic-Attributes

I dont understand how the optionsList on p557 gets set. i guess its set via something calling setOptionsList. But what calls setOptionsList? But how do the HTML attributes get set?

The code makes sense to me, but i dont know where the attributes actually get populated on the optionsList object.

Can anyone help?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Jim So
Greenhorn

Joined: Mar 18, 2009
Posts: 28
thanks very much for your reply.

I am still really confused with this:

I would like to know how the HTML tagAttributes get set? I cant understand this....

so for select tag, they say that it has many attributes right.

And by using dynamic attributes, we can populate tagAttributes with all of these select attributes like size, colour, id, class, title, lang, dir, onclick, disbaled, mutiple, onfocus etc etc

But i dont see the list of tagAttributes ever be set. we loop through them (the tag names and values) here:

# for ( String attrName : tagAttributes.keySet() ) {
# out.print(attrName);
# out.print("='");
# out.print(tagAttributes.get(attrName));

but where are the tagAttributes set? (onchange, onblur, onclick, id, lang, title, dir, etc etc)

The whole point of using dynamic attributes is that the attributes for that tag are automatically added. But how??

Does it some how know the names of the html select tag? I dont see where the tag attributes are set.
Jim So
Greenhorn

Joined: Mar 18, 2009
Posts: 28
if anyone can help with this, it would be much appreciatd, thanks in advance!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.
Jim So
Greenhorn

Joined: Mar 18, 2009
Posts: 28
so you call setDynamicAttribute multiple times? for each attribute you want to set?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

so you call setDynamicAttribute multiple times?

The container calls it for you.
Jim So
Greenhorn

Joined: Mar 18, 2009
Posts: 28
*Bing* I finally get it!! Thanks for your help dude - your a legend!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Really confused about how Dynamic Attributes work
 
Similar Threads
Book for SCWCD 5.0
reg scwcd
Doubt in JSP Custom tags (Simple Tag) in Dynamic Drop Down
Tutorial on Dynamic Attributes
Need Help ?