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

Which one to select between Classic custom tag and Simple custom tag

 
sudhakar karnati
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a question from Enthuware:
You are creating a tag called SmartInputTag to replace the HTML <input> tag. If the request contains a value for a given parameter, this tag automatically puts that value in the input tag for that parameter. This tag is useful when the same form is redisplayed to the user if it fails validation. For example, if the user has already input 28 as the value of "age" parameter, your SmartInputTag will generate the following outout:

<input type="text" name="age" value="28" />

Which of the following is an appropriate tag handler method to achieve this?


a)

b)

c)

d)

Which option would you select?

I selected answer as (b) but the answer given is (d)

Any idea on why option b could be wrong?

Thanks & Regards
Sudhakar Karnati
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void doStartTag() ?
 
sudhakar karnati
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void doStartTag() ?


Thanks Christophe Verre,

Now i understood.I hope i wont do these kind of silly mistakes in the exam..
 
Anand Bhatt
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct option is d.
How can you say option c:
It will give you compile time error as:
1: retun type of diStartTag is an int not void.
2: getJspContext() not defined in any classic tag handler API.
This methid is indeed defined in SimpleTag API.
Hope this is clear your doubt?
 
Amandeep Singh
Ranch Hand
Posts: 850
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer given by Veere is wrong becuase doTag method
always throws two exceptions JspException and IOException..
But here it is throwing only one exception.

So correct answer is b.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer given by Veere is wrong

Are you saying that doStartTag is a void method ?

So correct answer is b.

Go back to the API and check doStartTag's signature.

So correct answer is b.

Please send us a link to the API you are referring to.
 
Amandeep Singh
Ranch Hand
Posts: 850
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok there is problem in both answers a and d.


1) In answer b, the return type is void for doStartTag(), should be int. It is throwing one exception that is right.

2) In answer d, the return type is void for doTag() is right, but is throwing only 1 exception. It should throw two exceptions as JspException and IOException.(Alothough it is catching the IOException.)
 
Praveen Sharma
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amandeep,
Option d is correct. We can use the throws clause if we dont want to handle the exception in the same method. Either ways it is our choice. Either we can put the exception type in the throws clause or catch it in the same method.
 
Amandeep Singh
Ranch Hand
Posts: 850
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Deepak and Veere for their replies.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic