Reputation: 81
In one of my web pages I have a HTML table. This table will have 0 or more rows and each row has 3 columns.
It looks like this:
<table>
<tr>
<td>Row1-Col1</td>
<td>Row1-Col2</td>
<td>Row1-Col1</td>
</tr>
<tr>
<td>Row2-Col1</td>
<td>Row2-Col2</td>
<td>Row3-Col1</td>
</tr>
</table>
I want to transfer the values of the columns (content of td's) to Action class.
Is there a way to
Struts 2 btw.
Thanks
Upvotes: 1
Views: 2633
Reputation: 3859
One of possible solutions, I guess, that you have this rows in an iterator...
So the JSP would look like that:
<s:form action="myAction">
<table>
<s:iterator value="someCollection" status="stat">
<!-- set id of column -->
<tr id="myTd<s:property value="#stat.index" />">
<td>some html</td>
</tr>
</s:iterator>
</table>
<s:hidden name="lastIndex" />
<s:hidden name="htmlValues" />
<s:submit onclick="submitValues();">
</s:form>
JS file:
function submitValues() {
var htmlValue;
int i = 0;
while(document.getElementById('myId'+i)) {
htmlValue += document.getElementById('myId'+i).innerHTML;
i++;
}
document.getElementyById('lastIndex').value = i;
document.getElementyById('htmlValues').value = htmlValue;
}
Action class:
public MyAction extends ActionSupport {
private Integer lastIndex;
private String htmlValues;
public String execute() {
//here there should be values filled
System.out.println(getLastIndex);
}
}
I did not test this, so maybe there could be mistakes, but the main idea is shown. Of course, you will get in htmlValues
in action class in html form, but there are a lot of html parses out there.
Upvotes: 1