You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Brian Hall <ne...@giant.net.au> on 2001/10/24 14:30:03 UTC
Rendering Frames and Concatonating Strings & Background Images
I have three quick (I hope) questions about rendering of the
templates.
1. Can a template be in the form of a framed page? I would like to
have an html banner across the top, a permanent search panel vm
on the left and a results vm on the right.
2. In a displayed template, I would like to display the output from a
database search in text boxes with a #foreach statement, allowing
the user to edit the results and post the changes back to the
database. I did this with a for loop in a jsp by concatonating the
textbox name with an int counter eg:
for(int i = 1; i < resultSet.size(); i++)
textboxes would be named: "Name" + i, "Address" + i, "Email" + i,
etc, then similarly in the servlet, the data to be sent to the database
was received by:
name = request.getParameter("Name" + i); etc.
I can't see an example of concationation in the manuals or
examples. Can it be done?
3, I tried to put a <body background="by9.gif" > statement into the
template but the background image would not render. Can it be
done or is it simply that it can't find the image file? I tried locating it
in all the subdirectories.
Thanks
Brian Hall
Re: Rendering Frames and Concatonating Strings & Background Images
Posted by Bojan Smojver <bo...@binarix.com>.
Brian Hall wrote:
>
> I have three quick (I hope) questions about rendering of the
> templates.
>
> 1. Can a template be in the form of a framed page? I would like to
> have an html banner across the top, a permanent search panel vm
> on the left and a results vm on the right.
So, you're having three frames here, which makes it 4 HTML pages in
total. I guess you'd have to have 4 VM pages or less (if you choose to
keep some as static HTML - good for speed) for this.
> 2. In a displayed template, I would like to display the output from a
> database search in text boxes with a #foreach statement, allowing
> the user to edit the results and post the changes back to the
> database. I did this with a for loop in a jsp by concatonating the
> textbox name with an int counter eg:
> for(int i = 1; i < resultSet.size(); i++)
> textboxes would be named: "Name" + i, "Address" + i, "Email" + i,
> etc, then similarly in the servlet, the data to be sent to the database
> was received by:
> name = request.getParameter("Name" + i); etc.
>
> I can't see an example of concationation in the manuals or
> examples. Can it be done?
To concatenate string and the reference in the output you can do this:
-----------------------------------------
${reference}text
-----------------------------------------
If $reference value is "some", Velocity renders as:
-----------------------------------------
sometext
-----------------------------------------
So, I'm guessing you're trying to do this:
-----------------------------------------
#foreach($some in $thelot)
Name: <input type="text" name="Name${velocityCount}"
value="$!{some.name}"/><br/>
Email: <input type="text" name="Email${velocityCount}"
value="$!{some.email}"/><br/>
..
#end
-----------------------------------------
provided that $thelot is an array of Properties or similar. By default
$velocityCount starts at 1, but it can be changed.
> 3, I tried to put a <body background="by9.gif" > statement into the
> template but the background image would not render. Can it be
> done or is it simply that it can't find the image file? I tried locating it
> in all the subdirectories.
I'm pretty sure that this GIF file cannot be found. Check you web server
log files. There is no other reason why Velocity HTML would be any
different to any other HTML to the browser. The rendering in the browser
works so that every link within the page is resolved by sending a
request back to the server. The same applies to this page.
Most of the answers to your questions already exist in the excellent
Velocity User's Guide. Check it out.
Bojan
Re: Rendering Frames and Concatonating Strings & Background Images
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 10/25/01 2:51 AM, "Skondras Panagiotis" <pa...@acn.gr> wrote:
>
>
> Brian Hall wrote:
>
>> I have three quick (I hope) questions about rendering of the
>> templates.
>>
>> 1. Can a template be in the form of a framed page? I would like to
>> have an html banner across the top, a permanent search panel vm
>> on the left and a results vm on the right.
>>
>
> Yes you can. like this this is a frameset
>
> #set ($h=30)
> #if ( $is_ie )
> #set ($h=30)
> #end
> <FRAMESET cols="200,*" FRAMEBORDER="1" BORDER="1" framespacing="1">
> <FRAME
> SRC=$link.setPage("foo.vm").
> name="left" FRAMEBORDER="1" BORDER="1" framespacing="1" scrolling="NO">
> <FRAME SRC=$link.setPage("foo1.vm") NAME="right" FRAMEBORDER="1"
> BORDER="1" framespacing="0"
> scrolling="YES">
> </FRAMESET>
>>
>> 3, I tried to put a <body background="by9.gif" > statement into the
>> template but the background image would not render. Can it be
>> done or is it simply that it can't find the image file? I tried locating it
>> in all the subdirectories.
>>
>
> Yes like this
> $page.setBackground($content.getURI($skin.BgImg))
>
> $skin.BgImg is the image name
>
Note that these two answers are Turbine specific, I believe, and would only
apply if you were using Turbine.
Velocity has no $page or $content objects that it places in the context.
Geir
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin
Re: Rendering Frames and Concatonating Strings & Background Images
Posted by Skondras Panagiotis <pa...@acn.gr>.
Brian Hall wrote:
> I have three quick (I hope) questions about rendering of the
> templates.
>
> 1. Can a template be in the form of a framed page? I would like to
> have an html banner across the top, a permanent search panel vm
> on the left and a results vm on the right.
>
Yes you can. like this this is a frameset
#set ($h=30)
#if ( $is_ie )
#set ($h=30)
#end
<FRAMESET cols="200,*" FRAMEBORDER="1" BORDER="1" framespacing="1">
<FRAME
SRC=$link.setPage("foo.vm").
name="left" FRAMEBORDER="1" BORDER="1" framespacing="1" scrolling="NO">
<FRAME SRC=$link.setPage("foo1.vm") NAME="right" FRAMEBORDER="1"
BORDER="1" framespacing="0"
scrolling="YES">
</FRAMESET>
>
> 2. In a displayed template, I would like to display the output from a
> database search in text boxes with a #foreach statement, allowing
> the user to edit the results and post the changes back to the
> database. I did this with a for loop in a jsp by concatonating the
> textbox name with an int counter eg:
> for(int i = 1; i < resultSet.size(); i++)
> textboxes would be named: "Name" + i, "Address" + i, "Email" + i,
> etc, then similarly in the servlet, the data to be sent to the database
> was received by:
> name = request.getParameter("Name" + i); etc.
>
> I can't see an example of concationation in the manuals or
> examples. Can it be done?
Yes like this if you want to start from 1 and up and your velocityCount is
defined to start from 0
#set ($count=0)
#foreach ($type in $ADDEXTRAFIELDS)
#set ($count=$velocityCount+1)
<INPUT NAME="item_$count" TYPE="text" value="" length=50 >
#end
>
>
> 3, I tried to put a <body background="by9.gif" > statement into the
> template but the background image would not render. Can it be
> done or is it simply that it can't find the image file? I tried locating it
> in all the subdirectories.
>
Yes like this
$page.setBackground($content.getURI($skin.BgImg))
$skin.BgImg is the image name
> Thanks
> Brian Hall
Re: Rendering Frames and Concatonating Strings & Background Images
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 10/24/01 8:30 AM, "Brian Hall" <ne...@giant.net.au> wrote:
> I have three quick (I hope) questions about rendering of the
> templates.
>
> 1. Can a template be in the form of a framed page? I would like to
> have an html banner across the top, a permanent search panel vm
> on the left and a results vm on the right.
Yes. Very possible (I do it all the time.)
I do it with #parse() mostly :
<table>
<tr>
<td colspan=2> #parse($header) </td>
</tr>
<tr>
<td>
#parse($search) {or put in HTML}
</td>
<td>
#parse($mainbody)
</td>
</tr>
</table>
(any of those #parse() could be static HTML, or a combination...)
>
> 2. In a displayed template, I would like to display the output from a
> database search in text boxes with a #foreach statement, allowing
> the user to edit the results and post the changes back to the
> database. I did this with a for loop in a jsp by concatonating the
> textbox name with an int counter eg:
> for(int i = 1; i < resultSet.size(); i++)
> textboxes would be named: "Name" + i, "Address" + i, "Email" + i,
> etc, then similarly in the servlet, the data to be sent to the database
> was received by:
> name = request.getParameter("Name" + i); etc.
>
> I can't see an example of concationation in the manuals or
> examples. Can it be done?
Sure. Just put things next to eash other :
#foreach( $i in [1..5])
<a href="FooServlet?Name$i=value$I">Thingy$I</a>
#end
> 3, I tried to put a <body background="by9.gif" > statement into the
> template but the background image would not render. Can it be
> done or is it simply that it can't find the image file? I tried locating it
> in all the subdirectories.
It cant find it. Velocity doesn't 'know' anything about HTML, so what you
put there is what goes to the browser.
Its probably a path issue.
>
> Thanks
> Brian Hall
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
"Whoever would overthrow the liberty of a nation must begin by subduing the
freeness of speech." - Benjamin Franklin