• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Taghandler doubt

 
Brijesh shah
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers;

What would be the answer of following question

Given the following tag handler defined with <bodycontent>JSP</bodycontent>

public class body extends TagSupport {
public int doStartTag() throws JspException{
return EVAL_BODY_INCLUDE;
}
public int doAfterBody() throws JspException {
try { pageContext.getOut().print("how are you?"); }catch(IOException e) {}
return SKIP_BODY;
}
}

what will be printed out by the following part of a jsp page?
<prefix:sufix>
<i>Hello</i>
</prefix:sufix>

1) The tag handler won't compile.
2) The jsp page will print Hello how are you?
3) The jsp page will print how are you? Hello
4) The jsp page will print Hello

In above Answer given as 4
But i think answer should be 2..

Would appreciate if somebody explain me with the correct answer for the same..

Thanks & Regards;
Brijesh
 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I think it should throw an exception, because <body-content>JSP</body-content>
is available for Simple tags and not for classic tags so when you compile the tag handler class it will compile,the jsp gets translated fine,but when it tries to evaluate the tag it should give an exception.

Please correct me if i am wrong.

Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it should throw an exception, because <body-content>JSP</body-content> is available for Simple tags and not for classic tags

It's the opposite A body-content of JSP is valid for custom tags only, so no problem here.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And yes, I agree that the answer should be 2.
 
Sarat Koduri
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
brijesh.. i think you are right.. the answer should be 2.. may be its by mistake they printed 4 as answer..
 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, It works fine with out any problem. In HFSJ we have only empty,scriptless,tagdependent for Classic tags, When it comes to Simple Tags in addition to above three we also have Jsp, But in this code Jsp option also works fine why is it so. Is that means for both Simple and Classic tags we can use any of the 4 entries.

Thanks
[ October 03, 2008: Message edited by: raja ram ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In HFSJ we have only empty,scriptless,tagdependent for Classic tags

Check again (or check this), and tell us which page you've read it.
 
Sarat Koduri
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

As the discussion came up here.. need to clarify one thing related to the link Christophe has given. The link says
Tag Files body content
does this mean <%@ tag %> directvie are you talking about? or Actual Tag files body you are talking about?.

Beacause i am sure the body of an actual Tag file can have script and it is true as per the HFSJ second edition page no:534 question no:2.


i guess you should say it is tag directive isn't it?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
About Tag Files (which is not what is discussed in this thread ), it refers to the tag directive of the tag file (JSP.8.5.1 The tag Directive).
Syntax : { body-content=�scriptless|tagdependent|empty� }

body-content (optional) : Provides information on the content of the body of this tag. Can be either empty, tagdependent, or scriptless. A translation error will result if JSP or any other value is used. Defaults to scriptless.

What HFSJ says is probably that there may be some script in the tag file (in the .tag file itself). But there won't be script in the body of the tag, in the JSP page where the tag is used.
 
Sarat Koduri
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes.. yes.. i got that one.. just to make sure i am on the right track..
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see I've changed the FAQ to make it less obscure.
 
Sarat Koduri
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aaahh.. Thanks a lot Christophe.. now the faq looks pretty cool..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic