Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem regarding JSTL remove tag  RSS feed

 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I'v made a code for demo of remove tag of JSTL.

Output of the above code is-
userstatus is : Brilliant
userstatus is now : Brilliant

The output which I expect is-
userstatus is : Brilliant
userstatus is now : not available

In this JSP page, previously scope of var is set as application and im removing is from page scope. So shouldn't it be removed from the current page? Why is has not been removed?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65891
135
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you put something in one box, and try to remove it from a different box, does it disappear from the first box? Of course not.

If you want to remove it from app scope, you need to specify app scope on the remove action. It's not in page scope, so you can't remove it from somewhere where it does not exist.

 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but if something is in application scope, that means that field is visible in whole application. So, shouldn't it in page scope also? and in this code, im trying to remove it from that particular page.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65891
135
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, that's no the way it works.

Things in app scope aren't copied to page scope. The page sees the page, request, session and app scopes, and hence sees all the scoped variables in those scopes.

Think of them as four separate boxes that the page can see. You can't remove an item from a box that that item is not in.
 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah..i was taking it as a hierarchy of scopes. Now its clear to me...thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65891
135
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it is a hierarchy of scopes. But your mistake was in thinking that app scoped wear shared with a page by somehow copying the values into page scope. Not so.

When a scoped variable is referenced, first page scope is searched, and if the variable is not found there, request scope is searched, then session scope, then app scope.
 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok...thanks Bear Bibeault
now one last question. if these scopes make a hierarchy, than we should consider these scopes like separate boxes or like small box page contained inside a bigger box request which is contained inside bigger box session again which is inside the bigger one application?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65891
135
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The scopes do not contain each other. The hierarchy defines the search order for references.
 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it. thankyou
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!