My struts2 action class is this. I want to return a list of SampleModel to my jsp. This SampleModel is been created as a List
public class HelloWorld extends BaseActionSupport implements ModelDriven<HelloWorldForm>{
HelloWorldForm helloWorldForm = new HelloWorldForm();
private List<SampleModel> sampleModels;
private List countries;
public List getCountries()
{
return countries;
}
public List<SampleModel> getSampleModel() {
return sampleModels;
}
public void setSampleModel(List<SampleModel> sampleModels) {
this.sampleModels = sampleModels;
}
public String checkMultipleFunc() {
System.out.println("checked");
return "success";
}
public String execute() throws IOException {
countries = new ArrayList();
countries.add("Uganda");
countries.add("Ukraine");
countries.add("United States");
countries.add("United Arab Emirates");
countries.add("United Kingdom");
countries.add("Uruguay");
countries.add("Uzbekistan");
sampleModels = new ArrayList<SampleModel>();
SampleModel sampleModel1 = new SampleModel();
sampleModel1.setData1("d1");
sampleModel1.setData2("d2");
sampleModels.add(sampleModel1);
SampleModel sampleModel2 = new SampleModel();
sampleModel2.setData1("d11");
sampleModel2.setData2("d22");
sampleModels.add(sampleModel2);
return "success";
}
public HelloWorldForm getModel() {
return helloWorldForm;
}
}
The object that has to be printed is:
public class SampleModel {
public String data1;
public String data2;
@Override
public String toString() {
return "SampleModel [data1=" + data1 + ", data2=" + data2 + "]";
}
public String getData1() {
return data1;
}
public void setData1(String data1) {
this.data1 = data1;
}
public String getData2() {
return data2;
}
public void setData2(String data2) {
this.data2 = data2;
}
}
My jsp page is this:
<body bgcolor="pink">
<s:property value="sampleModels"/>
<s:property value="countries"/>
<s:iterator value="sampleModels" var="eachUser">
<s:property value="#eachUser.data1"/>
</s:iterator>
<s:iterator value="countries">
<s:property /><br>
</s:iterator>
<s:iterator value="sampleModels">
hello
<s:property />
<s:property value="data1" />
</s:iterator>
</body>
The country is getting displayed in jsp. But the SampleModels is not getting displayed. I have made all the getters as public only. Not sure what the issue is. Help me solving this issue.
Comments
Post a Comment