I've got an abstract calendar already coded, the only problem is that it's using a DataTable (instead of only a gridview), I have to change the code to use the gridview instead, I'll post the code tomorrow if I've got the time and you're still interested.

Edgar Merino





John Krasnay escribió:
Uh, yeah, that's what I meant to say, just use a GridView :-)

jk

On Thu, Oct 23, 2008 at 05:14:42PM -0700, Igor Vaynberg wrote:
all you need is a gridview. set columns to 7 and generate 30 items...

-igor

On Thu, Oct 23, 2008 at 1:47 PM, V. Jenks <[EMAIL PROTECTED]> 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">&nbsp;</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">&nbsp;</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]


---------------------------------------------------------------------
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]

Reply via email to