Re: logic:iterate, checkboxes, and arrays of selected values...
Put ALL the values in an arraylist and manipulate the arraylist values uppon return to the action. All the values are available in the same row together. The trick is getting the values from the arrayList back to the action when the form is submitted. I'm a genuine newbie and I have managed to pull this off numerous times now and it has made life much easier. I pieced together how to do this from searching the archives on this list including a previous post to someone else how to do it. If you cant find it you can send me an email off line and I'll send you some sample code. [EMAIL PROTECTED] wrote:Hi folks, I have a problem which I have a kludgy solution for, and have to believe there is a more elegant way of doing it... Here's the scenario. The page displays a non-editable list of records in a database, with a checkbox at the beginning of each row. The list is indeterminate length, based on selection criteria entered by the user in the previous page. The user selects n number of rows, using the check boxes. Those rows are to be deleted from the database. The trick is that the rows have a three column key. One is constant based on the user, so I need to get 2 pieces of information from each row before I can delete it. My kludge is to have the value of the checkboxes be the indexId of the logic:iterate. Each row has two hidden input fields, with the two required key values. Something like this: ="Transaction" indexId="counter"> [input] " name=selectedTxns> display data ... about the selected transaction... --> [input] ()%>" name=orderIds> [input] ()%>" name=deptAreas> In the formData bean, I have three String [ ] attributes to accept the values of the checkbox and the two hidden fields. The problem is that since there is data in the hidden input fields for every row, I get every value back in the array, instead of only the data for the rows which are checked. What I have to do in the action is read the values from the String [ ] for the checkbox , and use that value as the index into the other two string arrays. Like I said, its kludgy, but it works... But, I have to believe there's a way to send back an array of beans, with only the values of the fields for those rows which are checked, but I can't find anything in books or searching the web which describes how to do this. Does anyone have a cleaner way to do this type of thing? Thanx! c'ya Mike Mike Boucher [EMAIL PROTECTED] Edgil Associates www.edgil.com "Don't take life too seriously, you'll never get out of it alive!" - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: logic:iterate, checkboxes, and arrays of selected values...
A couple of options: 1) Use a key for the checkbox that is a combination of the two keys, combined with a character that cannot be in the keys themselves (e.g. key1::key2). They just separate them in the action, or better yet, have the form separate them. 2) Use JavasSript on the check of a row to enable/disable the two hidden fields. Disabled fields do not get transferred to the server. However, this may not be an option because it is browser-dependant. I'd probably go with the first option. -- Michael D. Norman ProbuSoft -- Custom Software Development http://www.probusoft.com/ 913-390-6951 [EMAIL PROTECTED] > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Sent: Tuesday, February 24, 2004 8:51 AM > To: [EMAIL PROTECTED] > Subject: logic:iterate, checkboxes, and arrays of selected values... > > Hi folks, > > I have a problem which I have a kludgy solution for, and have to believe > there is a more elegant way of doing it... Here's the scenario. > > The page displays a non-editable list of records in a database, with a > checkbox at the beginning of each row. The list is indeterminate length, > based on selection criteria entered by the user in the previous page. The > user selects n number of rows, using the check boxes. Those rows are to > be > deleted from the database. > > The trick is that the rows have a three column key. One is constant based > on the user, so I need to get 2 pieces of information from each row before > I can delete it. > > My kludge is to have the value of the checkboxes be the indexId of the > logic:iterate. Each row has two hidden input fields, with the two > required > key values. Something like this: > >="Transaction" indexId="counter"> > > > > > display data ... > <%=item.getTotal()%> > > > > > > > > > > > In the formData bean, I have three String [ ] attributes to accept the > values of the checkbox and the two hidden fields. > > The problem is that since there is data in the hidden input fields for > every row, I get every value back in the array, instead of only the data > for the rows which are checked. What I have to do in the action is read > the values from the String [ ] for the checkbox , and use that value as > the > index into the other two string arrays. > > Like I said, its kludgy, but it works... > > But, I have to believe there's a way to send back an array of beans, with > only the values of the fields for those rows which are checked, but I > can't > find anything in books or searching the web which describes how to do > this. > > Does anyone have a cleaner way to do this type of thing? > > Thanx! > > c'ya > Mike > > Mike Boucher [EMAIL PROTECTED] > Edgil Associates www.edgil.com > > "Don't take life too seriously, you'll never get out of it alive!" > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
logic:iterate, checkboxes, and arrays of selected values...
Hi folks, I have a problem which I have a kludgy solution for, and have to believe there is a more elegant way of doing it... Here's the scenario. The page displays a non-editable list of records in a database, with a checkbox at the beginning of each row. The list is indeterminate length, based on selection criteria entered by the user in the previous page. The user selects n number of rows, using the check boxes. Those rows are to be deleted from the database. The trick is that the rows have a three column key. One is constant based on the user, so I need to get 2 pieces of information from each row before I can delete it. My kludge is to have the value of the checkboxes be the indexId of the logic:iterate. Each row has two hidden input fields, with the two required key values. Something like this: display data ... <%=item.getTotal()%> In the formData bean, I have three String [ ] attributes to accept the values of the checkbox and the two hidden fields. The problem is that since there is data in the hidden input fields for every row, I get every value back in the array, instead of only the data for the rows which are checked. What I have to do in the action is read the values from the String [ ] for the checkbox , and use that value as the index into the other two string arrays. Like I said, its kludgy, but it works... But, I have to believe there's a way to send back an array of beans, with only the values of the fields for those rows which are checked, but I can't find anything in books or searching the web which describes how to do this. Does anyone have a cleaner way to do this type of thing? Thanx! c'ya Mike Mike Boucher [EMAIL PROTECTED] Edgil Associates www.edgil.com "Don't take life too seriously, you'll never get out of it alive!" - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]