Quantcast

gsp syntax question

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

gsp syntax question

Martin Flower
Hi - getting to grips with gsp tags and syntax and I need a little help please.

In the gsp I have a ${startDate} and ${endDate}.  I would like to compare the months of the two dates inside a <g:if /> tag.

I have found out that this works :

<g:set var="monthNumber" value="${Calendar.getInstance().get(Calendar.MONTH)}" />
${monthNumber}

But what I want to do is set the date something like :

<g:set var="monthNumber" value="${Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)}" />

or

<g:set var="monthNumber" value="${Calendar.getInstance().setTime(${startDate}).get(Calendar.MONTH)}" />

but these don't work

Even this doesn't work

<g:set var="monthNumber" value="${Calendar.getInstance().setTime(new Date()).get(Calendar.MONTH)}" />

Should it ?

Can you see where I'm trying to go ?  Can it be done ?  Many thanks in advance.

Martin


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: gsp syntax question

Dustin Whitney
For this

Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)

your problem is that setTime() has a void return type, so when you call get() afterward, you get a NullPointerException.

Honestly in this situation, I'd use a scriptlet:

<%
def calendar = Calendar.getInstance().setTime(startDate)
def monthNumber = calendar.get(Calendar.MONTH)
%>

-Dustin


On Sun, Aug 31, 2008 at 11:47 AM, MartinFlower <[hidden email]> wrote:

Hi - getting to grips with gsp tags and syntax and I need a little help
please.

In the gsp I have a ${startDate} and ${endDate}.  I would like to compare
the months of the two dates inside a <g:if /> tag.

I have found out that this works :

<g:set var="monthNumber"
value="${Calendar.getInstance().get(Calendar.MONTH)}" />
${monthNumber}

But what I want to do is set the date something like :

<g:set var="monthNumber"
value="${Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)}" />

or

<g:set var="monthNumber"
value="${Calendar.getInstance().setTime(${startDate}).get(Calendar.MONTH)}"
/>

but these don't work

Even this doesn't work

<g:set var="monthNumber" value="${Calendar.getInstance().setTime(new
Date()).get(Calendar.MONTH)}" />

Should it ?

Can you see where I'm trying to go ?  Can it be done ?  Many thanks in
advance.

Martin



--
View this message in context: http://www.nabble.com/gsp-syntax-question-tp19243390p19243390.html
Sent from the grails - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: gsp syntax question

Martin Flower
Dustin, thanks for the explanation - *now* I understand ...

I've now got :

def calendar = Calendar.getInstance()
calendar.setTime(startDate)
def startMonthNumber = calendar.get(Calendar.MONTH)

So, as I see it I have the following options :

1. scriptlet (current solution)
2. write my own tag
3. put the processing in the controller

Technically I would prefer option 3, but I haven't got to understanding Command objects in Grails yet. Until then I'll stick with the scriptlet.

Martin


Dustin Whitney wrote
For this

Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)

your problem is that setTime() has a void return type, so when you call
get() afterward, you get a NullPointerException.

Honestly in this situation, I'd use a scriptlet:

<%
def calendar = Calendar.getInstance().setTime(startDate)
def monthNumber = calendar.get(Calendar.MONTH)
%>

-Dustin


On Sun, Aug 31, 2008 at 11:47 AM, MartinFlower <grails@dialogue.ag> wrote:

>
> Hi - getting to grips with gsp tags and syntax and I need a little help
> please.
>
> In the gsp I have a ${startDate} and ${endDate}.  I would like to compare
> the months of the two dates inside a <g:if /> tag.
>
> I have found out that this works :
>
> <g:set var="monthNumber"
> value="${Calendar.getInstance().get(Calendar.MONTH)}" />
> ${monthNumber}
>
> But what I want to do is set the date something like :
>
> <g:set var="monthNumber"
> value="${Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)}" />
>
> or
>
> <g:set var="monthNumber"
> value="${Calendar.getInstance().setTime(${startDate}).get(Calendar.MONTH)}"
> />
>
> but these don't work
>
> Even this doesn't work
>
> <g:set var="monthNumber" value="${Calendar.getInstance().setTime(new
> Date()).get(Calendar.MONTH)}" />
>
> Should it ?
>
> Can you see where I'm trying to go ?  Can it be done ?  Many thanks in
> advance.
>
> Martin
>
>
>
> --
> View this message in context:
> http://www.nabble.com/gsp-syntax-question-tp19243390p19243390.html
> Sent from the grails - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: gsp syntax question

fernando.takai
Well, it's better to add all this processing to the controller.

You could do something like this:


def calendar = Calendar.getInstance()
calendar.setTime(startDate)
def startMonthNumber = calendar.get(Calendar.MONTH)

return [startMonthNumber: startMonthNumber]

IMHO views just show information, delegating processing data to controllers and services.


On Sun, Aug 31, 2008 at 2:16 PM, MartinFlower <[hidden email]> wrote:

Dustin, thanks for the explanation - *now* I understand ...

I've now got :

def calendar = Calendar.getInstance()
calendar.setTime(startDate)
def startMonthNumber = calendar.get(Calendar.MONTH)

So, as I see it I have the following options :

1. scriptlet (current solution)
2. write my own tag
3. put the processing in the controller

Technically I would prefer option 3, but I haven't got to understanding
Command objects in Grails yet. Until then I'll stick with the scriptlet.

Martin



Dustin Whitney wrote:
>
> For this
>
> Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)
>
> your problem is that setTime() has a void return type, so when you call
> get() afterward, you get a NullPointerException.
>
> Honestly in this situation, I'd use a scriptlet:
>
> <%
> def calendar = Calendar.getInstance().setTime(startDate)
> def monthNumber = calendar.get(Calendar.MONTH)
> %>
>
> -Dustin
>
>
> On Sun, Aug 31, 2008 at 11:47 AM, MartinFlower <[hidden email]> wrote:
>
>>
>> Hi - getting to grips with gsp tags and syntax and I need a little help
>> please.
>>
>> In the gsp I have a ${startDate} and ${endDate}.  I would like to compare
>> the months of the two dates inside a <g:if /> tag.
>>
>> I have found out that this works :
>>
>> <g:set var="monthNumber"
>> value="${Calendar.getInstance().get(Calendar.MONTH)}" />
>> ${monthNumber}
>>
>> But what I want to do is set the date something like :
>>
>> <g:set var="monthNumber"
>> value="${Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)}"
>> />
>>
>> or
>>
>> <g:set var="monthNumber"
>> value="${Calendar.getInstance().setTime(${startDate}).get(Calendar.MONTH)}"
>> />
>>
>> but these don't work
>>
>> Even this doesn't work
>>
>> <g:set var="monthNumber" value="${Calendar.getInstance().setTime(new
>> Date()).get(Calendar.MONTH)}" />
>>
>> Should it ?
>>
>> Can you see where I'm trying to go ?  Can it be done ?  Many thanks in
>> advance.
>>
>> Martin
>>
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/gsp-syntax-question-tp19243390p19243390.html
>> Sent from the grails - user mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>>
>
>

--
View this message in context: http://www.nabble.com/gsp-syntax-question-tp19243390p19244107.html
Sent from the grails - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email





--
Fernando "Takai"
http://flickr.com/photos/supeertakai
http://fernandotakai.wordpress.com
http://fernandotakai.jaiku.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: gsp syntax question

Dimo Velev
In reply to this post by Martin Flower
You might also consider setting the correct user time zone and locale
while you are at this :)

Am So 31.08.2008 19:16 schrieb MartinFlower <[hidden email]>:

>
>Dustin, thanks for the explanation - *now* I understand ...
>
>I've now got :
>
>def calendar = Calendar.getInstance()
>calendar.setTime(startDate)
>def startMonthNumber = calendar.get(Calendar.MONTH)
>
>So, as I see it I have the following options :
>
>1. scriptlet (current solution)
>2. write my own tag
>3. put the processing in the controller
>
>Technically I would prefer option 3, but I haven't got to understanding
>Command objects in Grails yet. Until then I'll stick with the
>scriptlet.
>
>Martin
>
>
>
>Dustin Whitney wrote:
>>
>>For this
>>
>>Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)
>>
>>your problem is that setTime() has a void return type, so when you
>>call
>>get() afterward, you get a NullPointerException.
>>
>>Honestly in this situation, I'd use a scriptlet:
>>
>><%
>>def calendar = Calendar.getInstance().setTime(startDate)
>>def monthNumber = calendar.get(Calendar.MONTH)
>>%>
>>
>>-Dustin
>>
>>
>>On Sun, Aug 31, 2008 at 11:47 AM, MartinFlower <[hidden email]>
>>wrote:
>>
>>>
>>>Hi - getting to grips with gsp tags and syntax and I need a little
>>>help
>>>please.
>>>
>>>In the gsp I have a ${startDate} and ${endDate}. I would like to
>>>compare
>>>the months of the two dates inside a <g:if /> tag.
>>>
>>>I have found out that this works :
>>>
>>><g:set var="monthNumber"
>>>value="${Calendar.getInstance().get(Calendar.MONTH)}" />
>>>${monthNumber}
>>>
>>>But what I want to do is set the date something like :
>>>
>>><g:set var="monthNumber"

>>>>>>value="${Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)}"
>>>/>
>>>
>>>or
>>>
>>><g:set var="monthNumber"

>>>>>>value="${Calendar.getInstance().setTime(${startDate}).get(Calendar.MONTH)}"
>>>/>
>>>
>>>but these don't work
>>>
>>>Even this doesn't work
>>>
>>><g:set var="monthNumber" value="${Calendar.getInstance().setTime(new
>>>Date()).get(Calendar.MONTH)}" />
>>>
>>>Should it ?
>>>
>>>Can you see where I'm trying to go ? Can it be done ? Many thanks in
>>>advance.
>>>
>>>Martin
>>>
>>>
>>>
>>>--
>>>View this message in context:
>>>http://www.nabble.com/gsp-syntax-question-tp19243390p19243390.html
>>>Sent from the grails - user mailing list archive at Nabble.com.
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe from this list, please visit:
>>>
>>>http://xircles.codehaus.org/manage_email
>>>
>>>
>>>
>>
>>
>
>--
>View this message in context:
>http://www.nabble.com/gsp-syntax-question-tp19243390p19244107.html
>Sent from the grails - user mailing list archive at Nabble.com.
>
>
>---------------------------------------------------------------------
>To unsubscribe from this list, please visit:
>
>http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: gsp syntax question

Mingfai
In reply to this post by Dustin Whitney
ignoring any best practice, you may get the GSP work by:

<g:set var="monthNumber" value="${Calendar.getInstance().with{it.setTime(startDate);it}.get(Calendar.MONTH)}" />

regards,
mingfai

On Sun, Aug 31, 2008 at 11:56 PM, Dustin Whitney <[hidden email]> wrote:
For this

Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)

your problem is that setTime() has a void return type, so when you call get() afterward, you get a NullPointerException.

Honestly in this situation, I'd use a scriptlet:

<%
def calendar = Calendar.getInstance().setTime(startDate)
def monthNumber = calendar.get(Calendar.MONTH)
%>

-Dustin



On Sun, Aug 31, 2008 at 11:47 AM, MartinFlower <[hidden email]> wrote:

Hi - getting to grips with gsp tags and syntax and I need a little help
please.

In the gsp I have a ${startDate} and ${endDate}.  I would like to compare
the months of the two dates inside a <g:if /> tag.

I have found out that this works :

<g:set var="monthNumber"
value="${Calendar.getInstance().get(Calendar.MONTH)}" />
${monthNumber}

But what I want to do is set the date something like :

<g:set var="monthNumber"
value="${Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)}" />

or

<g:set var="monthNumber"
value="${Calendar.getInstance().setTime(${startDate}).get(Calendar.MONTH)}"
/>

but these don't work

Even this doesn't work

<g:set var="monthNumber" value="${Calendar.getInstance().setTime(new
Date()).get(Calendar.MONTH)}" />

Should it ?

Can you see where I'm trying to go ?  Can it be done ?  Many thanks in
advance.

Martin



--
View this message in context: http://www.nabble.com/gsp-syntax-question-tp19243390p19243390.html
Sent from the grails - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: gsp syntax question

Robby O'Connor
He was given a far better solution by putting it where this should go:
the controller. (Read the archive before you reply to a message thread ;)

--rob
Mingfai wrote:

> ignoring any best practice, you may get the GSP work by:
>
> <g:set var="monthNumber"
> value="${Calendar.getInstance().with{it.setTime(startDate);it}.get(Calendar.MONTH)}"
> />
>
> regards,
> mingfai
>
> On Sun, Aug 31, 2008 at 11:56 PM, Dustin Whitney
> <[hidden email] <mailto:[hidden email]>> wrote:
>
>     For this
>
>     Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)
>
>     your problem is that setTime() has a void return type, so when you
>     call get() afterward, you get a NullPointerException.
>
>     Honestly in this situation, I'd use a scriptlet:
>
>     <%
>     def calendar = Calendar.getInstance().setTime(startDate)
>     def monthNumber = calendar.get(Calendar.MONTH)
>     %>
>
>     -Dustin
>
>
>
>     On Sun, Aug 31, 2008 at 11:47 AM, MartinFlower <[hidden email]
>     <mailto:[hidden email]>> wrote:
>
>
>         Hi - getting to grips with gsp tags and syntax and I need a
>         little help
>         please.
>
>         In the gsp I have a ${startDate} and ${endDate}.  I would like
>         to compare
>         the months of the two dates inside a <g:if /> tag.
>
>         I have found out that this works :
>
>         <g:set var="monthNumber"
>         value="${Calendar.getInstance().get(Calendar.MONTH)}" />
>         ${monthNumber}
>
>         But what I want to do is set the date something like :
>
>         <g:set var="monthNumber"
>         value="${Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)}"
>         />
>
>         or
>
>         <g:set var="monthNumber"
>         value="${Calendar.getInstance().setTime(${startDate}).get(Calendar.MONTH)}"
>         />
>
>         but these don't work
>
>         Even this doesn't work
>
>         <g:set var="monthNumber" value="${Calendar.getInstance().setTime(new
>         Date()).get(Calendar.MONTH)}" />
>
>         Should it ?
>
>         Can you see where I'm trying to go ?  Can it be done ?  Many
>         thanks in
>         advance.
>
>         Martin
>
>
>
>         --
>         View this message in context:
>         http://www.nabble.com/gsp-syntax-question-tp19243390p19243390.html
>         Sent from the grails - user mailing list archive at Nabble.com.
>
>
>         ---------------------------------------------------------------------
>         To unsubscribe from this list, please visit:
>
>            http://xircles.codehaus.org/manage_email
>
>
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: gsp syntax question

Robby O'Connor
erm, i should do that too; but yes, this belongs in a controller of some sort.
-Rob



On Mon, Sep 1, 2008 at 1:00 AM, Robby O'Connor <[hidden email]> wrote:

> He was given a far better solution by putting it where this should go: the
> controller. (Read the archive before you reply to a message thread ;)
>
> --rob
> Mingfai wrote:
>>
>> ignoring any best practice, you may get the GSP work by:
>>
>> <g:set var="monthNumber"
>> value="${Calendar.getInstance().with{it.setTime(startDate);it}.get(Calendar.MONTH)}"
>> />
>>
>> regards,
>> mingfai
>>
>> On Sun, Aug 31, 2008 at 11:56 PM, Dustin Whitney <[hidden email]
>> <mailto:[hidden email]>> wrote:
>>
>>    For this
>>
>>    Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)
>>
>>    your problem is that setTime() has a void return type, so when you
>>    call get() afterward, you get a NullPointerException.
>>
>>    Honestly in this situation, I'd use a scriptlet:
>>
>>    <%
>>    def calendar = Calendar.getInstance().setTime(startDate)
>>    def monthNumber = calendar.get(Calendar.MONTH)
>>    %>
>>
>>    -Dustin
>>
>>
>>
>>    On Sun, Aug 31, 2008 at 11:47 AM, MartinFlower <[hidden email]
>>    <mailto:[hidden email]>> wrote:
>>
>>
>>        Hi - getting to grips with gsp tags and syntax and I need a
>>        little help
>>        please.
>>
>>        In the gsp I have a ${startDate} and ${endDate}.  I would like
>>        to compare
>>        the months of the two dates inside a <g:if /> tag.
>>
>>        I have found out that this works :
>>
>>        <g:set var="monthNumber"
>>        value="${Calendar.getInstance().get(Calendar.MONTH)}" />
>>        ${monthNumber}
>>
>>        But what I want to do is set the date something like :
>>
>>        <g:set var="monthNumber"
>>
>>  value="${Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)}"
>>        />
>>
>>        or
>>
>>        <g:set var="monthNumber"
>>
>>  value="${Calendar.getInstance().setTime(${startDate}).get(Calendar.MONTH)}"
>>        />
>>
>>        but these don't work
>>
>>        Even this doesn't work
>>
>>        <g:set var="monthNumber"
>> value="${Calendar.getInstance().setTime(new
>>        Date()).get(Calendar.MONTH)}" />
>>
>>        Should it ?
>>
>>        Can you see where I'm trying to go ?  Can it be done ?  Many
>>        thanks in
>>        advance.
>>
>>        Martin
>>
>>
>>
>>        --
>>        View this message in context:
>>        http://www.nabble.com/gsp-syntax-question-tp19243390p19243390.html
>>        Sent from the grails - user mailing list archive at Nabble.com.
>>
>>
>>
>>  ---------------------------------------------------------------------
>>        To unsubscribe from this list, please visit:
>>
>>           http://xircles.codehaus.org/manage_email
>>
>>
>>
>>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: gsp syntax question

a.shneyderman
In reply to this post by fernando.takai
I do not get these advices of how one should put everything in a
controller. Why?

You have a date and you want to show only the number of the month. How
does it warranty code in a controller? Views are there to render the
result. If rendering means given a date display a month number of that
date, the view should be able to do it (hence is the word rendering).

I can agree with trying to avoid scriptlets, that is why there are
taglibs and in GSPs and they are a breeze to create and use, but they
are part of the view. So, in either case this sort of processing does
belong to a view IMHO.

Alex.

On Sun, Aug 31, 2008 at 7:42 PM, Fernando Takai
<[hidden email]> wrote:

> Well, it's better to add all this processing to the controller.
>
> You could do something like this:
>
>
> def calendar = Calendar.getInstance()
> calendar.setTime(startDate)
> def startMonthNumber = calendar.get(Calendar.MONTH)
>
> return [startMonthNumber: startMonthNumber]
>
> IMHO views just show information, delegating processing data to controllers
> and services.
>
>
> On Sun, Aug 31, 2008 at 2:16 PM, MartinFlower <[hidden email]> wrote:
>>
>> Dustin, thanks for the explanation - *now* I understand ...
>>
>> I've now got :
>>
>> def calendar = Calendar.getInstance()
>> calendar.setTime(startDate)
>> def startMonthNumber = calendar.get(Calendar.MONTH)
>>
>> So, as I see it I have the following options :
>>
>> 1. scriptlet (current solution)
>> 2. write my own tag
>> 3. put the processing in the controller
>>
>> Technically I would prefer option 3, but I haven't got to understanding
>> Command objects in Grails yet. Until then I'll stick with the scriptlet.
>>
>> Martin
>>
>>
>>
>> Dustin Whitney wrote:
>> >
>> > For this
>> >
>> > Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)
>> >
>> > your problem is that setTime() has a void return type, so when you call
>> > get() afterward, you get a NullPointerException.
>> >
>> > Honestly in this situation, I'd use a scriptlet:
>> >
>> > <%
>> > def calendar = Calendar.getInstance().setTime(startDate)
>> > def monthNumber = calendar.get(Calendar.MONTH)
>> > %>
>> >
>> > -Dustin
>> >
>> >
>> > On Sun, Aug 31, 2008 at 11:47 AM, MartinFlower <[hidden email]>
>> > wrote:
>> >
>> >>
>> >> Hi - getting to grips with gsp tags and syntax and I need a little help
>> >> please.
>> >>
>> >> In the gsp I have a ${startDate} and ${endDate}.  I would like to
>> >> compare
>> >> the months of the two dates inside a <g:if /> tag.
>> >>
>> >> I have found out that this works :
>> >>
>> >> <g:set var="monthNumber"
>> >> value="${Calendar.getInstance().get(Calendar.MONTH)}" />
>> >> ${monthNumber}
>> >>
>> >> But what I want to do is set the date something like :
>> >>
>> >> <g:set var="monthNumber"
>> >>
>> >> value="${Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)}"
>> >> />
>> >>
>> >> or
>> >>
>> >> <g:set var="monthNumber"
>> >>
>> >> value="${Calendar.getInstance().setTime(${startDate}).get(Calendar.MONTH)}"
>> >> />
>> >>
>> >> but these don't work
>> >>
>> >> Even this doesn't work
>> >>
>> >> <g:set var="monthNumber" value="${Calendar.getInstance().setTime(new
>> >> Date()).get(Calendar.MONTH)}" />
>> >>
>> >> Should it ?
>> >>
>> >> Can you see where I'm trying to go ?  Can it be done ?  Many thanks in
>> >> advance.
>> >>
>> >> Martin
>> >>
>> >>
>> >>
>> >> --
>> >> View this message in context:
>> >> http://www.nabble.com/gsp-syntax-question-tp19243390p19243390.html
>> >> Sent from the grails - user mailing list archive at Nabble.com.
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe from this list, please visit:
>> >>
>> >>    http://xircles.codehaus.org/manage_email
>> >>
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/gsp-syntax-question-tp19243390p19244107.html
>> Sent from the grails - user mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>
>
>
> --
> Fernando "Takai"
> http://flickr.com/photos/supeertakai
> http://fernandotakai.wordpress.com
> http://fernandotakai.jaiku.com
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: gsp syntax question

Dustin Whitney
I agree, and in fact I'd go so far as to say that a 2 or 3 line scriptlet is no big deal.  More lines than that is likely a problem, and if your scriptlets are common it's a problem, but for the most part, being practical with the use of scriptlets and minor processing in the view is no big deal, and is ultimately worth it if it saves time.

-Dustin

On Mon, Sep 1, 2008 at 2:18 AM, Alex Shneyderman <[hidden email]> wrote:
I do not get these advices of how one should put everything in a
controller. Why?

You have a date and you want to show only the number of the month. How
does it warranty code in a controller? Views are there to render the
result. If rendering means given a date display a month number of that
date, the view should be able to do it (hence is the word rendering).

I can agree with trying to avoid scriptlets, that is why there are
taglibs and in GSPs and they are a breeze to create and use, but they
are part of the view. So, in either case this sort of processing does
belong to a view IMHO.

Alex.

On Sun, Aug 31, 2008 at 7:42 PM, Fernando Takai
<[hidden email]> wrote:
> Well, it's better to add all this processing to the controller.
>
> You could do something like this:
>
>
> def calendar = Calendar.getInstance()
> calendar.setTime(startDate)
> def startMonthNumber = calendar.get(Calendar.MONTH)
>
> return [startMonthNumber: startMonthNumber]
>
> IMHO views just show information, delegating processing data to controllers
> and services.
>
>
> On Sun, Aug 31, 2008 at 2:16 PM, MartinFlower <[hidden email]> wrote:
>>
>> Dustin, thanks for the explanation - *now* I understand ...
>>
>> I've now got :
>>
>> def calendar = Calendar.getInstance()
>> calendar.setTime(startDate)
>> def startMonthNumber = calendar.get(Calendar.MONTH)
>>
>> So, as I see it I have the following options :
>>
>> 1. scriptlet (current solution)
>> 2. write my own tag
>> 3. put the processing in the controller
>>
>> Technically I would prefer option 3, but I haven't got to understanding
>> Command objects in Grails yet. Until then I'll stick with the scriptlet.
>>
>> Martin
>>
>>
>>
>> Dustin Whitney wrote:
>> >
>> > For this
>> >
>> > Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)
>> >
>> > your problem is that setTime() has a void return type, so when you call
>> > get() afterward, you get a NullPointerException.
>> >
>> > Honestly in this situation, I'd use a scriptlet:
>> >
>> > <%
>> > def calendar = Calendar.getInstance().setTime(startDate)
>> > def monthNumber = calendar.get(Calendar.MONTH)
>> > %>
>> >
>> > -Dustin
>> >
>> >
>> > On Sun, Aug 31, 2008 at 11:47 AM, MartinFlower <[hidden email]>
>> > wrote:
>> >
>> >>
>> >> Hi - getting to grips with gsp tags and syntax and I need a little help
>> >> please.
>> >>
>> >> In the gsp I have a ${startDate} and ${endDate}.  I would like to
>> >> compare
>> >> the months of the two dates inside a <g:if /> tag.
>> >>
>> >> I have found out that this works :
>> >>
>> >> <g:set var="monthNumber"
>> >> value="${Calendar.getInstance().get(Calendar.MONTH)}" />
>> >> ${monthNumber}
>> >>
>> >> But what I want to do is set the date something like :
>> >>
>> >> <g:set var="monthNumber"
>> >>
>> >> value="${Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)}"
>> >> />
>> >>
>> >> or
>> >>
>> >> <g:set var="monthNumber"
>> >>
>> >> value="${Calendar.getInstance().setTime(${startDate}).get(Calendar.MONTH)}"
>> >> />
>> >>
>> >> but these don't work
>> >>
>> >> Even this doesn't work
>> >>
>> >> <g:set var="monthNumber" value="${Calendar.getInstance().setTime(new
>> >> Date()).get(Calendar.MONTH)}" />
>> >>
>> >> Should it ?
>> >>
>> >> Can you see where I'm trying to go ?  Can it be done ?  Many thanks in
>> >> advance.
>> >>
>> >> Martin
>> >>
>> >>
>> >>
>> >> --
>> >> View this message in context:
>> >> http://www.nabble.com/gsp-syntax-question-tp19243390p19243390.html
>> >> Sent from the grails - user mailing list archive at Nabble.com.
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe from this list, please visit:
>> >>
>> >>    http://xircles.codehaus.org/manage_email
>> >>
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/gsp-syntax-question-tp19243390p19244107.html
>> Sent from the grails - user mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>
>
>
> --
> Fernando "Takai"
> http://flickr.com/photos/supeertakai
> http://fernandotakai.wordpress.com
> http://fernandotakai.jaiku.com
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: gsp syntax question

Robby O'Connor
In reply to this post by a.shneyderman
Model
View
*CONTROLLER*
Alex Shneyderman wrote:

> I do not get these advices of how one should put everything in a
> controller. Why?
>
> You have a date and you want to show only the number of the month. How
> does it warranty code in a controller? Views are there to render the
> result. If rendering means given a date display a month number of that
> date, the view should be able to do it (hence is the word rendering).
>
> I can agree with trying to avoid scriptlets, that is why there are
> taglibs and in GSPs and they are a breeze to create and use, but they
> are part of the view. So, in either case this sort of processing does
> belong to a view IMHO.
>
> Alex.
>
> On Sun, Aug 31, 2008 at 7:42 PM, Fernando Takai
> <[hidden email]> wrote:
>> Well, it's better to add all this processing to the controller.
>>
>> You could do something like this:
>>
>>
>> def calendar = Calendar.getInstance()
>> calendar.setTime(startDate)
>> def startMonthNumber = calendar.get(Calendar.MONTH)
>>
>> return [startMonthNumber: startMonthNumber]
>>
>> IMHO views just show information, delegating processing data to controllers
>> and services.
>>
>>
>> On Sun, Aug 31, 2008 at 2:16 PM, MartinFlower <[hidden email]> wrote:
>>> Dustin, thanks for the explanation - *now* I understand ...
>>>
>>> I've now got :
>>>
>>> def calendar = Calendar.getInstance()
>>> calendar.setTime(startDate)
>>> def startMonthNumber = calendar.get(Calendar.MONTH)
>>>
>>> So, as I see it I have the following options :
>>>
>>> 1. scriptlet (current solution)
>>> 2. write my own tag
>>> 3. put the processing in the controller
>>>
>>> Technically I would prefer option 3, but I haven't got to understanding
>>> Command objects in Grails yet. Until then I'll stick with the scriptlet.
>>>
>>> Martin
>>>
>>>
>>>
>>> Dustin Whitney wrote:
>>>> For this
>>>>
>>>> Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)
>>>>
>>>> your problem is that setTime() has a void return type, so when you call
>>>> get() afterward, you get a NullPointerException.
>>>>
>>>> Honestly in this situation, I'd use a scriptlet:
>>>>
>>>> <%
>>>> def calendar = Calendar.getInstance().setTime(startDate)
>>>> def monthNumber = calendar.get(Calendar.MONTH)
>>>> %>
>>>>
>>>> -Dustin
>>>>
>>>>
>>>> On Sun, Aug 31, 2008 at 11:47 AM, MartinFlower <[hidden email]>
>>>> wrote:
>>>>
>>>>> Hi - getting to grips with gsp tags and syntax and I need a little help
>>>>> please.
>>>>>
>>>>> In the gsp I have a ${startDate} and ${endDate}.  I would like to
>>>>> compare
>>>>> the months of the two dates inside a <g:if /> tag.
>>>>>
>>>>> I have found out that this works :
>>>>>
>>>>> <g:set var="monthNumber"
>>>>> value="${Calendar.getInstance().get(Calendar.MONTH)}" />
>>>>> ${monthNumber}
>>>>>
>>>>> But what I want to do is set the date something like :
>>>>>
>>>>> <g:set var="monthNumber"
>>>>>
>>>>> value="${Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)}"
>>>>> />
>>>>>
>>>>> or
>>>>>
>>>>> <g:set var="monthNumber"
>>>>>
>>>>> value="${Calendar.getInstance().setTime(${startDate}).get(Calendar.MONTH)}"
>>>>> />
>>>>>
>>>>> but these don't work
>>>>>
>>>>> Even this doesn't work
>>>>>
>>>>> <g:set var="monthNumber" value="${Calendar.getInstance().setTime(new
>>>>> Date()).get(Calendar.MONTH)}" />
>>>>>
>>>>> Should it ?
>>>>>
>>>>> Can you see where I'm trying to go ?  Can it be done ?  Many thanks in
>>>>> advance.
>>>>>
>>>>> Martin
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> View this message in context:
>>>>> http://www.nabble.com/gsp-syntax-question-tp19243390p19243390.html
>>>>> Sent from the grails - user mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe from this list, please visit:
>>>>>
>>>>>    http://xircles.codehaus.org/manage_email
>>>>>
>>>>>
>>>>>
>>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/gsp-syntax-question-tp19243390p19244107.html
>>> Sent from the grails - user mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>>    http://xircles.codehaus.org/manage_email
>>>
>>>
>>
>>
>> --
>> Fernando "Takai"
>> http://flickr.com/photos/supeertakai
>> http://fernandotakai.wordpress.com
>> http://fernandotakai.jaiku.com
>>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: gsp syntax question

a.shneyderman
In reply to this post by Dustin Whitney
I guess I was not really clear at what I was getting. Tthe message I
wanted to convey was:

If the logic is a rendering one put it in the view!

I.e. is the row I ittertate over even/odd, formatting dates, getting
parts out of the dates, display or hide a panel based on user's role,
etc.

I did not mean to count lines of code in the scriptlet as indicator
(although if you have more thatn 2/3 shove it into taglib it just
reads better), but please do not go over board with this controller is
the king advice, it is simply wrong. As the matter of fact most of my
controllers have very little logic nowadays as I have delegation to
services; which makes me question the need for controller all-together
except for a hadful of cases.

Alex.

On Mon, Sep 1, 2008 at 8:32 AM, Dustin Whitney <[hidden email]> wrote:

> I agree, and in fact I'd go so far as to say that a 2 or 3 line scriptlet is
> no big deal.  More lines than that is likely a problem, and if your
> scriptlets are common it's a problem, but for the most part, being practical
> with the use of scriptlets and minor processing in the view is no big deal,
> and is ultimately worth it if it saves time.
>
> -Dustin
>
> On Mon, Sep 1, 2008 at 2:18 AM, Alex Shneyderman <[hidden email]>
> wrote:
>>
>> I do not get these advices of how one should put everything in a
>> controller. Why?
>>
>> You have a date and you want to show only the number of the month. How
>> does it warranty code in a controller? Views are there to render the
>> result. If rendering means given a date display a month number of that
>> date, the view should be able to do it (hence is the word rendering).
>>
>> I can agree with trying to avoid scriptlets, that is why there are
>> taglibs and in GSPs and they are a breeze to create and use, but they
>> are part of the view. So, in either case this sort of processing does
>> belong to a view IMHO.
>>
>> Alex.
>>
>> On Sun, Aug 31, 2008 at 7:42 PM, Fernando Takai
>> <[hidden email]> wrote:
>> > Well, it's better to add all this processing to the controller.
>> >
>> > You could do something like this:
>> >
>> >
>> > def calendar = Calendar.getInstance()
>> > calendar.setTime(startDate)
>> > def startMonthNumber = calendar.get(Calendar.MONTH)
>> >
>> > return [startMonthNumber: startMonthNumber]
>> >
>> > IMHO views just show information, delegating processing data to
>> > controllers
>> > and services.
>> >
>> >
>> > On Sun, Aug 31, 2008 at 2:16 PM, MartinFlower <[hidden email]>
>> > wrote:
>> >>
>> >> Dustin, thanks for the explanation - *now* I understand ...
>> >>
>> >> I've now got :
>> >>
>> >> def calendar = Calendar.getInstance()
>> >> calendar.setTime(startDate)
>> >> def startMonthNumber = calendar.get(Calendar.MONTH)
>> >>
>> >> So, as I see it I have the following options :
>> >>
>> >> 1. scriptlet (current solution)
>> >> 2. write my own tag
>> >> 3. put the processing in the controller
>> >>
>> >> Technically I would prefer option 3, but I haven't got to understanding
>> >> Command objects in Grails yet. Until then I'll stick with the
>> >> scriptlet.
>> >>
>> >> Martin
>> >>
>> >>
>> >>
>> >> Dustin Whitney wrote:
>> >> >
>> >> > For this
>> >> >
>> >> > Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)
>> >> >
>> >> > your problem is that setTime() has a void return type, so when you
>> >> > call
>> >> > get() afterward, you get a NullPointerException.
>> >> >
>> >> > Honestly in this situation, I'd use a scriptlet:
>> >> >
>> >> > <%
>> >> > def calendar = Calendar.getInstance().setTime(startDate)
>> >> > def monthNumber = calendar.get(Calendar.MONTH)
>> >> > %>
>> >> >
>> >> > -Dustin
>> >> >
>> >> >
>> >> > On Sun, Aug 31, 2008 at 11:47 AM, MartinFlower <[hidden email]>
>> >> > wrote:
>> >> >
>> >> >>
>> >> >> Hi - getting to grips with gsp tags and syntax and I need a little
>> >> >> help
>> >> >> please.
>> >> >>
>> >> >> In the gsp I have a ${startDate} and ${endDate}.  I would like to
>> >> >> compare
>> >> >> the months of the two dates inside a <g:if /> tag.
>> >> >>
>> >> >> I have found out that this works :
>> >> >>
>> >> >> <g:set var="monthNumber"
>> >> >> value="${Calendar.getInstance().get(Calendar.MONTH)}" />
>> >> >> ${monthNumber}
>> >> >>
>> >> >> But what I want to do is set the date something like :
>> >> >>
>> >> >> <g:set var="monthNumber"
>> >> >>
>> >> >>
>> >> >> value="${Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)}"
>> >> >> />
>> >> >>
>> >> >> or
>> >> >>
>> >> >> <g:set var="monthNumber"
>> >> >>
>> >> >>
>> >> >> value="${Calendar.getInstance().setTime(${startDate}).get(Calendar.MONTH)}"
>> >> >> />
>> >> >>
>> >> >> but these don't work
>> >> >>
>> >> >> Even this doesn't work
>> >> >>
>> >> >> <g:set var="monthNumber" value="${Calendar.getInstance().setTime(new
>> >> >> Date()).get(Calendar.MONTH)}" />
>> >> >>
>> >> >> Should it ?
>> >> >>
>> >> >> Can you see where I'm trying to go ?  Can it be done ?  Many thanks
>> >> >> in
>> >> >> advance.
>> >> >>
>> >> >> Martin
>> >> >>
>> >> >>
>> >> >>
>> >> >> --
>> >> >> View this message in context:
>> >> >> http://www.nabble.com/gsp-syntax-question-tp19243390p19243390.html
>> >> >> Sent from the grails - user mailing list archive at Nabble.com.
>> >> >>
>> >> >>
>> >> >>
>> >> >> ---------------------------------------------------------------------
>> >> >> To unsubscribe from this list, please visit:
>> >> >>
>> >> >>    http://xircles.codehaus.org/manage_email
>> >> >>
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >>
>> >> --
>> >> View this message in context:
>> >> http://www.nabble.com/gsp-syntax-question-tp19243390p19244107.html
>> >> Sent from the grails - user mailing list archive at Nabble.com.
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe from this list, please visit:
>> >>
>> >>    http://xircles.codehaus.org/manage_email
>> >>
>> >>
>> >
>> >
>> >
>> > --
>> > Fernando "Takai"
>> > http://flickr.com/photos/supeertakai
>> > http://fernandotakai.wordpress.com
>> > http://fernandotakai.jaiku.com
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: gsp syntax question

olivier_f
In reply to this post by Robby O'Connor
Hi,
I would implement the following logic.

The controller controller is responsible of the business logic. So in this case, to  provide the date of the day.
it returns a java Date instance.

The view is responsible of the display of this Date instance.
And to do this, it's easy to create your own tag to embed java.text.SimpleDateFormat
Then you can have a generic tag component.
There is an example in the doc, btw : http://grails.org/doc/1.0.x/ref/Tag%20Libraries/Usage.html

Olivier.


2008/9/1 Robby O'Connor <[hidden email]>
Model
View
*CONTROLLER*
Alex Shneyderman wrote:
I do not get these advices of how one should put everything in a
controller. Why?

You have a date and you want to show only the number of the month. How
does it warranty code in a controller? Views are there to render the
result. If rendering means given a date display a month number of that
date, the view should be able to do it (hence is the word rendering).

I can agree with trying to avoid scriptlets, that is why there are
taglibs and in GSPs and they are a breeze to create and use, but they
are part of the view. So, in either case this sort of processing does
belong to a view IMHO.

Alex.

On Sun, Aug 31, 2008 at 7:42 PM, Fernando Takai
<[hidden email]> wrote:
Well, it's better to add all this processing to the controller.

You could do something like this:


def calendar = Calendar.getInstance()
calendar.setTime(startDate)
def startMonthNumber = calendar.get(Calendar.MONTH)

return [startMonthNumber: startMonthNumber]

IMHO views just show information, delegating processing data to controllers
and services.


On Sun, Aug 31, 2008 at 2:16 PM, MartinFlower <[hidden email]> wrote:
Dustin, thanks for the explanation - *now* I understand ...

I've now got :

def calendar = Calendar.getInstance()
calendar.setTime(startDate)
def startMonthNumber = calendar.get(Calendar.MONTH)

So, as I see it I have the following options :

1. scriptlet (current solution)
2. write my own tag
3. put the processing in the controller

Technically I would prefer option 3, but I haven't got to understanding
Command objects in Grails yet. Until then I'll stick with the scriptlet.

Martin



Dustin Whitney wrote:
For this

Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)

your problem is that setTime() has a void return type, so when you call
get() afterward, you get a NullPointerException.

Honestly in this situation, I'd use a scriptlet:

<%
def calendar = Calendar.getInstance().setTime(startDate)
def monthNumber = calendar.get(Calendar.MONTH)
%>

-Dustin


On Sun, Aug 31, 2008 at 11:47 AM, MartinFlower <[hidden email]>
wrote:

Hi - getting to grips with gsp tags and syntax and I need a little help
please.

In the gsp I have a ${startDate} and ${endDate}.  I would like to
compare
the months of the two dates inside a <g:if /> tag.

I have found out that this works :

<g:set var="monthNumber"
value="${Calendar.getInstance().get(Calendar.MONTH)}" />
${monthNumber}

But what I want to do is set the date something like :

<g:set var="monthNumber"

value="${Calendar.getInstance().setTime(startDate).get(Calendar.MONTH)}"
/>

or

<g:set var="monthNumber"

value="${Calendar.getInstance().setTime(${startDate}).get(Calendar.MONTH)}"
/>

but these don't work

Even this doesn't work

<g:set var="monthNumber" value="${Calendar.getInstance().setTime(new
Date()).get(Calendar.MONTH)}" />

Should it ?

Can you see where I'm trying to go ?  Can it be done ?  Many thanks in
advance.

Martin



--
View this message in context:
http://www.nabble.com/gsp-syntax-question-tp19243390p19243390.html
Sent from the grails - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email




--
View this message in context:
http://www.nabble.com/gsp-syntax-question-tp19243390p19244107.html
Sent from the grails - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email




--
Fernando "Takai"
http://flickr.com/photos/supeertakai
http://fernandotakai.wordpress.com
http://fernandotakai.jaiku.com


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email





---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email



Loading...