Dynamic form processing in struts

Hi all,

I need your help regarding dynamic form elements form processing.

Here is my JSP Script,

<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN">

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>

<html:html>

<HEAD>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

<TITLE>Processing Dynamic Forms</TITLE>

<script type="text/javascript">

//function which adds new row

function AddRow()

{

tb=document.getElementById("demo");

// attach counter

lnrows = tb.rows.length;

//alert(lnrows);

newrow = tb.insertRow(lnrows);

var fourth_col ="amt"+lnrows;

cell3=newrow.insertCell(0);

cell3.innerHTML="<center><input type='text' id='"+fourth_col+"' name='"+fourth_col+"' size='10'/></center>";

document.getElementById("cntr").value = lnrows;

}

// function to delete row

function DeleteRow()

{

tb=document.getElementById("demo");

lnrows = tb.rows.length;

//alert(lnrows);

if(lnrows > 2)

{

tb.deleteRow(lnrows-1);

document.getElementById("cntr").value = tb.rows.length - 1;

}

}

</script>

</HEAD>

<BODY>

<html:form action="/dynaActions">

<TABLE id='demo' align='center' width='80%' border='1'>

<TR>

<TH width='25%'>Party Name</TH>

</TR>

<TR>

<TD align='center'><input type='text' id="party1" name="party1" size="30" /></TD>

</TR>

</TABLE>

<TABLE align='center' width='80%' border='0'>

<TR align="right">

<td>

<html:button property="Add" value="Add" onclick="AddRow();" ></html:button>

<html:button property="Remove" value="Remove" onclick="DeleteRow();"></html:button>

</td>

</TR>

<TR align="center">

<td>

<input type='hidden' id="cntr" name="cntr" value="1" />

<html:submit/>

</td>

</TR>

</TABLE>

</html:form>

</BODY>

</html:html>

As you seen there is dynamically form elements generated as many as required. Now how do I process this with ActionForm & Action?

Regards,

Mahesh

[4059 byte] By [bonzya] at [2007-10-3 11:22:07]
# 1
my idea is try to access with same name with array....so when submit you get it through arrray..not sure just try and see.
rrhegdea at 2007-7-15 13:47:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hi rrhegde,

Thanks for response.

Ok, So instead of making it party1, party2, party3, party4, .............................

if I make it party[1], party[2], party[3], party[4],.............................

But then how do I process this array. Since the array length will not be fixed, it depends upon users.

If possible pls provide me some example code on this.

Thanks & Regards,

bonzy

bonzya at 2007-7-15 13:47:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...