Two Laptop Bag*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Doubts in Mock exam HFSJ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Doubts in Mock exam HFSJ" Watch "Doubts in Mock exam HFSJ" New topic
Author

Doubts in Mock exam HFSJ

sravanthi pulukuri
Ranch Hand

Joined: Mar 15, 2007
Posts: 125
1:Which are valid in tag files? (Choose all that apply.)
A. <jsp:doBody />
B. <jsp:invoke fragment=”frag” />
C. <%@ page import=”java.util.Date” %>
D. <%@ variable name-given=”date”
variable-class=”java.util.Date” %>
E. <%@ attribute name=”name” value=”blank”
type=”java.lang.String” %>

answer is A,B,D

Please help me why D is Correct.

2: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-tag dependent in the TLD.
Which JSP code snippets are valid uses of these 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,C
not very clear why A is correct.
Sourin K. Sen
Ranch Hand

Joined: May 02, 2006
Posts: 86

Hi sravanthi,

1. The variable directive is used to define a scripting variable in the page which invokes this tag file.

The variable directive is analogous to the <variable> element in the Tag Library descriptor, and defines the details of a variable exposed by the tag handler to the calling page.


For example, you define a variable in your tag file, let's say, myTag.tag, like this :
<%@ variable name-given=”date” variable-class=”java.util.Date” %>
And then you invoke it in your jsp :
<tag:mytag>
${date}
</tag:myTag>

So basically, the variable directive is giving you information as to what kind of variable you are going to use and its implementation details.

Well, atleast that's what my idea for the variable tag is. If anyone finds me wrong, please correct me.

2. Option A is an example of nested tags. Tags can be nested within one another. Also, simple tags can be nested within complex tags and complex tags can be nested within simple tags. Although, implementing complex tag nested inside a simple tag is really complex (option A is one such example) as getParent() method of complex tags returns Tag type whereas simple tags dont implement the Tag interface. They implement the JspTag interface. So it does takes a hack to get it work, but the point is, it does works.



Regards,<br />Sourin.
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
1:Which are valid in tag files? (Choose all that apply.)
A. <jsp:doBody />
B. <jsp:invoke fragment=”frag” />
C. <%@ page import=”java.util.Date” %>
D. <%@ variable name-given=”date”
variable-class=”java.util.Date” %>
E. <%@ attribute name=”name” value=”blank”
type=”java.lang.String” %>


answer is A,B,D

hey is somebody noticed the bold line... this is also valid, then why not included in the given options...
it is used to define the attributes for the tag file , just like a <attribute> sub-element of a <tag> element for the tag handler(custom tags).


Am i right?? please correct me if not


Thanks <br />Poonam Agarwal SCWCD 86%
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
For example, you define a variable in your tag file, let's say, myTag.tag, like this :
<%@ variable name-given=”date” variable-class=”java.util.Date” %>
And then you invoke it in your jsp :
<tag:mytag>
${date}
</tag:myTag>

So basically, the variable directive is giving you information as to what kind of variable you are going to use and its implementation details.


hey Sourin,
could you please expain this in more detail. even i have some doubt regarding thee <%@ variable%> directive. I understand that this is used to expose the scripting variable used by the tags in JSP file,
1. But what is need to do so, can't we declare a variable itself in the JSP file.
2. <variable> element and <%@variable%> directive are same. Please give an example to explore this.

Thanks In advance
Poonam
sravanthi pulukuri
Ranch Hand

Joined: Mar 15, 2007
Posts: 125
hi,

regarding the Question 1:

We use Atrribute tag to define inside the tag file.. any Diff between Variable and attribute declaration?/?


<%@ attribute name=”name” value=”blank”
type=”java.lang.String” %> is not the correct one

we only have
<%@ attribute name=”name” required ='true' ,rtexprvalue =''> is the sytax for that.. ignore typo errors


2nd Question iam not justified with the Answers.
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323

I got it guys, this is invalid because of the use of value attribute. which is not allowed by the specs.


Thnaks Guys
Sourin K. Sen
Ranch Hand

Joined: May 02, 2006
Posts: 86
Poonam Agarwal wrote:
hey is somebody noticed the bold line... this is also valid, then why not included in the given options...
it is used to define the attributes for the tag file , just like a <attribute> sub-element of a <tag> element for the tag handler(custom tags).


Its not correct as the attribute directive has got no attribute named "value". It will give translation error.
Sourin K. Sen
Ranch Hand

Joined: May 02, 2006
Posts: 86
Poonam Agarwal wrote:
hey Sourin,
could you please expain this in more detail. even i have some doubt regarding thee <%@ variable%> directive. I understand that this is used to expose the scripting variable used by the tags in JSP file,
1. But what is need to do so, can't we declare a variable itself in the JSP file.
2. <variable> element and <%@variable%> directive are same. Please give an example to explore this.

Thanks In advance
Poonam


1. Well, lets just take the given example, say we need to display this date on many jsp's which, coincidentally also happen to be using the same tag file.
Now instead of declaring this date variable on each and every jsp, just declare it in the tag file and voila, it gets included in all the other jsp's. Well, this is one reason I can think of. Maybe you could think of some more...

2. Do you remember that I had asked a question regarding the <variable> and the <name-from-attribute> tags? Well, obviously even I haven't used these things yet to be able to give an example. I hope someone else on this forum can help us out in this regard. The only thing that I can say for this point is that the directive is used for only the tag files whereas the <variable> element is used for the tag handler classes.

Ranchers, please give us a few examples to make things even more clear...


Sourin K. Sen
Ranch Hand

Joined: May 02, 2006
Posts: 86
sravanthi pulukuri wrote:hi,
2nd Question iam not justified with the Answers.


Well, what can I say, just pick up the Head First Servlets & JSP and read the 10th chapter on "Using Custom tags".
They themselves have mentioned that this can be done via some extra hack.
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
pulukuri,

2: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-tag dependent in the TLD.
Which JSP code snippets are valid uses of these 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,C
not very clear why A is correct

Please read the question once again. it gives you 2 information. that the specify values for the <body-content> element should be
1. JSP
2. scripless (empty and tagdependent is not allowed by the scenario)

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


In this option outer tag <my:simpleTag> enclosed the inner tag <my:complexTag /> which is allowed by specifying
<body-content>JSP</body-content> because JSP can accept any kinds of tags (custom OR standard). so this option is valid one.

I hope this will help
sravanthi pulukuri
Ranch Hand

Joined: Mar 15, 2007
Posts: 125
hi,

Thanks for the reply.

But complex tags is supposed to be non empty rite??
for answer A it is empty tag is it?
Sourin K. Sen
Ranch Hand

Joined: May 02, 2006
Posts: 86
sravanthi pulukuri wrote:hi,

Thanks for the reply.

But complex tags is supposed to be non empty rite??
for answer A it is empty tag is it?


Complex tags are not supposed to be non-empty by default.
You must provide the <body-content> element in the TLD. Its a mandatoryattribute and you cannot leave it. And it is this attribute which defines what kind of a body your tag can have, doesn't matters which tag you are using, whether complex or simple. It is a mandatory attribute for both type of tags.
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
sravanthi pulukuri wrote:hi,

Thanks for the reply.

But complex tags is supposed to be non empty rite??
for answer A it is empty tag is it?


you can specify that your tag handler goona take which type of body like JSP, scriptless, tagdependent, empty.
by specifying empty you can be rest assure that tag handler won't accept anything. Right??
but by specify rest of the tree tags (JSP, scriptless, tagdependent) you can still write your tag in the JSP file without body , that is empty . because rest of all 3 values of <body-content> accept the empty tag as a valid value.

To just add on to your knowledge please refer to HFSJ (2 Edt), chapter no 9, page no 493, question no 5. I hope you will get the idea of possible values and how they behave in different manner.
sravanthi pulukuri
Ranch Hand

Joined: Mar 15, 2007
Posts: 125
hii,

Both tags are declared to be non-empty and non-tag dependent in the TLD.

this is what i mean

<my:simpleTag>
<my:complexTag />
</my:simpleTag then how come this is true.. complextag should have body rite??>
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
sravanthi pulukuri wrote:hii,

Both tags are declared to be non-empty and non-tag dependent in the TLD.

this is what i mean

<my:simpleTag>
<my:complexTag />
</my:simpleTag then how come this is true.. complextag should have body rite??>


again you can design a tag without a body,(by declare <body-content> empty</body-content>) in this case tag body won't accept anything. but if you declare any of the value in the rest of three(tagdependent, JSP, or scriptless), empty tag like <complexTag> in the above example are valid. these types are accept empty tags.
Sourin K. Sen
Ranch Hand

Joined: May 02, 2006
Posts: 86
sravanthi pulukuri wrote:hii,

Both tags are declared to be non-empty and non-tag dependent in the TLD.

this is what i mean

<my:simpleTag>
<my:complexTag />
</my:simpleTag then how come this is true.. complextag should have body rite??>


Simply put, if you declare <body-content> to be something other than empty and you dont give a body for that tag, it will still work and the tag body will not be evaluated. No exception will be thrown. Only the thing is that, setJspBody() method will not be called.

[p.s. : I dont exactly remember the name of the setter method for the tag body. Please correct me if I am wrong]
 
 
subject: Doubts in Mock exam HFSJ
 
Similar Threads
Parents of Simple - Classic tags
HFSJ - Custom Tag Development - Question 17 (Page 567)
HFSJ mock Q
Simple Tag & Classic Tag handler mock exam question - what's YOUR answer?
Doubt in question of HFSJ - Empty Tags