This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Regarding struts buttons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Regarding struts buttons" Watch "Regarding struts buttons" New topic

Regarding struts buttons

LV Reddy

Joined: Mar 20, 2006
Posts: 13
I am using struts. I am getting values from database using bean and displaying it in a table. For each row there is a button named edit.
Below that table there are text areas pertaining to 2 columns of the above table.
If edit button is clicked for any row then I want that row data to appear in the textarea and it should be editable.
Please Can anyone suggest me a solution for doing this.
Oscar Gonzalez
Ranch Hand

Joined: Mar 28, 2006
Posts: 63
This is how I usually do that:

1. Create a "task" property in your form.
2. Create a <html:hidden property="task" value="idOfTheButton"/>
3. Add this js code to the JSP
function setTask (formName, task)
formName.task.value = task;
4.The button should submit the page, then in the Action class, after checking if the task property is null or not, set any property you may need.
5. Use a <logic:notEMpty property="task"> in you jsp to show the textarea.
6. You are done.

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Since all you want to do is move text from one area of the form to another, this could be done entirely with JavaScript without submitting the form. Just write a function called by the on click event that:

* finds the data you need in the current row. (hint: you can get the row of the clicked button with this.parentNode.parentNode)
* put this data in a temporary variable
* set the value of the text box to the value of the temporary variable

Consultant, Sima Solutions
LV Reddy

Joined: Mar 20, 2006
Posts: 13
Hi Merril,
Thank you very much for the reply. I got ur point I am very poor in javascript. So please can u tell me how to get the individual elements(td element contents) of the row.
LV Reddy

Joined: Mar 20, 2006
Posts: 13
Hai Merril,
Thank you very much. I got the contents populated into the required fields.
Don't get me started about those stupid light bulbs.
subject: Regarding struts buttons
Similar Threads
Adding new elements to table in struts 1.2
add a row
Struts and dynamic table rows and editing?
duplicate row for editing
Highlighting a row in a table