I am working on a Canteen Software project based on Struts2 / jsp / hibernate / MYSQL.
I have a requirement that in a jsp page i have to add a row of struts2 input fields dynamically when user clicks on Add Button.
Along with the row 3 buttons are also added Save, Cancel, Edit
All this is working allright using javascript.
my problem is that since these set of rows are loaded dynamically as per user choice, hence they have no relation to action properties.
I didn't understand what you want to do, can you share screen shot as per your requirement.
ocjp 6 — Feeding a person with food is a great thing in this world. Feeding the same person by transferring the knowledge is far more better thing. The reason is the amount of satisfaction which we get through food is of only one minute or two. But the satisfaction which we can get through the knowledge is of life long.
I am working on a Canteen Software project based on Struts2 / jsp / hibernate / MYSQL.
I have a requirement that in a jsp page i have to add a row of struts2 input fields dynamically when user clicks on Add Button.
Along with the row 3 buttons are also added Save, Cancel, Edit
All this is working allright using javascript.
my problem is that since these set of rows are loaded dynamically as per user choice, hence they have no relation to action properties.
how do i populate these to action properties ?
Waiting for your advises
Regards
Vijay Kumar
if your input fields have same name, then you can get these using array.
i have to add students details in a jsp as per attached pictures.
The problem i am facing is that the row of input fields (performance.standard & performance.marks) are generated dynamically on the Add Button Click (using javascript), hence thereby there can be any no of rows of such input fields. Though i have decalred performance & student object in the action properties but action performance property setter is never fired after action submit. Only other properties which are hardcorded in jsp page using struts2 form tags are fired in the action.
how do i populate the dynamically added performance input elements row object in the jsp to action.
cosequently the target jsp output.jsp does not display performance object properties
function cost_addRow(tableid,button,value)
{
button.disabled = "true";
var table = document.getElementById(tableid);
var rowcount = table.rows.length;
var colcount = table.rows[0].cells.length;
colcount+=1; // provision for 1 more column for save buttons
var row = table.insertRow(rowcount);
for (var i=0;i<colcount;i++)
{
var newcell = row.insertCell(i);
var id=tableid+rowcount+i;
switch (i)
{
case 0:
newcell.innerHTML='<s:textfield id="'+id+'" name="perform.standard" value="'+value+'" size="20" theme="simple"/>';
break;
case 1:
newcell.innerHTML='<s:textfield id="'+id+'" name="perform.marks" value="'+value+'" size="10" theme="simple"/>';
break;
case 2:
newcell.innerHTML='<input id="'+id+'" type="button" value="Save">';
newcell.childNodes[0].onclick=new Function("saveRow('"+tableid+"','"+rowcount+"','"+colcount+"')");
break;
}
}
}
function saveRow(tableid,row_no,total_cells)
{
var table = document.getElementById(tableid);
for (var i=0;i<total_cells;i++)
{
var id = tableid+row_no+i;
var element = document.getElementById(id);
element.disabled="true";
}
var button = document.getElementById("performance_button");
button.disabled = "";
}
></script>