you are welcome -igor
On Fri, Oct 24, 2008 at 9:38 AM, V. Jenks <[EMAIL PROTECTED]> wrote: > > Igor, thanks again for the clue on using GridView, I got it figured out and > it works great! I attached the code in case anyone's interested in drawing > a basic calendar. It's lean and clean so it's easy to extend. > http://www.nabble.com/file/p20153494/Cal.java Cal.java > http://www.nabble.com/file/p20153494/Cal.html Cal.html > http://www.nabble.com/file/p20153494/DayProvider.java DayProvider.java > > > 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-tp20138860p20153494.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]
