You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Derek Stevenson <de...@retrocode.com> on 2002/08/29 10:51:29 UTC

using static object fields for date comparisons

I'm trying to put together a page on which three <select> boxes are 
displayed, allowing the user to select month, date, and year, 
respectively.  I'd also like to automatically set those fields properly 
based on the current date.  From turbine, I've done:

         GregorianCalendar g = new GregorianCalendar();
         g.setTime(new Date());
         context.put("date", g);

In my vm file, I've also put (I'm only using the select box for the month 
to demonstrate the point):

<select name="month">
...
	<option value="$date.JANUARY"
	#if ($date.get($date.MONTH) == $date.JANUARY)
		selected
	#end
	>January</option>
...	
</select>

On execution, the error indicates $date.JANUARY is not a valid 
reference.  So I've drawn the following conclusions:
1. the static field I'm trying to reference from class GregorianCalendar 
isn't working (I figured as much would happen based on the naming 
conventions Velocity imposes).
2. the embedded if statement would set the 'selected' attribute for the 
<option> tag if I was able to use the indicated comparison, however since 
it relies on static fields of the GregorianCalendar class, I'm not able to 
automatically select the proper month.

Any suggestions on addressing these issues?  Is there another way of 
referencing static fields of classes within Velocity?  It seems I could 
work around these problems using methods from the Date class, but they're 
mostly deprecated in favor of the methods in class GregorianCalendar...

Thanks,
Derek

ps. TDK 2.1, turbine 2.1, velocity 1.3-dev


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: using static object fields for date comparisons

Posted by Derek Stevenson <de...@retrocode.com>.
Geir,

Thanks, that looks like it'll do the trick.

I did a little more research and it looks like I can use 
org.apache.turbine.util.DateSelector, along with the Element Construction 
Set (ecs-1.4.1), to create HTML components for selecting a date (taken from 
the DateSelector api docs):

         ElementContainer ec = new ElementContainer();
         String myName = "mydate";
         ec.addElement(DateSelector.getMonthSelector(myName));
         ec.addElement(DateSelector.getDaySelector(myName));
         ec.addElement(DateSelector.getYearSelector(myName));
         context.put("ec",ec);

Then, when $ec is rendered in my velocity template it creates the date 
selection fields perfectly.  It also looks like it automatically sets the 
fields to the current date.

However, I thought I read somewhere that the ECS was being phased out of 
Turbine, or something else like that -- does anyone know anything more 
about this?

Thanks,
Derek

At 05:26 AM 8/29/2002, you wrote:
>On 8/29/02 4:51 AM, "Derek Stevenson" <de...@retrocode.com> wrote:
>
> > I'm trying to put together a page on which three <select> boxes are
> > displayed, allowing the user to select month, date, and year,
> > respectively.  I'd also like to automatically set those fields properly
> > based on the current date.  From turbine, I've done:
> >
> >        GregorianCalendar g = new GregorianCalendar();
> >        g.setTime(new Date());
> >        context.put("date", g);
> >
> > In my vm file, I've also put (I'm only using the select box for the month
> > to demonstrate the point):
> >
> > <select name="month">
> > ...
> > <option value="$date.JANUARY"
> > #if ($date.get($date.MONTH) == $date.JANUARY)
> > selected
> > #end
> >> January</option>
> > ...
> > </select>
> >
> > On execution, the error indicates $date.JANUARY is not a valid
> > reference.  So I've drawn the following conclusions:
> > 1. the static field I'm trying to reference from class GregorianCalendar
> > isn't working (I figured as much would happen based on the naming
> > conventions Velocity imposes).
>
>It's not the naming convention but rather we don't allow you to access
>fields in an object.
>
>There is a class called the 'FieldMethodizer' that will do this for you.
>
>
>--
>Geir Magnusson Jr.
>Research & Development, Adeptra Inc.
>geirm@adeptra.com
>+1-203-247-1713
>
>
>
>--
>To unsubscribe, 
>e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: 
><ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: AW: building javadocs

Posted by Scott Eade <se...@backstagetech.com.au>.
> From: "Marc Lustig" <ma...@marclustig.com>
> 
>>> From: "Marc Lustig" <ma...@marclustig.com>
>>> 
>>> I followed the instructions and checked out Turbine from CVS.
>>> But in the directory jakarta-turbine-2/build there is no
>> build.xml file to
>>> build the javadoc.
>>> Any ideas or suggestions how to build the javadocs another way?
>> 
>> The easiest way is to use maven.  Install maven-b6 and then in your
>> jakarta-turbine-2 directory execute:
>> 
>>     maven javadoc
> 
> I installed maven-b4. (no b6 found)
> But how is this supposed to run on my win2000 box w/o any maven.bat file?
Not sure where you were looking.  Following the links from the maven site
leads to the b6 distribution (not that you need it now - see below).

> What I understand is with the TDK 2.1 release I don't have to make another
> build with maven. I only need to build the javadocs as they don't come along
> with the package.
> So how do I build the javadocs from the TDK 2.1 release the easiest way?

I had assumed you were using turbine 2.2bx as you were referring to CVS.

In fact the tdk 2.1 does come bundled with the javadocs.  If you have
started the tdk tomcat instance (assuming port 8080) you can browse to:

    http://localhost:8080/

...and you will be presented with a bunch of links, one of which is the
Turbine API documentation.

If you want the latest API docs you can just go to the turbine 2 site and
click the JavaDocs link to go to:

http://jakarta.apache.org/turbine/turbine-2/apidocs/index.html


Cheers,

Scott
-- 
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


AW: building javadocs

Posted by Marc Lustig <ma...@marclustig.com>.
> > From: "Marc Lustig" <ma...@marclustig.com>
> >
> > I followed the instructions and checked out Turbine from CVS.
> > But in the directory jakarta-turbine-2/build there is no
> build.xml file to
> > build the javadoc.
> > Any ideas or suggestions how to build the javadocs another way?
>
> The easiest way is to use maven.  Install maven-b6 and then in your
> jakarta-turbine-2 directory execute:
>
>     maven javadoc

I installed maven-b4. (no b6 found)
But how is this supposed to run on my win2000 box w/o any maven.bat file?
What I understand is with the TDK 2.1 release I don't have to make another
build with maven. I only need to build the javadocs as they don't come along
with the package.
So how do I build the javadocs from the TDK 2.1 release the easiest way?

Thanks!
Marc


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: building javadocs

Posted by Scott Eade <se...@backstagetech.com.au>.
> From: "Marc Lustig" <ma...@marclustig.com>
> 
> I followed the instructions and checked out Turbine from CVS.
> But in the directory jakarta-turbine-2/build there is no build.xml file to
> build the javadoc.
> Any ideas or suggestions how to build the javadocs another way?

The easiest way is to use maven.  Install maven-b6 and then in your
jakarta-turbine-2 directory execute:

    maven javadoc

HTH,

Scott
-- 
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


building javadocs

Posted by Marc Lustig <ma...@marclustig.com>.
Hi again,
I followed the instructions and checked out Turbine from CVS.
But in the directory jakarta-turbine-2/build there is no build.xml file to
build the javadoc.
Any ideas or suggestions how to build the javadocs another way?

Thanks!

Marc


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: using static object fields for date comparisons

Posted by Peter Courcoux <pe...@courcoux.biz>.
Derek,

I used the following as a request scoped pull tool for something
similar. Not the best design but it worked for what I was doing. Use in
the template like :

#set ( $ds = $utilstool.getDateSelector("datefield") )



    /**
     * Method to get an html date selector initialised with todays date.
     * The method takes the name of a datefield which is suffixed with
     * Day, Month and Year to represent the html form field names
     */
    public String getDateSelector(String datefield)
    {
	StringBuffer sb = new StringBuffer();
	try
	    {
	//set locale
	Locale loc = new Locale("ENGLISH", "UK");
	// get a formatter for the month names
	DateFormatSymbols dfs = new DateFormatSymbols(loc);
	String[] months = dfs.getMonths();
	String dfd = datefield + new String("Day");
	String dfm = datefield + new String("Month");
	String dfy = datefield + new String("Year");
	java.util.Date date = new Date(System.currentTimeMillis());
	Log.info("system", "UtilsTool-getDateSelector - date :" +
date.toString());
	GregorianCalendar gc = new GregorianCalendar(loc);
	gc.setTime(date);
	int day = gc.get(GregorianCalendar.DATE);
	int month = gc.get(GregorianCalendar.MONTH);
	int year = gc.get(GregorianCalendar.YEAR);
	// now for the formatting
	//day first
	sb.append("<select name=\"" + dfd + "\">");
	for (int i=1; i<=31;i++)
	    {
		sb.append("<option value=\"" + i + "\"");
		if (i == day)
		    {
			sb.append(" selected");
		    }
		sb.append(">" + i );		
	    }
	sb.append("</select>");
	// month next
	sb.append("<select name=\"" + dfm + "\">");
	for (int i=0; i<12; i++)
	    {
		sb.append("<option value=\"" + i + "\"");
		if (month == i)
		    {
			sb.append(" selected");
		    }
		sb.append(">");
		sb.append(months[i]);
	    }
	sb.append("</select>");
	// year last
	sb.append("<select name=\"" + dfy + "\">");
	int startyear = 2002;
	int endyear = 2010;
	for (int i=startyear; i<= endyear; i++)
	    {
		sb.append("<option value=\"" + i + "\">" + i);
	    }
	sb.append("</select>");
	    }
	catch (Exception e)
	    {
		Log.info("system", "UtilsTool-getDateSelector Exception caught :" +
e.getMessage());
	    }
	return sb.toString();
    }


Hope that helps.

Peter Courcoux


On Thu, 2002-08-29 at 09:51, Derek Stevenson wrote:
> I'm trying to put together a page on which three <select> boxes are 
> displayed, allowing the user to select month, date, and year, 
> respectively.  I'd also like to automatically set those fields properly 
> based on the current date.  From turbine, I've done:
> 
>          GregorianCalendar g = new GregorianCalendar();
>          g.setTime(new Date());
>          context.put("date", g);
> 
> In my vm file, I've also put (I'm only using the select box for the month 
> to demonstrate the point):
> 
> <select name="month">
> ...
> 	<option value="$date.JANUARY"
> 	#if ($date.get($date.MONTH) == $date.JANUARY)
> 		selected
> 	#end
> 	>January</option>
> ...	
> </select>
> 
> On execution, the error indicates $date.JANUARY is not a valid 
> reference.  So I've drawn the following conclusions:
> 1. the static field I'm trying to reference from class GregorianCalendar 
> isn't working (I figured as much would happen based on the naming 
> conventions Velocity imposes).
> 2. the embedded if statement would set the 'selected' attribute for the 
> <option> tag if I was able to use the indicated comparison, however since 
> it relies on static fields of the GregorianCalendar class, I'm not able to 
> automatically select the proper month.
> 
> Any suggestions on addressing these issues?  Is there another way of 
> referencing static fields of classes within Velocity?  It seems I could 
> work around these problems using methods from the Date class, but they're 
> mostly deprecated in favor of the methods in class GregorianCalendar...
> 
> Thanks,
> Derek
> 
> ps. TDK 2.1, turbine 2.1, velocity 1.3-dev
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


getting started with turbine 2.1

Posted by Marc Lustig <ma...@marclustig.com>.
Hi,

is there sort of tutorial available telling the basic steps of creating a
turbine-based web-application? Like 30.000 feet view.
I checked sites like javaworld, webmonkey etc. w/o any result.

Thanks!
Marc


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: using static object fields for date comparisons

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 8/29/02 4:51 AM, "Derek Stevenson" <de...@retrocode.com> wrote:

> I'm trying to put together a page on which three <select> boxes are
> displayed, allowing the user to select month, date, and year,
> respectively.  I'd also like to automatically set those fields properly
> based on the current date.  From turbine, I've done:
> 
>        GregorianCalendar g = new GregorianCalendar();
>        g.setTime(new Date());
>        context.put("date", g);
> 
> In my vm file, I've also put (I'm only using the select box for the month
> to demonstrate the point):
> 
> <select name="month">
> ...
> <option value="$date.JANUARY"
> #if ($date.get($date.MONTH) == $date.JANUARY)
> selected
> #end
>> January</option>
> ...    
> </select>
> 
> On execution, the error indicates $date.JANUARY is not a valid
> reference.  So I've drawn the following conclusions:
> 1. the static field I'm trying to reference from class GregorianCalendar
> isn't working (I figured as much would happen based on the naming
> conventions Velocity imposes).

It's not the naming convention but rather we don't allow you to access
fields in an object.

There is a class called the 'FieldMethodizer' that will do this for you.


-- 
Geir Magnusson Jr. 
Research & Development, Adeptra Inc.
geirm@adeptra.com
+1-203-247-1713



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>