Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Classic Tag's

 
Amandeep Singh
Ranch Hand
Posts: 850
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given:

<%@ taglib uri="example" prefix="example" %>
<example:aTagWithBody>
<%="Body Content"%>
</example:aTagWithBody>

If the aTagWithBody handler extends from TagSupport and returns BodyTag.EVAL_BODY_BUFFERED from doStartTag(), what will the above page print?

1)The tag handler class would not compile.

2)An exception at request time.

3)"Body Content" will NOT be printied.

4)"Body Content" will be printied.

5)None of these.

this is from enthuware, the correct answer given is 2.

But according to me the correct asnwer should be 1.

The reason given for 1 answer is It will, because the compiler only checks whether the doStartTag() is returning an int or not. It does not check whether the int value is valid or not.

In this forum some day's back i had ask the question similar to this. All post's told me that time, the compiler do comaplain's about whether the int value is valid or not.

Please advice.
 
kurt hanni
Ranch Hand
Posts: 140
Eclipse IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will compile as long as you return an int,

the answer "an exception at request time" is not clear as this behavior depends on the container.

I tried this code in tomcat, it compiled and no exception was thrown.
 
Amandeep Singh
Ranch Hand
Posts: 850
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey Rancher's i got this question from Enthuware.

Consider the following JSP code:

<mylib:MyIterTag>
<%="Hello World"%>
</mylib:MyIterTag>

If the tag handler class for MyIterTag implements IterationTag and returns IterationTag.EVAL_BODY_BUFFERED from doStartTag(), what will be output in the response?

1)Hello World

2)<%="Hello World"%>

3)The tag handler will not compile.

4)The tag handler will compile but throw an exception at request time.

5)No compile-time or run-time erros and nothing will be printed in the output.

Here the correct answer given is 3.
And the reason given is Because EVAL_BODY_BUFFERED is defined in BodyTag and not in IterationTag!.

So if we compare this answer's real reason to the above question in this post, it is different. Here the compiler will check who is returning the int value.

But in the above first question in this post, the compiler will check only as far as the int value is returned or not.

This is real strange. Please clear my this doucbt as i am going to have exam on Sept2.

Please advise. I will appreciate help.
 
kurt hanni
Ranch Hand
Posts: 140
Eclipse IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because in the above code it says "BodyTag.EVAL_BODY_BUFFERED" this returns an int, so it is valid.

in the second question it says "IterationTag.EVAL_BODY_BUFFERED", there is no "EVAL_BODY_BUFFERED" constant in IterationTag interface, this will not compile because you are accessing an undefined variable.

[ August 31, 2008: Message edited by: kurt hanni ]
[ August 31, 2008: Message edited by: kurt hanni ]
 
Amandeep Singh
Ranch Hand
Posts: 850
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got it Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic