Solved

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

Posted on 2008-10-23
1
2,453 Views
Last Modified: 2013-11-24
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
Comment
Question by:dancingevilgenius
1 Comment
 

Accepted Solution

by:
dancingevilgenius earned 0 total points
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now