Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Parents of Simple - Classic tags

 
Greenhorn
Posts: 11
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Studying the excellent Head First Servlets and JSP book and am having a little trouble with one of the Coffee Cram questions...

Chaper 10 Custom Tag Development
Mock Exam Chapter 10

Question 17

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 in the TLD.

Which JSP code snippets are valid uses of this tag? (Choose all that apply)

A. <my:simpleTag>
<my:complexTag />
</my:simpleTag>


B. <my:simpleTag>
<%= displayText %>
</my:simpleTag>

C. <my:simpleTag>
<%@ include file="/WEB-INF/web/common/headerMenu.html" %>
</my:simpleTag>

D. <my:simpleTag>
<my:complexTag>
<% i++; %>
</my:complexTag>
</my:simpleTag>

----------------------------------------
A and C are correct.

Option A seems to be a classic tag with a simple parent.
Page 540 of the text leads off with the bold title:
"Simple tags can have Classic parents"
before going onto explain that using the getParent() method a classic tag can access classic tag parents and a simple tag can access either a classic or simple parent.

Should A be incorrect as it's a classic tag with a simple parent?
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A is correct, because Simple Tags can have in their body, Classic Tags as long as the Classic Tags don't have any scriptlets... (as explained in answers for that option in 2nd ed. book)

And by my understanding, Simple Tags can have Simple or Classic Tag as a parent and vice versa...
But it is while getting the reference to the parent tag using getParent() method where the issue arises.
( That SimpleTags can use the getParent() method to get the reference of either a SimpleTag or a Classic Tag and Classic Tag can use the getParent() to access only Classic Tag parents)
 
Paul Bartels
Greenhorn
Posts: 11
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. Understood.

So,ClassicTags can have either parent (without using the TagAdapter class), as long as they don't interact - specifically, that getParent() or maybe findAncestorWithThisClass() isn't used.

Thanks a lot!
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The body-content is defined as non-tagdependent that means we can have scriplets, EL and tags allowed. I am confused!
Please help.
 
namita sasa
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please let me know the correct answer. HFSJ says that tagdependent means body would be treated as plain text. Here body is declared as non-tagdependent i.e. it should allow scriplets and EL?? Then B and D are also correct choices.
 
Paul Bartels
Greenhorn
Posts: 11
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The errata for the first edition states:

Both tags are declared to be non-empty in the TLD.
should read:
Both tags are declared to be non-empty and non-tag dependent in the TLD.
 
Greenhorn
Posts: 17
jQuery PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

namita sasa wrote:The body-content is defined as non-tagdependent that means we can have scriplets, EL and tags allowed. I am confused!
Please help.



Not sure what your question is.
 
namita sasa
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am confused about the meaning of non-tag dependent. Does it mean that scriplets and EL and tags are allowed?
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tagdependent means no EL ,no scriplet only plain text

correct me if i am wrong
 
namita sasa
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That means non-tag dependent indicates scriplets, EL, tags allowed if tagdependent means no scriplets, no EL, no tags??
 
rachna jain
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes it should be as per my understanding it would be gud if you can share a question where it is used.
 
rachna jain
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops.........

are you refering question 17 on page 587

yes in this question i think its little tricky as simple tags never have scriplets or we can say simple tags dnt have JSP(tagdependent ) body

so option B,D is wrong and scrptless can have EMPTY BODY so A is write
 
namita sasa
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is regarding same question Chaper 10 Custom Tag Development
Mock Exam Chapter 10 , Question 17. Paul who started this topic mentioned that the choces are A and C. My question is why not B and C also valid?
 
namita sasa
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again Rachana. I did not know about that point. I saw one more thread which explained about that. Now it is clear. Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic