Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2465
  • Last Modified:

How do I make dynamic lists of Struts 2 form elements?

I can display my lists of form objects using Struts 2. I am having problems with the JSP syntax to retrieve data using a ModelDriven object. You can see in code snippet the idea of what I am trying to do.  I have a dynamic list of data and I need to get back one or more data members from each individual object in the list.
<s:iterator value="myList" status="status">			
	<s:textfield id="%{myList[#status.index].description" />
	<s:textfield id="%{myList[#status.index].quantity" />
</s:iterator>
 
class MyRowItem
{
  private String description;
  private Integer quantity;
  // Assume getters/setters
}
 
 
class MyModel
{
  private List<MyRowItem> myList;
  // Assume getters/setters and proper initialization of class
}

Open in new window

0
dancingevilgenius
Asked:
dancingevilgenius
1 Solution
 
dancingevilgeniusAuthor Commented:
Found the solution on my own. Below is an example of list of parts.  2 data members will be changed in the form.  One is a dropdown and the other is a textfield.
<s:iterator id="partList"  status="status">
	<s:select list="%{shippingCarrier}" headerKey="-1"
		headerValue="Select One" listKey="id" listValue="descr"		
		id="partList[%{#status.index}].coreReturnCarrierId"
		name="partList[{#status.index}].coreReturnCarrierId"
		value="%{partList[#status.index].coreReturnCarrierId}"       
	/>
	<s:textfield								
		id="partList[%{#status.index}].coreReturnTrackingNumber"
		name="partList[%{#status.index}].coreReturnTrackingNumber"								
		value="%{partList[#status.index].coreReturnTrackingNumber}"
	/>
</s:iterator>

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now