• Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt in question number 13 in page.555?  RSS feed

 
Jessica James
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..
The question is:
10.public class ExampleTag extends TagSupport{
11.private String param;
12.public void setParam(String p){param=p;}
13.public int doStartTag() throws JspException{
14.//insert code here
15.//more code here
16.}
17.}

which, inserted at line 14, would be guaranteed to assign the value of the request-scoped attribute param to the local variable p?(Choose all that apply)

A. String p=findAttribute("param)

and there is some other options..

I want to know why option A is wrong..

Thanks in advance..
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A. String p=findAttribute("param)

Is this really the answer ? Where does findAttribute() come from ?
 
Jessica James
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this really the answer ? Where does findAttribute() come from ?


findAttribute(String) is one of the method in the JspContext..

why can't we use it?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But it should be something like
String p = ctx.findAttribute("param"), shouldn't it ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually it should look like :
 
Jessica James
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok.. Thanks..
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am I right if I say that even the following code



will not be guaranteed to assign the value of the request-scoped attribute param to the local variable p?

It could find a page-coped attribute with the same name.

[ March 23, 2007: Message edited by: Sergio Tridente ]
[ March 23, 2007: Message edited by: Sergio Tridente ]
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it will start by looking from page and as soon as it finds attribute in any scope it stops there.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!