• 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

HashSet and the empty operator

 
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all
i am having a HashSet object as the request attribute.
All i need is to display the values it hold. which i need to do using JSTL.

TO check whether its empty or not i used something like ${empty objHashSet}
but it didn't return true even when the objHashSet is empty...

i donno where i made mistake. any clue....

[ July 11, 2006: Message edited by: Parameswaran Thangavel ]
[ July 11, 2006: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67750
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
Why did you change your subject from one that was perfectly appropriate to one that was nonsense?

I've changed it back to something that makes sense.
 
Bear Bibeault
Sheriff
Posts: 67750
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
My own observations do not support your findings.

The test page:



yeilds:

Is aMap empty? true

Is aSet empty? true

 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
bear,
when i tried the following


i am getting following

is aList empty : true
is aSet empty : true
is aMap empty : true
is PubTrans empty : false // pubTrans is empty
is Non-PubTrans empty : false

pubTrans which is in request scope is empty (which i checked by printing it on the page), but the result it printed is false i donno why???

And also the code below resulted as true....


will setting the object in request scope and retrieving it change their behaviours.......
 
Bear Bibeault
Sheriff
Posts: 67750
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

Originally posted by Parameswaran Thangavel:

will setting the object in request scope and retrieving it change their behaviours.......



No.

I have no idea what pubTrans is or how it got set up, so I can't say why you are getting the behavior that you are. You can see from the "aSet test" that empty works as expected when an empty HashSet is tested.
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i doubt the way the pubTrans got populated has to do with this bizzare behaviour. bcoz the below lines says it is empty. true is printed in console.


To have more understanding i pasted the code snippet of how the pubTrans and noPubTrans get populated....




i am creating two HashSet object and based on the boolean values returned by
reprocessHelper.publish(pubDetails); i am adding object to one of the hashset. in my case, pubTrans is not populated at all...
 
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
Try to explicitly look into the request scope :
${empty requestScope.pubTrans}

I'm wondering if you have another pubTrans variable already set in the page scope.
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nope. there is no ohter pubTrans variable available.

And also when i tried the below


the following is displayed in the page.
PubTrans: []
Non-PubTrans: [com.cccis.interfaces.iatpa.reprocess.dataobj.ReprocessResults@2af631, com.cccis.interfaces.iatpa.reprocess.dataobj.ReprocessResults@1ff0777]

but when i tried

it returns false...
 
Christophe Verré
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
Which web container are you using ?
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
weblogic server 8.1
 
Christophe Verré
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
You're using JSTL 1.0. right ?
I'm not sure how empty works with collections...
 
Christophe Verré
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
I've just looked at the implementation of JSTL 1.0 by jakarta's taglib:
It checks for null, "", Array, List and Map.
All other collections(like HashSet) will return false.

I can't see this behaviour specified in the spec...
 
Christophe Verré
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
Oh, found it in the spec:

A.3.8 Empty Operator - empty A
The empty operator is a prefix operator that can be used to determine if a value is
null or empty.
To evaluate empty A
If A is null, return true,
Otherwise, if A is the empty string, then return true.
Otherwise, if A is an empty array, then return true.
Otherwise, if A is an empty Map, return true
Otherwise, if A is an empty List, return true,
Otherwise return false.
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all
i got the problem hashSet is not supported for ${empty objHashSet}.

But i am surprised how Bear got "Is aSet empty? true".
is this has to do with any version problem. but empty is supported for ArrayList and HashMap,not for HashSet why it is so???


Posted by Bear

My own observations do not support your findings.

The test page:

code:

<%
request.setAttribute( "aMap", new java.util.HashMap() );
request.setAttribute( "aSet", new java.util.HashSet() );
%>
<html>
<body>
<p>Is aMap empty? ${empty aMap}</p>
<p>Is aSet empty? ${empty aSet}</p>
</body>
</html>





yeilds:

quote:Is aMap empty? true

Is aSet empty? true

--------------------
 
Christophe Verré
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
First, look at your sample:

You've written aList instead of aSet !

About Bear's result, he is probably using JSP2.0, which supports all type of Collection.
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Satou
Thanks for your effort.
 
Don't listen to Steve. Just read 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