• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JSTL - c:remove doubt

 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your info...
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
https://coderanch.com/forums/
 
Rizwan Mohammad
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
What's wrong? Where are you going? Stop! Read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic