Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding struts buttons

 
LV Reddy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Regards,
Venkatesh.
 
Oscar Gonzalez
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
formName.submit();
}
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
LV Reddy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Regards,
Venkatesh.
 
LV Reddy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai Merril,
Thank you very much. I got the contents populated into the required fields.
Regards,
Venkatesh.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic