Solved

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

Posted on 2008-10-23
1
2,460 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
dancingevilgenius earned 0 total points
ID: 22798842
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

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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.

691 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