• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using checkbox & textfield together

 
Craig Ricciuto
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've run into a little problem and with my limited knowledge in Struts 2 I've been unable to figure it out.

So I have an ArrayList of Strings being set in my action class and I can access it fine in the JSP via the Struts 2 tags (iterator with checkbox, OR using checkboxlist and no iterator). But I need an HTML text box input corresponding to each check box. So I want something that looks like the following once the HTML is rendered:



I've modified the checkboxlist tag once and have created my own "theme" that just has that change. I don't really want to do it again (create a second theme for another change to checkboxlist) unless I can modify my custom theme already to do what I currently have OR put a text box after the label.

Any ideas on how to use some kind of condition check in the FreeMarker checkboxlist.ftl file so after the label I can do what I'm already doing OR add the text field?

Thanks for any help. =)
 
Kartik Tal
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this what you wanted.
If there are 10 values in ArrayList, then you needed 10 checkboxes and 10 textboxes where one checkbox and one textbox in a row.
So there will be 10 rows.
 
Craig Ricciuto
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. That's exactly what I want. Again though, I have modified the checkboxlist template once so if there is some kind of condition check I can make (I've tried once but failed. It's still a little bit beyond my understanding) to either do what I already modified to do after the label OR add the text box that would be fantastic.
 
Kartik Tal
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This can be achieved by using Iterator tags in JSP

Action



JSP
 
Craig Ricciuto
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah I'm an idiot sometimes. I was just trying to use the struts2 tags to do it...was so dead set on that that I didn't even think about just using normal HTML. Gah!
Yay for overcomplicating things. I need to work on that.

Thanks Kartik.
 
Krzysztof Pieńkowski
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question regarding this solution. What should be the next step when I want to receive only selected checkboxes and text that was given only to those that are selected. What structure do I need to use when processing this form using struts?
 
Joe Ess
Bartender
Posts: 9318
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch. As the Struts page on Checkboxes points out, the relevant specifications do not provide a way to submit checkboxes that have not been selected. There are a number of examples on that page that show how to work with checkboxes. Keep in mind that if you are working with line items, you will also need to use indexed properties (I don't know why the comments above don't address this since it is clear they want line items)
 
Krzysztof Pieńkowski
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for this hint. Unfortunately I was not able to figure it out to adapt it to my problem.
Maybe I will give a code:

I have

List<Station> stationsList;

each Station has field "id"

I want to create as many pairs checkbox(with value of Station.id)+textfile as the size of stationsList is. I want also to store them into some structure into bean. I want to have only selected checkboxes and corresponding texts.

Now on my JSP I have something like:



This saves ids into selectedStations array but also stores all(not only those connected with checkbox that is selected) text values into stationNumbers.

Any idea how to solve that?
 
Joe Ess
Bartender
Posts: 9318
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can either remove the unselected line items on the browser using javascript or in you action on the server side.
There may be other options...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic