• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BodyTagSupport + EVAL_BODY_BUFFERED + tag hierarchy

 
Łukasz Suchecki
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm confused.
In few places it was said that tag based on BodyTagSupport is not able to process it's body (with body-content tagdependent and EVAL_BODY_BUFFERED in doStartTag)
And now imagine:
<t:outer>
<t:inner/>
</t:outer>

Both for them are BodyTagSupport tags.
Is it possible from inner tag to get outer tag by calling getParent() ? Or while tagdependent body of outer tag the inner is "not fired" (it's treated like simple text).

And maybe second quick question:
- in Head First it's told that it's impossible to get outer tag from inner tag if inner is classic tag, and outer is simple tag. But one of entruware questions claims, that we can get from inner to outer by simply calling getParent(). So how is it ?
 
Keith Flo
Ranch Hand
Posts: 128
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Łukasz,

The Tag interface (for classic tags) and SimpleTag (for simple tags) only supply a getParent() method! There is no 'getChild() method or something like that. So inside t:inner you can call getParent() and get the parent touter. Not the other way around! Once you have a reference to the parent you call methods on it or whatever. Also, Tag getParent() returns a 'Tag' and SimpleTag getParent() returns a JspTag which is why classic tags which implement Tag cannot have SimpleTag parents and SimpleTags can have either.

'tagdependent' means that EL expressions, scripting and Tags are not evaluated (see p. 508 in K&B)

 
Łukasz Suchecki
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Yes, I know that I cant get child's list and it was not mentioned in the question.

So examples from enthruware question (com.enthuware.ets.scwcd.v5.2.473):

Answers with explanation:
(wrong) MiddleTag can get a reference to OuterTag by calling TagSupport.findAncestorWithClass(this, OuterTag.class).
Since OuterTag is a SimpleTag, MiddleTag will not find the OuterTag's instance by passing OuterTag.class. It should pass TagAdapter.class instead.
(right) MiddleTag can get a reference to OuterTag by calling TagSupport.getParent() method.
(wrong) InnerTag can get a reference to OuterTag by calling TagSupport.findAncestorWithClass(this, OuterTag.class) method.
Note that the body-content of MiddleTag is "tagdependent". Therefore, InnerTag will never be executed.

So we can get from classic tag parent which is simple tag (answers 1 & 2) !!
And it means that tagdependent body is not evaluated ... (and not only scpritlets and EL are treated like text, but tag are also treated like text, and tags arent really tags but text body)

Am I right, or answers are wrong ?

ps.
I don't trust in 100% in books (Head First for example). They have lots of mistakes. For example in head first it was said few times, that in taglib directive uri it's just a name and it has nothing with file location. But when you read specs there is one sentence which tells that if uri is not found (in taglib.taglib-uri in web.xml or in any tld file know to the container) that the container is trying to use the uri from directive as PATH to the tld file. 1:0 in spec vs. Head First
 
Keith Flo
Ranch Hand
Posts: 128
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The issue seems to be are the Enthuware answers and explanations correct? Is that so? Have you included the entire question? It seems like some pieces are missing?

... Ok ..

First, Can a classic tag have a SimpleTag parent? No! A classic tag's getParent() method returns a Tag instance. Simple tags do not implement the Tag interface!

Second ...
not only scpritlets and EL are treated like text, but tag are also treated like text, and tags arent really tags but text body

You're right! ... 'tagdependent' means that the container will not evaluate the the body content but rather pass it along as text to your tag handler.

Next ...
I don't trust in 100% in books (Head First for example).
... Yeah ... nobody's perfect ... but what can you trust in 100%??? Books have errata, containers don't fully conform to the specs, software has bugs ... people make mistakes! The bottom line is this ... the K&B book - Head first Servlets and JSP is excellent and about 98% of the time .. IMHO .. its correct.

Lastly ...
uri it's just a name and it has nothing with file location
.. You're right ... Ive noticed this too! In fact content assist in Eclipse suggests using a relative file location. However, using it as 'just a name' works in Tomcat and agrees with the spec. So K&B is not wrong when it says this.



 
Łukasz Suchecki
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Tnx for answers and sorry for so long time between my answers.
Yes - enthruware answers and their explains made me confused.
1. Hmmm. They can. And we can get reference of parents. But we cant execute anything in parents (call getParent(), or .findAncestorWithClass(this, TagAdapter.class) works fine, but we cant cast it to real tag class)
2. Great, I was worried that there is something that I dont understand
3. I have papers version without errata ;) And from book based answers I prefer experienced or JSR (spec) based answers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic