You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Rich Aston <ri...@thenetrevolution.com> on 2001/04/20 18:09:47 UTC

Select Box and Velocity

What is the recommended way of building select boxes with turbine and 
velocity?

Is there an equivalent of the SelectorBox class that works with velocity 
and a vector of Data objects?

Cheers,

Rich

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


HTML Widgetss (was: select Box and Velocity)

Posted by Jason van Zyl <jv...@apache.org>.
Nathan Bubna wrote:
> 
> try using a macro like this...
> 
> #macro ( generateSelectBox $name $options $selectedvalue)
>     <select name=$name>
>     #set ($count = 1)
>     #foreach( $option in $options )
>         #if ($selectedvalue)
>             <option value=$count #if ($count == $selectedvalue)
> selected="1"#end>$option</option>
>         #else
>             <option value=$count>$option</option>
>         #end
> 
>         #set ($count = $count + 1)
>     #end
>     </select>
> #end

Cool! Does anyone else have macros like this? It might be nice to
collect
all these HTML widget macros and collect them somewhere so that we
can all use them. I will collect them all and either put them in the
velocity CVS and make them available in the TDK for general use, or
keep them in Turbine CVS. We'll figure the storage out. But having
a widget library would be great!


> > What is the recommended way of building select boxes with turbine and
> > velocity?
> >
> > Is there an equivalent of the SelectorBox class that works with velocity
> > and a vector of Data objects?
> >
> > Cheers,
> >
> > Rich
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org

-- 
jvz.

Jason van Zyl
jvanzyl@apache.org

http://jakarta.apache.org/velocity
http://jakarta.apache.org/turbine
http://jakarta.apache.org/commons
http://tambora.zenplex.org

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Select Box and Velocity

Posted by Nathan Bubna <na...@esha.com>.
this also belongs on the velocity list, not the turbine one.

> Nathan,
>
> Thanks that's a great start -- but how do you build your $options array
> from a Vector of data objects? Say I've got a Vector of Book objects and
> I want to build the select box from $book.getTitle()?

you can either put some form of array (ArrayList, Vector, etc) in the
context and pass that into the macro, or you can create the options right in
your template like this...

    #set ($myoptions = ["Choose Gender", "Male", "Female"] )

    ##and then call the macro

    #generateSelectBox ( "gender" $myoptions 1 )


> Cheers
>
> Rich
>
> On Friday, April 20, 2001, at 05:20  pm, Nathan Bubna wrote:
>
> > try using a macro like this...
> >
> > #macro ( generateSelectBox $name $options $selectedvalue)
> >     <select name=$name>
> >     #set ($count = 1)
> >     #foreach( $option in $options )
> >         #if ($selectedvalue)
> >             <option value=$count #if ($count == $selectedvalue)
> > selected="1"#end>$option</option>
> >         #else
> >             <option value=$count>$option</option>
> >         #end
> >
> >         #set ($count = $count + 1)
> >     #end
> >     </select>
> > #end
> >
> >
> >> What is the recommended way of building select boxes with turbine and
> >> velocity?
> >>
> >> Is there an equivalent of the SelectorBox class that works with
> >> velocity
> >> and a vector of Data objects?
> >>
> >> Cheers,
> >>
> >> Rich
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> >>
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>
>



Re: Select Box and Velocity

Posted by Rich Aston <ri...@thenetrevolution.com>.
> <select name=blah>
> #foreach ( $book in $myBooks )
>   <option value="$book.ID">$book.Title
> #end
> </select>

I've got velocity building select boxes -- that's no problem. What I'm 
looking for is a convenience function for my template designers to use. 
Say they are creating a form to edit a user record containing the user 
name and their country.

The name part is easy:

   Last Name: <input type="text" name="lastname" value="$user.LastName">

The country is much more difficult. I would like to pull a Vector of 
countries (that has come via peers from a COUNTRY table in my database) 
so they could do something like this:

   #set ($countries = $countrytool.getCountries() )

   Country: #selectBox( "country" $countries "CountryId" "CountryName" 
$user.country )

   ## CountryId is the name of the property to use as the value and 
CountryName is to be used as the label in the list
   ## $user.country is the user's current country that should be selected 
by default

This would generate the <select> and <option> tags and stick <option 
selected> next to the selected one. I don't think the template designer 
should have to code a #foreach loop with a #if statement to place the 
"selected" for something as common as a select box. If there's no such 
function available I'd be happy to code one if someone could give me an 
idea of the best way do this (as a velocity macro or toolbox?).

Cheers

Rich

ps i'm keeping this on turbine-user because the bit i'm having trouble 
with is working with the data objects generated with Peers -- not the 
VTL.

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Select Box and Velocity

Posted by Steve Ruby <st...@rubysolutions.com>.
Rich Aston wrote:
> 
> Nathan,
> 
> Thanks that's a great start -- but how do you build your $options array
> from a Vector of data objects? Say I've got a Vector of Book objects and
> I want to build the select box from $book.getTitle()?
> 
> Cheers
> 
> Rich


<select name=blah>
#foreach ( $book in $myBooks )
  <option value="$book.ID">$book.Title
#end
</select>

assuming that myBooks is a Vector of book objects and that
the value is in book.getID() and shown option is book.getTitle()

remember that with velocity
book.ID will be expanded to book.getID()



> 
> On Friday, April 20, 2001, at 05:20  pm, Nathan Bubna wrote:
> 
> > try using a macro like this...
> >
> > #macro ( generateSelectBox $name $options $selectedvalue)
> >     <select name=$name>
> >     #set ($count = 1)
> >     #foreach( $option in $options )
> >         #if ($selectedvalue)
> >             <option value=$count #if ($count == $selectedvalue)
> > selected="1"#end>$option</option>
> >         #else
> >             <option value=$count>$option</option>
> >         #end
> >
> >         #set ($count = $count + 1)
> >     #end
> >     </select>
> > #end
> >
> >
> >> What is the recommended way of building select boxes with turbine and
> >> velocity?
> >>
> >> Is there an equivalent of the SelectorBox class that works with
> >> velocity
> >> and a vector of Data objects?
> >>
> >> Cheers,
> >>
> >> Rich
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> >>
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Select Box and Velocity

Posted by Nathan Bubna <na...@esha.com>.
this also belongs on the velocity list, not the turbine one.

> Nathan,
>
> Thanks that's a great start -- but how do you build your $options array
> from a Vector of data objects? Say I've got a Vector of Book objects and
> I want to build the select box from $book.getTitle()?

you can either put some form of array (ArrayList, Vector, etc) in the
context and pass that into the macro, or you can create the options right in
your template like this...

    #set ($myoptions = ["Choose Gender", "Male", "Female"] )

    ##and then call the macro

    #generateSelectBox ( "gender" $myoptions 1 )


> Cheers
>
> Rich
>
> On Friday, April 20, 2001, at 05:20  pm, Nathan Bubna wrote:
>
> > try using a macro like this...
> >
> > #macro ( generateSelectBox $name $options $selectedvalue)
> >     <select name=$name>
> >     #set ($count = 1)
> >     #foreach( $option in $options )
> >         #if ($selectedvalue)
> >             <option value=$count #if ($count == $selectedvalue)
> > selected="1"#end>$option</option>
> >         #else
> >             <option value=$count>$option</option>
> >         #end
> >
> >         #set ($count = $count + 1)
> >     #end
> >     </select>
> > #end
> >
> >
> >> What is the recommended way of building select boxes with turbine and
> >> velocity?
> >>
> >> Is there an equivalent of the SelectorBox class that works with
> >> velocity
> >> and a vector of Data objects?
> >>
> >> Cheers,
> >>
> >> Rich
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> >>
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Select Box and Velocity

Posted by Rich Aston <ri...@thenetrevolution.com>.
Nathan,

Thanks that's a great start -- but how do you build your $options array 
from a Vector of data objects? Say I've got a Vector of Book objects and 
I want to build the select box from $book.getTitle()?

Cheers

Rich

On Friday, April 20, 2001, at 05:20  pm, Nathan Bubna wrote:

> try using a macro like this...
>
> #macro ( generateSelectBox $name $options $selectedvalue)
>     <select name=$name>
>     #set ($count = 1)
>     #foreach( $option in $options )
>         #if ($selectedvalue)
>             <option value=$count #if ($count == $selectedvalue)
> selected="1"#end>$option</option>
>         #else
>             <option value=$count>$option</option>
>         #end
>
>         #set ($count = $count + 1)
>     #end
>     </select>
> #end
>
>
>> What is the recommended way of building select boxes with turbine and
>> velocity?
>>
>> Is there an equivalent of the SelectorBox class that works with 
>> velocity
>> and a vector of Data objects?
>>
>> Cheers,
>>
>> Rich
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Select Box and Velocity

Posted by Nathan Bubna <na...@esha.com>.
try using a macro like this...

#macro ( generateSelectBox $name $options $selectedvalue)
    <select name=$name>
    #set ($count = 1)
    #foreach( $option in $options )
        #if ($selectedvalue)
            <option value=$count #if ($count == $selectedvalue)
selected="1"#end>$option</option>
        #else
            <option value=$count>$option</option>
        #end

        #set ($count = $count + 1)
    #end
    </select>
#end


> What is the recommended way of building select boxes with turbine and
> velocity?
>
> Is there an equivalent of the SelectorBox class that works with velocity
> and a vector of Data objects?
>
> Cheers,
>
> Rich
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org