You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "V. Jenks" <za...@gmail.com> on 2008/10/23 22:47:26 UTC

Trying to create a calendar - need some guidance

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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Trying to create a calendar - need some guidance

Posted by James Carman <ja...@carmanconsulting.com>.
Mmmmmmmmmmmmmmmmmmm.  Waguy beef!

On Fri, Oct 24, 2008 at 11:04 AM, V. Jenks <za...@gmail.com> wrote:
>
> I'd really appreciate that Edgar, thanks!
>
> As for the GridView - "duh" for me.
>
> On another note, I just finished another one of our corporate sites, using
> Wicket.  Check it out, let me know your thoughts, criticisms, etc.  I used
> Wicket because I built our storefront a couple years ago with Wicket as well
> and eventually they'll be more tightly integrated.
>
> Everything is Wicket + Java EE 5 on Glassfish V2.
>
> http://www.snakeriverfarms.com/
>
>
> Edgar Merino wrote:
>>
>> 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 <za...@gmail.com> 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: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Trying-to-create-a-calendar---need-some-guidance-tp20138860p20151847.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Trying to create a calendar - need some guidance

Posted by "V. Jenks" <za...@gmail.com>.
I'd really appreciate that Edgar, thanks!

As for the GridView - "duh" for me.

On another note, I just finished another one of our corporate sites, using
Wicket.  Check it out, let me know your thoughts, criticisms, etc.  I used
Wicket because I built our storefront a couple years ago with Wicket as well
and eventually they'll be more tightly integrated.

Everything is Wicket + Java EE 5 on Glassfish V2.

http://www.snakeriverfarms.com/


Edgar Merino wrote:
> 
> 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 <za...@gmail.com> 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: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>>       
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>     
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>   
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Trying-to-create-a-calendar---need-some-guidance-tp20138860p20151847.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Trying to create a calendar - need some guidance

Posted by Edgar Merino <do...@gmail.com>.
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 <za...@gmail.com> 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: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Trying to create a calendar - need some guidance

Posted by John Krasnay <jo...@krasnay.ca>.
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 <za...@gmail.com> 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: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Trying to create a calendar - need some guidance

Posted by Igor Vaynberg <ig...@gmail.com>.
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 <za...@gmail.com> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Trying to create a calendar - need some guidance

Posted by adrienleroy <ad...@gmail.com>.
Yes, of course, but because webical is opensource, you can study the sources
and see they are building their calendar. 
 

V. Jenks wrote:
> 
> 
> 
> adrienleroy wrote:
>> 
>> Hello,
>> 
>> Take a look at the webical project, they are using Wicket :  
>> http://code.google.com/p/webical/
>> 
> 
> Thanks, but it's important that I build my own, given the nature of this
> project.  It took me 1.5 hrs. to do what I did in JSP so it's not like I'm
> trying to accomplish a huge task.
> 

-- 
View this message in context: http://www.nabble.com/Trying-to-create-a-calendar---need-some-guidance-tp20138860p20140136.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Trying to create a calendar - need some guidance

Posted by "V. Jenks" <za...@gmail.com>.


adrienleroy wrote:
> 
> Hello,
> 
> Take a look at the webical project, they are using Wicket :  
> http://code.google.com/p/webical/
> 

Thanks, but it's important that I build my own, given the nature of this
project.  It took me 1.5 hrs. to do what I did in JSP so it's not like I'm
trying to accomplish a huge task.
-- 
View this message in context: http://www.nabble.com/Trying-to-create-a-calendar---need-some-guidance-tp20138860p20140032.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Trying to create a calendar - need some guidance

Posted by adrienleroy <ad...@gmail.com>.
Hello,

Take a look at the webical project, they are using Wicket :  
http://code.google.com/p/webical/
-- 
View this message in context: http://www.nabble.com/Trying-to-create-a-calendar---need-some-guidance-tp20138860p20139967.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Trying to create a calendar - need some guidance

Posted by John Krasnay <jo...@krasnay.ca>.
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">&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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Trying to create a calendar - need some guidance

Posted by Igor Vaynberg <ig...@gmail.com>.
you are welcome

-igor

On Fri, Oct 24, 2008 at 9:38 AM, V. Jenks <za...@gmail.com> 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">&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-tp20138860p20153494.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Trying to create a calendar - need some guidance

Posted by "V. Jenks" <za...@gmail.com>.
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">&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-tp20138860p20153494.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org