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 Simple Tag & Classic Tag handler mock exam question - what's YOUR answer? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Simple Tag & Classic Tag handler mock exam question - what Watch "Simple Tag & Classic Tag handler mock exam question - what New topic
Author

Simple Tag & Classic Tag handler mock exam question - what's YOUR answer?

Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi,

I've another nice mock exam question and like to see YOUR answers and explanations:


Given a tag, simpleTag, whose handler is implemented using the Simple tag model and a tag, complexTag, whose handler is implemented using the Classic tag model. Both tags are declared to be non-empty and non-tagdependant in the TLD.

Which JSP code snippets are valid uses of these tag?

[B]

[/B]


Regards,
Darya


SCJP, SCJD, SCWCD, SCBCD
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Come on, aren't we here to solve questions like this one . I mean that one could be on the real exam .

Regards,
Darya
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi all,

Is that question too hard .

Regards,
Darya
B.Sathish
Ranch Hand

Joined: Aug 18, 2005
Posts: 372
Hi Darya,
For this question, the answer given by the book is right and thankfully, not on the erratta too. A and C are right. B and D are wrong as simple tags cannot have scripting bodies. In C, the source of the HTML would be copied into the body prior to translation. As the body of a HTML cannot contain scripting, it is valid.

Nobody answered this bcos I think it's too simple...
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi B Sathish,

ok , but I hope you agree with me that C is darn tricky .

Regards,
Darya
B.Sathish
Ranch Hand

Joined: Aug 18, 2005
Posts: 372
Can we make it trickier?

Assume that the simpleTag'g body content is declared as scriptless in TLD and the complexTag's body-content is tagdependent. Is D valid or invalid?

Don't ask me the answer
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi,

very good question, I would say that D is invalid , because simpleTag's child element (complexTag) contains scriptlet.

OK, what's your answer , please with a nice explanation

Regards,
Darya
B.Sathish
Ranch Hand

Joined: Aug 18, 2005
Posts: 372
I asked you not to ask me the answer I think what you said is right. But I still have a doubt. As the body is actually present in the inner tag and body-content is declared as tagdependent for that tag, it would be treated as just template text. Not really sure. Hope not to see such questions on the exam
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
I wouldn't be surprised when such type of question come in the exam :roll:

Regards,
Darya
Priya Jothi
Ranch Hand

Joined: Jul 13, 2004
Posts: 168
Hi Darya,

Referring to the question you posted,I dont get how option C is correct?.Could u explain me on this?.

Thanks,
Priya.
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi Priya,

the trick is that you can place a directive whereever you want in a JSP file.

One can think that if the body content should be non-empty AND non-tagdependant then it must be scriptless.

Scriptless means:

  • no scriptlets ( <% ... %> )
  • no scriptlet expressions ( <%= ... %> )
  • no scriptlet declarations ( <%! ... %> )


  • Directives like <%@ include ... %> however are not one of above and can be everywhere in your JSP page. You could have put the directive in front of C's <my:simpleTag> line. But because the directive is embedded in C and the fact of the %s one can easily go into this trap like myself

    Regards,
    Darya
    Paolo Metafune
    Ranch Hand

    Joined: Aug 22, 2005
    Posts: 34
    I run your tricker question with "simpleTag" scriptless and "complexTag" tagdependent.

    The following code works and nothing is written to the output

    <myS:simpleTag>
    <myS:complexTag>
    <% out.println("OK"); %>
    </myS:complexTag>
    </myS:simpleTag>

    So it is a valid use of your tags with this body-content.

    Bye.
    Darya Akbari
    Ranch Hand

    Joined: Aug 21, 2004
    Posts: 1855
    Hi Paolo,

    you mean that D is valid ? Can you post your TLD files here, so we all can see how it looks?

    Regards,
    Darya
    [ September 13, 2005: Message edited by: Darya Akbari ]
    Darya Akbari
    Ranch Hand

    Joined: Aug 21, 2004
    Posts: 1855
    Good input Paolo , I actually did test it also and I have to agree with you.

    The scenario Sathish came up with would be D is valid.

    And this would be the TLD:



    I like these kind of variations

    Regards,
    Darya
    Paolo Metafune
    Ranch Hand

    Joined: Aug 22, 2005
    Posts: 34
    Darya,
    my tld is the same.

    Bye.
    B.Sathish
    Ranch Hand

    Joined: Aug 18, 2005
    Posts: 372
    Darya and Paolo,
    Before confirming that this works, can we actually run the body and see?
    ie in the outer tag's doTag() method, just put a getJspBody().invoke(null). This would run the body. And then, in the classic tag's doStartTag() method, return an EVAL_BODY_INCLUDE. Let' see whether the entire scriptlet get's printed out to the response.

    Just want to make sure that no run-time exception is thrown
    Darya Akbari
    Ranch Hand

    Joined: Aug 21, 2004
    Posts: 1855
    Hi Sathish,

    I tested it as you supposed and receive the same result like before .

    Look to the code below:





    Regards,
    Darya
    Darya Akbari
    Ranch Hand

    Joined: Aug 21, 2004
    Posts: 1855
    So in Sathish's scenario D is still valid .

    Regards,
    Darya
    Paolo Metafune
    Ranch Hand

    Joined: Aug 22, 2005
    Posts: 34
    I wanted only to add that in my code
    *********************
    <myS:simpleTag>
    <myS:complexTag>
    <% out.println("OK"); %>
    </myS:complexTag>
    </myS:simpleTag>
    **********************
    nothing is displayed in the browser page because the engine doesn't evaluate the body of complex tag( because tagdependent) and sends it as it is to the browser that can't interpret it. So you see the string
    "<% out.println("OK"); %>" in the source of html page but not in the page.

    Bye
    Alec Lee
    Ranch Hand

    Joined: Jan 28, 2004
    Posts: 569
    What about if <my:complexTag> is made <body-content>JSP</body-content>. Classic tag handler CAN have scriptlet (yes, definitely can, if you look at the tld of Tomcat's JSTL implementation, they are all declared JSP and are using classic handler).

    I tested it and found that when classic tag handler is nested inside simple tag handler it suddenly cannot have scriptlet. I dont understand why!!!
    Darya Akbari
    Ranch Hand

    Joined: Aug 21, 2004
    Posts: 1855
    Hi Alec,

    I'll look tomorrow in it.

    Regards,
    Darya
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Simple Tag & Classic Tag handler mock exam question - what's YOUR answer?