• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to remove Bean?

 
Akhil Maharaj
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • 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
 
Collins Mbianda
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • 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
  • 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: 260
  • Mark post as helpful
  • send pies
  • 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.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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: 260
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic