In peacetime use S:iterator this iterative label, generally we are the same type of multiple objects into a set, then, can we put different objects to iterate? Daily work may sometimes be necessary to simplify the program, I tested it today, as if it could be completely
First step:
I set up two different Pojo classes,
public class Feng {
Private String Lou;
Private String Feng;
}
public class Fengfeng {
Private String A;
Private String B;
}
Of course, they need to provide their getter and setter methods.
Step Two:
Declare a list property in the action of STRUTS2
Private List Li;
also provides setter methods
To add different types of objects to the Li attribute in the appropriate Execute method
Feng f1=new Feng ();
F1.setfeng ("Feng");
F1.setlou ("Lou");
Feng f2=new Feng ();
F2.setfeng ("feng1");
F2.setlou ("lou1");
Fengfeng a1=new Fengfeng ();
A1.seta ("a");
A1.SETB ("B");
Fengfeng a2=new Fengfeng ();
A2.seta ("A1");
A2.setb ("B2");
Li=new ArrayList ();
Li.add (F1);
Li.add (F2);
Li.add (A1);
Li.add (A2);
The test is convenient, I have manually instantiated
Step Three:
In the page iteration, which is the most important part, I have added some judgments to the s:iterator to implement iterations of different types of objects
<s:iterator value= "Li" >
<s:if test= "Feng!=null" ><s:property value= "Feng"/>!! <s:property value= "Lou"/></s:if>
<s:if test= "A!=null" ><s:property value= "a"/>!! <s:property value= "B"/></s:if>
</s:iterator>
The page displays the following effect:
feng!! Lou feng1!! LOU1 a!! b a1!! B2
Ha ha! It worked! This will enable flexible iterations, very practical Oh!