user358352
user358352

Reputation:

how to set the value of textfield which will be used in iterator

private Integer[] routeId; private String[] routeName;

I have declared this array and getter setter. Now I want to set its values in iterator like:

Iterator<Object> iter=tManager.getApprovedTourPlan(staffId,9).iterator();  
 tourList=new ArrayList<TourPlan>();  
 int i=0;  while(iter.hasNext())  { 
                Object[] tour = (Object[]) iter.next();   
                TourPlan tp=new TourPlan();    
                tp.setRouteId(0);
                tp.setRouteName("asd");  
                tourList.add(tp);
       }

And on jsp I will use:

 <s:iterator list="tourList" var="tour"> <s:property
     name="#tour.routeId"> <s:property name="#tour.routeName">
 </s:iterator>

But when I set values:

tp.setRouteId(0);  
tp.setRouteName("asd");

I can't set values because they accept array. Please tell me how to handle that.

Upvotes: 0

Views: 2361

Answers (1)

coding_idiot
coding_idiot

Reputation: 13734

From what I get all you need is nested iterators, they'll look something like this

<s:iterator value="lstBean" id="lstBean" status="outerStat">
        <s:textfield value="%{name}" name="lstBean[%{#outerStat.index}].name"/>
        <s:textfield value="%{amt}" name="lstBean[%{#outerStat.index}].amt"/>
        <s:textfield value="%{id}" name="lstBean[%{#outerStat.index}].id"/>
        <s:iterator value="%{lstString}" status="myStat">
            <s:textfield name="lstBean[%{#outerStat.index}].lstString[%{#myStat.index}]"/>
        </s:iterator>
    </s:iterator>

and

class XBean
{
    private ArrayList<String> lstString=new ArrayList<String>();
    private String name;
    private Double amt;
    private Integer id;
}

Examples

http://www.onlinexamples.com/showfullexample.action?idexamples=10&title=Nested%20Iterators%20Example

http://www.onlinexamples.com/showfullexample.action?idexamples=11&title=Iterator%20over%20an%20array/list%20of%20objects/beans

Upvotes: 1

Related Questions