Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get the values of a table generated in the jsp in the action in struts 2?
    primarykey
    data
    text
    <p>In my jsp I am selecting some values from one Table1 and adding it to another table Table2 by using the Add button. This is my jsp:</p> <pre><code>&lt;%@page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8"%&gt; &lt;%@taglib prefix="s"uri="/struts-tags"%&gt; &lt;!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt; &lt;title&gt;Insert title here&lt;/title&gt; &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" /&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $('#add').on("click", function(){ $('#one tbody input:checked').parent().parent() .appendTo("#two tbody"); return false; }); $('#remove').on("click", function(){ $('#two tbody input:checked').parent().parent() .appendTo("#one tbody"); return false; }); }); function GetCellValues() { var oTable = document.getElementById('two'); var mycars = new Array(); var mycars1 = new Array(); var mycars2 = new Array(); //gets table var rowLength = oTable.rows.length; //gets rows of table for (i = 0; i &lt; rowLength; i++){ //loops through rows var oCells = oTable.rows.item(i).cells; //gets cells of current row var cellLength = oCells.length; for(var j = 0; j &lt; cellLength; j++){ //loops through each cell in current row //get your cell info here var cellVal = oCells.item(j).innerHTML; alert(cellVal); if(j==3){ mycars[i] = cellVal; } if(j==1){ mycars1[i] = cellVal; } if(j==2){ mycars2[i] = cellVal; } } } window.location ="DynamicTable?mytable="+mycars; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;button onclick="GetCellValues()"&gt;Submit&lt;/button&gt; &lt;table id="one" style="border:1px solid red;"&gt; &lt;caption&gt;Table 1&lt;/caption&gt; &lt;thead&gt; &lt;tr&gt; &lt;th &gt;&lt;/th&gt; &lt;th&gt; Id&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Status&lt;/th&gt; &lt;th&gt;Type&lt;/th&gt; &lt;th&gt;RollUp Type&lt;/th&gt; &lt;th&gt;System&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;s:iterator value="formList1"&gt; &lt;tr&gt; &lt;td&gt;&lt;s:checkbox theme="simple" &gt;&lt;/s:checkbox&gt; &lt;/td&gt; &lt;td&gt;&lt;s:property value="id"/&gt;&lt;/td&gt; &lt;td&gt;&lt;s:property value="named"/&gt;&lt;/td&gt; &lt;td&gt;&lt;s:property value="status"/&gt;&lt;/td&gt; &lt;td&gt;&lt;s:property value="type"/&gt;&lt;/td&gt; &lt;td&gt;&lt;s:property value="rollup"/&gt;&lt;/td&gt; &lt;td&gt;&lt;s:property value="unit"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/s:iterator&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;table id="two" style="border:1px solid green;"&gt; &lt;caption&gt;Table 2&lt;/caption&gt; &lt;thead&gt; &lt;tr&gt; &lt;th &gt;&lt;/th&gt; &lt;th&gt; Id&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Status&lt;/th&gt; &lt;th&gt;Type&lt;/th&gt; &lt;th&gt;RollUp Type&lt;/th&gt; &lt;th&gt;System&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;br&gt;&lt;hr&gt;&lt;br&gt; &lt;button id="add"&gt;Add&lt;/button&gt; &lt;button id="remove"&gt;Remove&lt;/button&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Here how do I retrieve the values that I added in Table 2 in my action when I click on Submit button in Struts2?</p> <p>This is what I tried, I called the javascript GetCellValues() on click of Submit button, where I set each column in the array mycars,mycars1 and so on.</p> <p>In my action class I have getters and setters for these arrays. But in my action I am not able to retrieve these values.</p> <p>How to get the values of a table generated in the jsp in the action?</p> <p><strong>UPDATE</strong>: I just corrected the line <code>window.location ="DynamicTable?mytable="+mycars;</code> now i'm getting the values in the action as a String separated by commas. I would like to know if there is any other method than what I have used?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload