logo       

Re: Variable defined (or not): msg#00125

lang.groovy.user

Subject: Re: Variable defined (or not)

Hi Shijun,

Try to check:
http://archive.groovy.codehaus.org/dev/threads/olbhcankeidijjpbemhk

Kim


On Sun, Oct 17, 2004 at 12:41:26PM +0800, Shijun He wrote:
> it seems that beta-7 had changed behavior of undefined var. See:
> [GROOVY-579]: http://jira.codehaus.org/browse/GROOVY-579
>
> but it affacts lot.
> For example, Groovlet now can't get param as usual!
>
> i write a single line groovlet
> test.gl
> -------
> out << request.parameterMap
>
> http://localhost/test/test.gl?foo
>
> HTTP Status 500 -
>
> type Exception report
>
> message
>
> description The server encountered an internal error () that prevented
> it from fulfilling this request.
>
> exception
>
> groovy.lang.MissingPropertyException: No such property: a for class:
> groovy.lang.Binding
> groovy.lang.Binding.getVariable(Binding.java:88)
> groovy.servlet.GroovyServlet.service(GroovyServlet.java:145)
>
> note The full stack trace of the root cause is available in the Apache
> Tomcat/5.0.28 logs.
>
>
> but this works http://localhost/test/test.gl?out=foo&request=foo2
> output:
> [out:[foo], request:[foo2]]
>
>
>
> Has anybody fixed it?
>
> On Sat, 16 Oct 2004 20:38:57 +0900,
> phkim-Yd8/yUic+sk+MW+wcPHoAA@xxxxxxxxxxxxxxxx
> <phkim-Yd8/yUic+sk+MW+wcPHoAA@xxxxxxxxxxxxxxxx> wrote:
> > Hi, juhani
> >
> > if(binding.getVariables().get('a')!=null)
> > b=[5, 9, 2, 2, 4, 5, 6].join("abc");
> > else
> > b=[5, 9, 2, 2, 4, 5, 6].join(" - ");
> >
> > This will help you.
> >
> > Kim
> >
> > On Sat, Oct 16, 2004 at 12:03:24AM -0700, juhani wrote:
> > > Thanks! Groovy is embedded and called from servlet (data contains
> > > request parameters as HashMap):
> > > ========================================= Servlet clip:
> > > groovy.lang.Binding binding = new groovy.lang.Binding(data);
> > > GroovyShell shell = new GroovyShell(binding);
> > > shell.evaluate( new File(fileName) );
> > > ========================================= Testfile:
> > > if(a!=null)
> > > b=[5, 9, 2, 2, 4, 5, 6].join("abc");
> > > else
> > > b=[5, 9, 2, 2, 4, 5, 6].join(" - ");
> > > ========================================= Results exception:
> > > groovy.lang.MissingPropertyException: No such property: a for class:
> > > groovy
> > > at groovy.lang.MetaClass.getProperty(MetaClass.java:697)
> > > - -
> > >
> > > --- Jeremy Rayner <groovy-WROaGtoGdBGWkzVdRvz7FA@xxxxxxxxxxxxxxxx> wrote:
> > > > On Fri, Oct 15, 2004 at 04:28:58AM -0700, juhani wrote:
> > > > > Hi! How do you test if variable is defined or not?
> > > > Hi, not sure of the context in which you're thinking,
> > > > but inside a groovy script all variables are an object
> > > > so a simple test for null should do the trick
> > > > if (foo != null) {
> > > > println foo
> > > > } else {
> > > > println "foo is undefined"
> > > > }
> > > > Hope that helps
> > >
> > >
> > >
> > >
> > > __________________________________
> > > Do you Yahoo!?
> > > Yahoo! Mail Address AutoComplete - You start. We finish.
> > > http://promotions.yahoo.com/new_mail
> >



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise