ListView is good if you already have a list of things you want to display. For this kind of iteration you'd be better off with a RepeatingView. Here's how I might tackle it:
- create a top-level panel to hold the calendar. The markup would contain your table element, and would have a RepeatingView attached to a tr element - create a panel representing the row, which has a RepeatingView attached to a td element. - create a panel representing a day. - put your loop in the ctor of the top-level panel. Start by creating a row panel and adding it to the first RepeatingView. Then for each day, create a day panel and add it to the repeating view in the row. When you get to the Saturday, just create a new row panel as the "current" one, add it to the first RepeatingView, and continue on your way. Now for the cool part: you could put the part where you create the day panel into an overrideable method. Then you could re-use the component to generate all kinds of different calendars by simply subclassing and returning different kinds of day panels. jk On Thu, Oct 23, 2008 at 01:47:26PM -0700, V. Jenks wrote: > > Hi all. > > I'm trying to build a component-ized calendar that will be the centerpiece > of a new application I'm working on. I built one this morning in JSP and > was able to do it with very little code. I kept it simple and I'm hoping I > can retro-fit the logic into a wicket page cleanly, without too much > trouble. I'm a little stuck because in my JSP, I simply loop through the > days and print until Saturday is reached, then I break to a new table row > and continue. Doing this in Wicket seems tough because if I use a ListView, > I can't be as flexible as far as throwing in a new row while looping and > outputting table cells. > > Here's the rough idea I came up with today in JSP, can someone give me some > pointers? > > <%@ page contentType="text/html" pageEncoding="UTF-8" %> > <%@ page import="java.util.*" %> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > "http://www.w3.org/TR/html4/loose.dtd"> > <% > //get parameters to change date > String monthParam = request.getParameter("month"); > String yearParam = request.getParameter("year"); > > //create calendar object > Calendar cal = Calendar.getInstance(); > cal.setFirstDayOfWeek(Calendar.SUNDAY); //set first day to Sunday > > if (monthParam != null) > cal.set(Calendar.MONTH, (Integer.valueOf(monthParam)-1)); > > if (yearParam != null) > cal.set(Calendar.YEAR, Integer.valueOf(yearParam)); > > //get total number of days in month > int numDaysInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH); > > //get current month name in English > String monthName = cal.getDisplayName(Calendar.MONTH, Calendar.LONG, > Locale.ENGLISH); > > //get current year > int year = cal.get(Calendar.YEAR); > > //get array of day names > String[] headers = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; > %> > <html> > <head> > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> > <title>Calendarama!</title> > </head> > <body> > <table border="1"> > <tr> > <!-- print month and year --> > <th colspan="7" align="center"><%= monthName + " " + year %></th> > </tr> > <tr> > <!-- loop and print days --> > <% > for (int i=0; i<7; i++) > { > %> > <td><%= headers[i] %></td> > <% > } > %> > </tr> > <!-- DRAW CALENDAR --> > <tr> > <% > for (int i=1; i<=numDaysInMonth; i++) > { > //re-set calendar day in context of loop > cal.set(Calendar.DAY_OF_MONTH, i); > > //get the day number of the week > int day = cal.get(Calendar.DAY_OF_WEEK); > > //days without numbers count > int blankDays = 0; > > //blank days before 1st of month? > if (i == 1 && day > 1) > { > blankDays = day - i; //get count > > //loop through count and print blank day > for (int x=1; x<=blankDays; x++) > { > %> > <td width="100" height="100"> </td> > <% > } > } > %> > <td width="100" height="100" valign="top"><%= i %></td> > <% > if (day == Calendar.SATURDAY) > { > %> > </tr> > <tr> > <% > } > > //blank days after last day of month? > if (i == numDaysInMonth && day < 7) > { > blankDays = 7 - day; //get count > > //loop through count and print blank day > for (int x=1; x<=blankDays; x++) > { > %> > <td width="100" height="100"> </td> > <% > } > } > } > %> > </tr> > </table> > </body> > </html> > > -- > View this message in context: > http://www.nabble.com/Trying-to-create-a-calendar---need-some-guidance-tp20138860p20138860.html > Sent from the Wicket - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]