Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to catch checkbox value

 
Revanth reddy
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I am pulling some records from the DB and displaying it on the UI using <logic:iterate>. Each time the count of the record will be changed. and i am displaying a checkbox beside every row. my requirement is i need to update the record where the user checked the checkbox. my question is how do we access the values for that particular checkbox.

Any help would be greatly appreciated.
Thanks in Advance

Kumar
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The records displayed via iterate tag should be in a form tag. When the user selects the record(s) and clicks the submit button for the form, then you can access the value for the checkbox(s) via ActionForm object associated with Action that handles form processing.

Check checkbox documentation at:

struts-html.html#checkbox
 
Revanth reddy
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by James Clark:
The records displayed via iterate tag should be in a form tag. When the user selects the record(s) and clicks the submit button for the form, then you can access the value for the checkbox(s) via ActionForm object associated with Action that handles form processing.

Check checkbox documentation at:

struts-html.html#checkbox




Thank you so much James....
 
Revanth reddy
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by James Clark:
The records displayed via iterate tag should be in a form tag. When the user selects the record(s) and clicks the submit button for the form, then you can access the value for the checkbox(s) via ActionForm object associated with Action that handles form processing.

Check checkbox documentation at:

struts-html.html#checkbox



James,
Here my scenario is quite tricky. here is my complete requirement
1. user enters a input
2. i will be displaying the recors in a grid based on user input, having checkbox beside every row.
3. when the user checks any checkbox(even morethan one checkbox) i need to display the 4 text boxes below the row where the user checks the checkbox, with the existing values on it.
4. user can update one or more fields (even one or more rows, when the user checks more than one checkbox) and hit update
5. then i need to update that particular rows(only update the rows where the user checks the checkbox)
6.currently i am assigning the rowid for each checkbox.

how do we send the updated values to the action, and how do we catch the user selected checkbox..

here is my jsp...




any suggetion is greatly appriciated...
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
3. when the user checks any checkbox(even morethan one checkbox) i need to display the 4 text boxes below the row where the user checks the checkbox, with the existing values on it.
4. user can update one or more fields (even one or more rows, when the user checks more than one checkbox) and hit update


I would first go for the following:

1. Have user make selections and then hit an edit/update button.

2. Then reprocess page and display the 4 text boxes under the selected rows (with existing values). Have either a single update/submit button or display a update/submit button for each record.

One you have this going, you can start to explore other possibilities.

You will need some conditional logic to process the variations with the same JSP page. This shouldn't be that tough.

Don't try to stuff everything in one Action class. (1) Have an Action to handle when the user first makes the selection. Here you will get data values from form which identify rows to be edited. (2) Then have another Action to handle processing the changed data.
 
Revanth reddy
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by James Clark:


Don't try to stuff everything in one Action class. (1) Have an Action to handle when the user first makes the selection. Here you will get data values from form which identify rows to be edited. (2) Then have another Action to handle processing the changed data.


James,
i am using 2 actions one is for getting the data from DB
another action is for update..

one more update for the requirement is :::

1.i have to display the db results in a grid
2. have a 4 text fields completley below the grid(in earlier case the text boxes are below each row, now we have only 4 text boxes)
3. when the user checks any checkboxes in the grid, then that particular row(existing values) values into the textbox.
4. so the user can change the existing values, and hit update we have to update the db. (in the previous case we have multiple updates at a time, in this case we have only one update at any time)

my question is how do we display the existing values in the textboxes
(based on user checkbox selection)

ex: if the user clicks on 2nd checkbox we need to display the 2nd row detials in the textboxes. if the user clicks on 5th checkbox we have to display 5th row data in the textboxes....

can you help me on this..... with some code snippets..

Thanks
Kumar
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my question is how do we display the existing values in the textboxes (based on user checkbox selection)

ex: if the user clicks on 2nd checkbox we need to display the 2nd row detials in the textboxes. if the user clicks on 5th checkbox we have to display 5th row data in the textboxes....


Before you get to the above do the following.

1. When you first display the records, at the bottom or at the top of the table have a Edit/Update button (go to UpdateDataAction).

2. The code in the UpdateDataAction should iterate through the objects in the ActionForm and identify the records that were selected. You must set a flag on these objects so that they can be identified when the JSP processes the page again.

3. UpdateDataAction forwards control back to JSP page.

4. The code in the JSP page must be written to identify the selected records. Instead of displaying the data in a plain table row with checkbox, it needs to display the data in the textboxes so that user can edit them.

5. There needs to be a button that will go to SaveDataAction. User changes data and clicks this button to save edited data.
 
Revanth reddy
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks James
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem.

You most likely will need some scriplet code in the JSP file. This will be the easiest way to get the conditional logic of either displaying the records in the table or displaying the records with the editable textboxes. Getting this into one JSP is better than trying to avoid putting scriptlet code in the JSP file. The scriptlets will only be a few lines anyhow. Just the if statements to determine how records should be displayed and what buttons to display and where.

Probably need 3 Actions to (1) getRecords, (2) editRecords, and (3) save RecordData

Once you have it working with the basic form submit buttons, then you could try some fancy stuff with onSelect or onClick JavaScript functions (if needed).
[ December 29, 2008: Message edited by: James Clark ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic