简体   繁体   English

如何设置将在迭代器中使用的textfield的值

[英]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. 我已经声明了此数组和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: 在jsp上,我将使用:

 <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. 请告诉我如何处理。

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=10&title=Nested%20Iterators%20Example

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM