gsp set tag not working?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

gsp set tag not working?

Steve Tekell
I am going crazy,
what's wrong with this?

 <g:def var='test' value='111' />${test} <br/>
 <g:set var='test' value='222' />${test} <br/>

the set doesn't occur and it prints
111
111


jja
Reply | Threaded
Open this post in threaded view
|

Re: gsp set tag not working?

jja
> I am going crazy,
> what's wrong with this?
>
>  <g:def var='test' value='111' />${test} <br/>
>  <g:set var='test' value='222' />${test} <br/>
>
> the set doesn't occur and it prints
> 111
> 111

I ran into that too. It worked in 0.5.6 and I was following
that idiom as it's similar to controller code, which requires
a def before a set (otherwise you get a groovy.lang.MissingPropertyException):

  def test = 111
  ...
  test = 222

But in 1.0, it seems g:def acts more like creating a constant.

Try using g:set everywhere and never use g:def.
That works for me in 0.5.6 and 1.0-RC2-SNAPSHOT.

Will this change in future?
Will GSP tags require a g:def before a g:set?

John Allison
[hidden email]

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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: gsp set tag not working?

Steve Tekell
many thanks!

Either this is a workaround for a bug or the documentation is incorrect.  I hope it's considered a bug, but I didn't find it in JIRA with a only quick search.  It's inconsistent for g:def to create a constant when def doesn't in Groovy.  Also it's not really creating something immutable, since you can still set it with a scriptlet.

e.g.,

<g:def var='test' value='111' />${test} <br/>
<g:set var='test' value='222' />${test} <br/>
<% test='333' %>${test} <br/>

will print
111
111
333


Steve

jja-3 wrote
> I am going crazy,
> what's wrong with this?
>
>  <g:def var='test' value='111' />${test} <br/>
>  <g:set var='test' value='222' />${test} <br/>
>
> the set doesn't occur and it prints
> 111
> 111

I ran into that too. It worked in 0.5.6 and I was following
that idiom as it's similar to controller code, which requires
a def before a set (otherwise you get a groovy.lang.MissingPropertyException):

  def test = 111
  ...
  test = 222

But in 1.0, it seems g:def acts more like creating a constant.

Try using g:set everywhere and never use g:def.
That works for me in 0.5.6 and 1.0-RC2-SNAPSHOT.

Will this change in future?
Will GSP tags require a g:def before a g:set?

John Allison
jja@ucar.edu

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

    http://xircles.codehaus.org/manage_email
jja
Reply | Threaded
Open this post in threaded view
|

Re: gsp set tag not working?

jja
In reply to this post by jja
Wow, it turns out the def tag is deprecated. See line 39 of the source:

http://fisheye.codehaus.org/browse/grails/trunk/grails/src/web/org/codehaus/groovy/grails/web/taglib/GroovyDefTag.java?r=5744#l39

Too bad I've never seen the deprecation message.

I've edited the wiki doc.

John

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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Problem with URL mapping

jens.riboe
Hi,

I'm trying to map an URL like
        /theApp/download/17/someName.p12

using
class UrlMappings {
    static mappings = {
        "/download/$id/${name}.p12" {
            controller = "certificate"
            action     = "downloadPKCS12"
        }

        "/$controller/$action?/$id?" {
            constraints {
                // apply constraints here
            }
        }
    }
}

However, I'm getting "Error 404 - Not Found."

The important parts of the path is the id and that the file name ends
in .p12, to choose the right action.

Any light on this is highly appreciated.
        /jens



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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Problem with URL mapping

jens.riboe
OK. Found it!

 "/download/$id/*.p12" {...}

I suggest the page http://grails.codehaus.org/URL+mapping gets updated
with the info that one can use wild card stars as well.

Regards /jens


On Thu, 2007-11-08 at 22:31 +0100, Jens Riboe wrote:

> Hi,
>
> I'm trying to map an URL like
> /theApp/download/17/someName.p12
>
> using
> class UrlMappings {
>     static mappings = {
>         "/download/$id/${name}.p12" {
>             controller = "certificate"
>             action     = "downloadPKCS12"
>         }
>
>         "/$controller/$action?/$id?" {
>             constraints {
>                 // apply constraints here
>             }
>         }
>     }
> }
>
> However, I'm getting "Error 404 - Not Found."
>
> The important parts of the path is the id and that the file name ends
> in .p12, to choose the right action.
>
> Any light on this is highly appreciated.
> /jens
>
>
>
> ---------------------------------------------------------------------
> 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