• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL - c:remove doubt

 
Nicky Eng
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
been given a scoped attribute lita exist only in a user's session. which two, taken independently, ensure the scoped attribute lita is no longer exist ? (choose 2)

A. <c:remove var="${lita}" />
B. <c:remove var="lita" scope="session" />
C. <c:remove scope="session" > ${lita} </c:remove>
D. <c:remove var="lita" />

my answer would be B and D.

A. would be wrong because inside var attribute must be String literal. it cannot be an expression(according to page 448, HFSJ).

C. i'm not sure about having a body inside <c:remove> .

what do you guys think?? give some opinion please
 
Rizwan Mohammad
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick, you are absolutely correct.
B & D are correct answers.
look at tld about remove tag.
it is the only core jstl tag, which has body-content as empty.
you cannot have body inside remove tag. so 'c' is wrong.
you cannot have runtime expression for var inside remove tag.
because, it is declared as rtexprvalue = false.
Also, note that 'var' cannot be run time expression value for any of core jstl tags.
 
Nicky Eng
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your info...
 
Priya Jothi
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys..

I dont think D is the correct answer.Only B is correct.coz in option D scope attribute value defaults to "page" if omitted.Will it remove attribute from Session scope also?.I think it wont.Correct me if am wrong.

Regards,
Priya.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65342
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in option D scope attribute value defaults to "page" if omitted


Incorrect. For the remove tag, omitting the scope removes the variable from all scopes.

Reference: section 4.4 of the JSTL 1.1 Specification
[ October 05, 2005: Message edited by: Bear Bibeault ]
 
Vidya Sethuraman
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Priya,

I think <c:remove var="user"/> will remove all the attributes with the name user in all the scopes.

Please refer to the following java ranch discussion:
http://www.coderanch.com/forums/
 
Rizwan Mohammad
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
To summarize,
According to JSTL spec,
====================(same as jstl spec- copied)================
If attribute scope is not specified, the scoped variable is removed by calling
PageContext.removeAttribute(varName). If attribute scope is specified, the
scoped variable is removed by calling
PageContext.removeAttribute(varName, scope).
============================
According to J2EE spec,
================(same from j2ee api) ============
for pageContext.removeAttribute(String varName)

Remove the object reference associated with the given name from all scopes. Does nothing if there is no such object

for pageContext.removeAttribute(String varName, String scope),

Remove the object reference associated with the specified name in the given scope. Does nothing if there is no such object.

=====================================
To summarize,
<c:remove var="user"/>
if scope is not specified, it removes the value from all scopes.

Hope it is clear.
 
Vasanth Raja.K.
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I think c is wrong because var attribute is required and c:remove can have body-content.
Plz explain if i am wrong.
Reg
Vasanth
 
Rizwan Mohammad
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raja,
you are partially correct.
for <c:remove> tag, var attribute is mandatory, but it cannot have body-content, in tld it is defined as empty.
 
Nicky Eng
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
great details, Rizwan.

i postpone my test day to next week cos this weekend i go clubbing.
 
Rizwan Mohammad
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay. All the best Nick. Even I have been postponing for many days as I have heavey work load. But I do write definitely this month some time.
Again, all the best.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic