I am working on a project where I load objects into an ArrayList arrayDiary in my action class populate method. The page linking to this page has the URL ‘populateDiary.action’. I have public getters & setters for this arrayList and I can see that the populate method is called and the arrayList does actually contain values.
My problem is that when I try to populate a li using the STRUTS iterator tag I am not seeing anything on the screen. I have read several posts on this and as far as I can see have copied them exactly – however I am not seeing my results on the screen.
Heres my diary.jsp code:
<s:iterator value="arrayDiary" status="pos" id="res">
<li onclick="$('#eventList').toggleClass('eventList'); $('#eventDesc').toggleClass('eventDesc'); $('.active').toggleClass('active'); $(this).toggleClass('active');"><a href="#"><s:property value="#res.title"/></a></li>
</s:iterator>
Heres my action class code:
private ArrayList<DiaryEntry> arrayDiary;
private ArrayList<DiaryEntry> arrayEvent;
public String populate() {
ArrayList<DiaryEntry> arrayEvent = new ArrayList<DiaryEntry>();
ArrayList<DiaryEntry> arrayDiary = new ArrayList<DiaryEntry>();
DiaryEntry load = new DiaryEntry();
username = (String) ActionContext.getContext().getSession().get("username");
loginId = (String) ActionContext.getContext().getSession().get("loginId");
ArrayList<DiaryEntry> diaryEntry = load.loadDiaryEntry(username, loginId);
for (DiaryEntry entry:diaryEntry) {
if(entry.getEvent() == null) {
arrayDiary.add(entry);
}
else {
arrayEvent.add(entry);
}
}
return "populate";
}
public ArrayList<DiaryEntry> getArrayDiary() {
return arrayDiary;
}
public void setArrayDiary(ArrayList<DiaryEntry> arrayDiary) {
this.arrayDiary = arrayDiary;
}
public ArrayList<DiaryEntry> getArrayEvent() {
return arrayEvent;
}
public void setArrayEvent(ArrayList<DiaryEntry> arrayEvent) {
this.arrayEvent = arrayEvent;
}
Heres my struts.xml:
<action name="*Diary" method="{1}" class="spirit.DiaryAction">
<result name="populate">/diary.jsp</result>
<result name="input">/diary.jsp</result>
<result name="success">/diary.jsp</result>
</action>
I would really appreciate if someone can spot where i’ve gone wrong. I’ve been working on this issue for 2 days now with no success. Thanks in advance for your help and feedback.
There is an obvious
ERRORin your action class, you hadarrayDiaryandarrayEventdefined in your class and in your methodpopulate(), there is for sure nothing happened in your<s:iterator>please change your method
populate()like this: