Thanks. Will do that.

On 3/16/06, Nathan Bubna <[EMAIL PROTECTED]> wrote:
>
> Yes, this behavior is to be expected.  Unlike java, Velocity does not
> create a new scope/namespace for each iteration in a #foreach loop.
> so if col-size is set to value A in the first iteration, then it will
> still have value A in the subsequent iterations until it is set again.
>
> so, just try doing a #set( $col-size = false ) or something like that
> at the end of every iteration.
>
> On 3/16/06, Piyush Purang <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > I have a foreach loop in my template. I set a variable 'col-size' and
> then
> > test if it's length > 0 to try and determine if it exists or not.
> >
> > The problem is that the condition evaluates true if in the previous
> > iteration col-size.length() was greater than 0 i.e. col-size retains the
> > value from the previous iteration..
> >
> > Is that intended? If yes then is there a way of changing the behaviour.
> >
> > Or is it a faulty template?
> >
> > Here is the code (it is part of a template that reads an XML file and
> > outputs an SQL dump file)
> >
> >
> > #foreach($col in $cols)
> >         #set($col-name=$col.getAttribute($col-attr-name).getValue())
> >         #set($col-type=$col.getAttribute($col-attr-type).getValue())
> >
> > #set($col-size=$col.getAttribute($col-attr-size).getValue())
> > ## the variable of interest...
> >
> > #set($col-percision=$col.getAttribute($col-attr-percision).getValue())
> >
> #set($col-not-null=$col.getAttribute($col-attr-not-null).getValue())
> >
> #set($col-default=$col.getAttribute($col-attr-default).getValue())
> >         $col-name $col-type #if($col-size.length() >
> 0)($col-size#if($col-
> > percision.length() > 0),$col-percision#end)#end
> > #if($col-default.length()>0)DEFAULT
> > $col-default#end #if($col-not-null)NOT NULL#end,
> >
> > #end  ##ends foreach
> >
> >
> > Thanks for clarifying things.
> >
> > Cheers
> > Piyush
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to