wood burning stoves 2.0*
The moose likes Struts and the fly likes non-whitespace whitespace Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "non-whitespace whitespace" Watch "non-whitespace whitespace" New topic

non-whitespace whitespace

Craig Ricciuto

Joined: Nov 05, 2009
Posts: 9
The title might be confusing but here's my situation.

I have an ArrayList of String values being set in my action class and then in my JSP I iterate over that list outputting a checkbox and a textfield. All the checkboxes share a name (so their values end up in a list) and all of the textfields also share a name (a different name than from the checkboxes though) whose values end up in a list too.

The list for the checkboxes ONLY includes the selected checkboxes. That's fine. That's what I expect.
My problem is that the list for text fields has an element for EVERY text field (blank fields and filled in fields). This is a problem because my two lists don't match up. One list (the textbox list) is always bigger than the other list (the checkbox list).

I tried looping over the textbox list and doing a check for a space via:
but that didn't work. I tried using the String's trim() method...that didn't get rid of the whitespace so I could just check for a blank String.

So I either need to know what character it is that the textbox returning so I can do a check for that character and just remove it from my list OR find a way to not have blank textboxes get submitted and stored in the list in the first place...or a third option I have not considered.

Thanks for any help.
Craig Ricciuto

Joined: Nov 05, 2009
Posts: 9
Nevermind. I figured out a way I could fix my problem. With a little javascript I just made the textboxes get enabled when it's corresponding checkbox is clicked. Any disabled textbox isn't passed into the list. I set all textboxes to be disabled by default.
jQuery in Action, 2nd edition
subject: non-whitespace whitespace
Similar Threads
Unchanged dynamically created check boxes not in request object.
problem in output format
CastMap getTrimmedString() error?
getParameterValues and TextArea inputs
Data mismatch between two separate lists in a single iterator in struts2