• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

How to remove Bean?

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
How do you remove Bean or map from requestScope ?

If it is a simple variable , We can remove it using

<c:remove var="choice" scope="request"/>

If it is a bean myBean in request scope , I can not use

<c:remove var="${mybean}" scope="request"/>
because var can not take EL expressions .

Any ideas on how I can remove attribute/bean from a given scope ?

Thanks
Akhil
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi !!!

If your bean is a request attribute, it as an id.
If you a request attribute with:

<jsp:useBean id="arrayList" class="java.util.ArrayList" scope="request" />

You can remove it with:

<c:remove var="arrayList" scope="reuest" />

The var attribute MUST be a string litteral. It can't be an expression.
 
Akhil Maharaj
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
your solution seems to be working. However when I check for empty , it is not giving the expected result .

Can you explain what I am missing ? Why I don't see " variable myPerson is gone" in the output ?

Thanks
Akhil

 
Collins Mbianda
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The empty operator is a prefix operation that can be used to determine
whether a value is null or empty.


${empty pageScope.myPerson} will return false because "myPerson" does not exist the request scope since you have removed it.

I think you want to test if the bean still exist in the request scope.
You can try to print it by:
<c ut value='${pageContext.myPerson}'/>

You will have message like:"myPerson does not exist in any scope"

Hope it help.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>Akhil

Why I don't see " variable myPerson is gone" in the output ?


Are you sure it is not ?

>Collins

The empty operator is a prefix operation that can be used to determine whether a value is null or empty. ${empty pageScope.myPerson} will return false because "myPerson" does not exist the request scope since you have removed it.


Aren't you contradicting yourself ? If myPerson is null, empty will return true.
 
Collins Mbianda
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Christophe Verre:
>Collins
...
Aren't you contradicting yourself ? If myPerson is null, empty will return true.



Yes Christophe, I'm contradicting myself. If myPerson is null will return null. Thanks !!!
 
Akhil Maharaj
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

It is working now . I have had my code with unclosed </br

I think thats is what caused the problem . Thanks to both of you .
Akhil
 
I've been selected to go to the moon! All thanks to this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic