And, in the JSP file, it uses the "if" tag like this:
Now my question is: where does it say the attribute "condition" is a boolean? What if, in the JSP page, I used the "if" tag like this? <test:if condition="1" /> At translation time, there will be no error. It will blow up at request time if the tag handler class only takes in boolean values for the "condition" parameter. Is this logic correct?
An interesting question. I can't say for sure but I think there are two important points to remember: 1)The example was used to show the use of JSP body-content, not as a full-blown example of the inner workings of a specific tag, or of the possible problems resulting from use of incompatible type. 2)I assume that you don't use a custom tag without some knowledge of it. So if this were instead an example of a the inner workings of this specific sampleLib.IfTag class then the the text would probably indicate that the class/tag expects the "condition" attribute to be a boolean. Since there is an optional "type" subelement for any attribute though, it seems like it might be wise to include the type when it's something other than String, which is the default. But I really haven't seen type mentioned much in either of the certification books I've read. Given your question though and the problems that seem like they could occur from using the wrong type it seems to me like a good idea to include it in the attribute list.
Yup, I agree! I think "type" should definitely be mandatory. I guess the simple answer to my question would be simply to test it. However, my excuse is that I am taking the test Wednesday and I am cramming the taglib section, so I'd rather be lazy and have people answer my questions here I'm just trying to predict what would happen...which probably explains why I get into trouble often... Thanks for your response Ken....
Good luck, Coco. I'm taking mine on Tuesday. Ken And the question was actually good preparation for test as I had to look up the subelements of attribute. Let's hope we both get asked about it on our tests.