It's not a secret anymore!
The moose likes Struts and the fly likes Struts 1.3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 1.3 " Watch "Struts 1.3 " New topic

Struts 1.3

Atif Jamil

Joined: Aug 11, 2013
Posts: 5
i m new to struts...
i have problem in creating a new requisition made by employee.
requisition contains(id,date,requisition items) where requisition items is a list of items containing in table rows.
every row contain one item information containing (item id, description, remarks etc)
my problem is that how i dynamically populate table rows...
i already seen some discussion about indexed properties on the forum but all these have some pre-information stored in database.
they display that information first and then edit/update it.
but i want to create blank requisition form and then add rows dynamically how many i want...then submit it to action class
any suggestion please..thanks in advance
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33124

You want to dynamically populate with what data? If they are new, wouldn't they be blank?

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Atif Jamil

Joined: Aug 11, 2013
Posts: 5
i want to populate the rows of table dynamically and them submit the table data to action class for further processing.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33124

I still don't understand what you mean by dynamically. Can you elaborate?

For example,
The user clicks new requisition form. It gets loaded with one row of form fields for one item. These form fields are three text fields initialized to the empty string. The user sees a "+" button. Clicking that button adds a second row of form fields for the second item.
Atif Jamil

Joined: Aug 11, 2013
Posts: 5
i have search field

<td><bean:message key="" />
<td><html:text styleId="pname" property="productName" onkeyup="return getProductList(this.value)" />
<td><div id="results" style="margin-left: 200px;"></div>
<td><bean:message key="label.description" />
<td><html:text styleId="pdescription" property="productDescription" />
<bean:message key="label.remarks" />
<html:text styleId="premarks" property="productRemarks" />
<html:button property="addNewRow" value="Add Line Item" onclick="return addRow('dataTable')"></html:button>

i used ajax to find product description and fill the description field. on clicking "addNewRow" button i want to add the row(productName, description, remarks) in table.
again search for 2nd, 3rd and more products add information to the table. my add row function is

function addRow(tableId) {
var table = document.getElementById(tableId);
var rowCount = table.rows.length;
var newRow = table.insertRow(rowCount);
var indexValue = rowCount - 1;

var cell1 = newRow.insertCell(0);
var element1 = document.createElement("input");
element1.type = "text"; = "lineItem[" + indexValue + "].lineNumber";
element1.value = rowCount;

var cell2 = newRow.insertCell(1);
var element2 = document.createElement("input");
element2.type = "text"; = "lineItem[" + indexValue + "].id";
element2.value = document.getElementById('pname').value;

var cell3 = newRow.insertCell(2);
var element3 = document.createElement("input");
element3.type = "text"; = "lineItem[" + indexValue + "].description";
element3.value = document.getElementById('pdescription').value;

var cell4 = newRow.insertCell(3);
var element4 = document.createElement("input");
element4.type = "text"; = "lineItem[" + indexValue + "].quantity";
element4.value = document.getElementById('pquantity').value;

var cell5 = newRow.insertCell(4);
var element5 = document.createElement("input");
element5.type = "text"; = "lineItem[" + indexValue + "].remarks";
element5.value = document.getElementById('premarks').value;

var cell6 = newRow.insertCell(5);
var element6 = document.createElement("input");
element6.type = "checkbox"; = "lineItem[" + indexValue + "].chkbox";
document.getElementById('submitButton').disabled = false;

<table id="dataTable" border="2" >
<td><bean:message key="label.line" /></td>
<td><bean:message key="" /></td>
<td><bean:message key="label.description" /></td>
<td><bean:message key="label.quantity" /></td>
<td><bean:message key="label.remarks" /></td>
<td><bean:message key="label.delete" /></td>

<html:submit styleId="submitButton" property="goto" value="save" disabled="true" />

by clicking "save" button i want to get all rows in action class for further processing.
my problem is that how to get all rows in action class?
Atif Jamil

Joined: Aug 11, 2013
Posts: 5
also check my addNewRow() method is right or not?
i means i used input field name is right or wrong?
Atif Jamil

Joined: Aug 11, 2013
Posts: 5
i saw the example by "Brent Sterling", user of this forum. link to Brent Sterling example
he used indexed properties but he pre populate the table on jsp page with some rows.
my form is blank on load. i search the product then add it to the table.
I agree. Here's the link:
subject: Struts 1.3
jQuery in Action, 3rd edition