Let me try to explain this a quickly and clearly as possible.  I want to
make my struts application have a calendar.  The user can add notes to each
day on the calendar.  I made a class that will contain all the information
for the note (see the ANote class below).  The note class contains a string
and a date.  I also have a class that store many notes.  The class (see the
MyNotes class below) will hold the notes in ArrayLists that are stored in a
Hashtable.  So if I add 2 notes for Jan 1, 2003 and 3 notes for Jan 2, 2003,
the Hashtable will contain 2 ArrayLists....one array list for each day.  I
thought this would be easy to iterate through each ArrayList.......that is
what I thought.  My struts Action will create a MyNotes object, fill the
MyNotes object with the notes that need to be displayed on the calendar (may
be a weekly calendar, monthly, etc).  This filled MyNotes object will be set
as a request attribute (e.g. request.setAttribute("myNotes", myNotes); ).

What I don't know how to do is to easily get the ArrayList for each day
using the MyNotes.getNotes(date) method.  I am _trying_ to use the struts
logic tag libraries to do this.  I CAN do this using Java code in my JSP,
but that is the purpose of the struts design...to minimize the use of Java
in the JSP.  So...is there a way to use the struts logic:iterate tag to get
the ArrayList of a particular day?  Something like:

("theDays" can be a collection of the days to display on the calendar)

<logic:iterate id="theDays" name="days">
   <logic:iterate name="someNotes" id="myNotes" property="notes"
parameter=<bean:write name="days">>
      The note says:<bean:write name="someNotes" property="note">
   </logic:iterate>

</logic:iterate>


----------------------------------------------------------------------------
---
import java.util.Date;

public class ANote {

    protected String note;
    protected Date event_date;

    public void setNote(String note) { this.note = note; }
    public String getNote() { return note; }

    public void setEventDate(Date event_date) { this.event_date =
event_date; }
    public Date getEventDate() { return event_date; }
}

----------------------------------------------------------------------------
---

import java.util.Hashtable;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.Calendar;
import java.util.Date;
import java.text.SimpleDateFormat;

public class MyNotes {

    private Hashtable allNotes;

    // Adds a note to the ArrayList in the Hashtable
    public void addNote(ANote myNote) {
        ArrayList notes;

        // Get date as hash key
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String dateString = sdf.format(note.getEventDate());

        // get existing array list for date
        try {
            notes = (ArrayList)allNotes.get(dateString);

            if (notes == null) {
                notes = new ArrayList();
                allNotes.put(dateString, notes);
            }
        } catch (Throwable t) {
        }

        // Add appointment
        notes.add(myNote);
    }

    // Returns all MyNotes from a date
    public ArrayList getNotes(Date date) {
        ArrayList notes;

        // Get hash key
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String dateString = sdf.format(date);

        // get existing array list for date
        try {
            notes = (ArrayList)allNotes.get(dateString);
            return notes;
        } catch (Throwable t) {
        }
    }

    public MyNotes() {
        allNotes = new Hashtable();
    }

}


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to