aspose file tools*
The moose likes Struts and the fly likes spaces while populating using s:iterator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "spaces while populating using s:iterator" Watch "spaces while populating using s:iterator" New topic
Author

spaces while populating using s:iterator

Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
I am populating an ArrayList in a select(<select>) tag using s:iterator but when it is populated there is gap between each item in the list...

why is that so? I even tried trimming the values before they are added to ArrayList...

The output looks like...


-----------------------
apple

guava

mango
-----------------------

instead of...

----------------
apple
guava
mango
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9304
    
  17

I think we'll need to see the code to know the problem. The s:select tag allows you to directly specify an iterable source which would be used to generate the select tag (with options inside) automatically...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
I used the simple select tag...

This is the code...

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Where are you seeing the newlines again?
M Turner
Greenhorn

Joined: Dec 16, 2009
Posts: 25
I think that whitespace exists where <s: tags /> used to be. Therefore, if you populate your <select> using the <s:select /> itself instead of the iterator your problem may be solved.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm still confused. If the whitespaces are in the emitted HTML, who cares? If there are empty option elements, then something's broken, because I'm not sure how they could be generated from the code posted.
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
I'm not sure how they could be generated from the code posted.


which is very strange... The problem still persists and I can't use s:select as it would disturb my UI alignment !!!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Not if you used the "simple" theme.

You still haven't explained *where* the spaces are coming. If it's just in the HTML, then it doesn't matter.
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
It's just in the HTML...

but the gap is of the size of the item in the list,so, a user can actually select the space between the two items which looks odd and also if there are 10 items, the list a 19 item drop down,( 9 spaces between 10 items)so it sort of hampers the UI display!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Are you *sure* the list contains what you think it does? It's just not possible for the iterator tag to include objects that aren't in the list.

Note, by the way, that this would be more canonical as:But if you're seeing blank *options*, then it's not "just" in the HTML--it means there are items in the list that aren't displaying.
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
But if you're seeing blank *options*, then it's not "just" in the HTML--it means there are items in the list that aren't displaying.


I tried to populate just 2 items say A,B

This is how the dropdown looks like....

-------------
A


B
-------------

instead of ...

--------------
A
B
--------------

may be it's silly but I am unable to solve this one...what else should be the culprit?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Post the rendered HTML.

A broken list is the only other option: iterator can't iterate over list items that aren't there.
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
Well I can sense a strange thing now...

First up I have an arrayList that contains values...

I am filtering these values by eliminating duplicates and putting them in another ArrayList...


In the above case,the following code would give more clarity...





The output...
-----------------

The conList is :--> [c1, c5, c1, c5]
j is :--> 0
j is :--> 1
The conValues set is :--> c1
The conValues set is :--> c5
The conValues is :--> [c1, c5]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

If there are only two items in the list then the JSP you posted cannot create empty option elements: all the iterator tag does is loop over the collection and run the body of the tag for each element.

Post the rendered HTML, along with the current JSP code.
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
Hey David ...thanks for your patient replies...


It is very frustrating though...you mean this should do?

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

No, the HTML rendered by the iterator tag--the part you're having a problem with.
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
I didn't get that...



Now where should be 'post' inserted??
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

*sigh*

Are you, or are you not, having an issue with your collection and/or iterator tag?
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
yes, I do, but i don't how and where to post the rendered html which you suggested! kindly clarify..
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Post it here. Post it by copying and pasting it from the "view source" of your browser. Put it in code tags and disable HTML.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

Just do a View Source in the browser! Sheesh.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
Whoa! that is some comfusion...I thought I need to "Post" the value somewhere...well,well,here it goes, a bit long and the part to be noticed lurks in the middle...

There are two tabpanels both having same structure and so is for select...

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617



No, the ***rendered*** output of the iterator tag--the part you're having the problem with.

"Rendered" means the stuff handed back to the browser, which is why both Bear and I referenced the "view source" thing.
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
Well, here it is...

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

I give up.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9304
    
  17

Bow down to David's patience

Pradeep, the source that you showed us is of the code that you wrote. Now you open that page in the browser and you get some unusual option elements right. Now when you open the page in the browser, depending upon the browser, do the following
If you are using firefox, go to View menu and there's an option called "Page Source", click on that
If you are using Internet Explorer, go to the View menu and there's an option called "Source", click on that

In both cases you'll see the HTML that the browser got from the server. Copy that HTML and post it here...
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336


Well,I looked foolish there,but here it is...



Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9304
    
  17



At both places you have an opening <option> tag instead of a closing </option> tag...
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
phew! that was one frivolous thing. Mother of all silliest things went on to become most important thread...yeah dats done and dusted.

Thank you all for those patient replies...

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

*lol* Good thing Ankit has sharper eyes than I do ;)

For future reference, when we ask for rendered HTML we usually just mean the parts you're having a problem with, not the entire page.
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
aye aye Sir! Kindly check my other queries...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: spaces while populating using s:iterator