• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

 
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Is that question too hard .

Regards,
Darya
 
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi B Sathish,

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

Regards,
Darya
 
B.Sathish
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wouldn't be surprised when such type of question come in the exam :roll:

Regards,
Darya
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
     
    Ranch Hand
    Posts: 34
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 1855
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 1855
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 34
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Darya,
    my tld is the same.

    Bye.
     
    B.Sathish
    Ranch Hand
    Posts: 372
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 1855
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 1855
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    So in Sathish's scenario D is still valid .

    Regards,
    Darya
     
    Paolo Metafune
    Ranch Hand
    Posts: 34
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
     
    Ranch Hand
    Posts: 569
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 1855
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Alec,

    I'll look tomorrow in it.

    Regards,
    Darya
     
    reply
      Bookmark Topic Watch Topic
    • New Topic