i've thought about suggesting this in the past as well.  it would be very cool.

On Thu, 6 Jan 2005 13:21:27 -0800, Will Glass-Husain <[EMAIL PROTECTED]> wrote:
> That's a clever idea for a shortcut.  I use the #if / #foreach combination
> all the time.  It's not a big deal, but the multiple #end can be confusing.
> 
> WILL
> 
> ----- Original Message -----
> From: "specialist33" <[EMAIL PROTECTED]>
> To: "Velocity Developers List" <[email protected]>
> Sent: Thursday, January 06, 2005 12:32 PM
> Subject: Just a thought...foreach else ?
> 
> > Looking through our templteas written over the last few months, we have a
> > LOT of cases of guarding on an empty foreach - empty means either
> > something went wrong OR we need an explicit "no results returned" message.
> >
> > One of the problmes with the previous engine we used was that you couldn't
> > easily detect empty results sets, so we had lots of blanks where users
> > didn't realise something was SUPPOSED to be there.
> >
> > So now we have:
> >
> > #set( $result = some method to get the data )
> >
> > #if( $result && $result.size() > 0 )
> >
> > #foreach( $item in $result )
> > ...
> > #end
> >
> > #else
> > No results! Was expecting some here. The "some method" hasn't worked,
> > please tell an admin. Whatever. Your message goes here :)
> > #end
> >
> > Which, I realised, would work much more nicely as:
> >
> > #foreach( $r in $result )
> > ...
> > #else
> > No results found. Error message. Etc.
> > #end
> >
> > Now, not only does this make a lot of sense and cut out a lot of typing
> > but it has another handy feature: it removes the explicit "size()".
> > Unfortunately, Sun are poor at their own standards, and on some data you
> > have "length()" on others "length" on others "size()" - but NONE of these
> > are valid javabeans (you do sometimes see "getSize()" too but I can't
> > think of an example in a Sun API right now...).
> >
> > So, $result.size doesn't work and you must have the () - which looks very
> > strange if you're using the beanshell shortcuts all over the rest of hte
> > template.
> >
> > We had a LOT of bugs where people didn't realise this, or saw the () and
> > thought it was a mistake, seeing as nothing else had it. Even I made the
> > mistake a couple of times (weeks apart) before I memorized it.
> >
> > So...if we encoded the algorithm for picking legnths/sizes and checking if
> >  > 0 (where null ref is treated as 0, which is mathematically accurate :))
> > then we remove this convoluted and irritating and confusing (but short!)
> > algorihtm from the heads of all the VTL users and put it into the engine.
> >
> > PS sorry if this has already been proposed, but I had a quick search and
> > didn't notice it anywhere
> >
> > Thoughts? Should be quick n easy to implement I suspect if you're already
> > familiar with the VTL code?
> >
> > PPS don't ask me to fill a BZ bug. When you remove the account-creation BS
> > so I don't have to faff about creating an account, waiting for an email,
> > etc, I'll use BZ. Until then - no way. Honestly I would be *very* happy to
> > file RFE's directly if there were no hassle...
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to