You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Bryce Nesbitt <br...@obviously.com> on 2005/12/15 01:38:09 UTC

How to output a tab from a velocity template?

I'm using a velocity/xwork/WebWork template to write a text file, which
needs to have tabs between each record:

$res.setHeader("content-type", "text/plain")#*
*#$res.setHeader("Content-Disposition", "attachment; filename=xxxxx.tsv")
#foreach( $step in $result )
RECORD&tab;$!step.PrimaryContact.firstName&tab;$!step.PrimaryContact.lastName
#end

How can I get tabs or other special characters out of Velocity? \t does
not work.  &tab; and &#09; won't work, because the target is not a HTML
browser.

Putting actual tabs in the text file might work, but that's icky.

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


Re: How to output a tab from a velocity template?

Posted by Bryce Nesbitt <br...@obviously.com>.
Based on the kind help I got on this list,  here's my final solution.
I added the following method to the matching action:

    public String getTab() {
       return "\t";
    }

Then simply used ${tab} in the velocity page:
   CUST${tab}NAME${tab}BADDR1${tab}BADDR2${tab}BADDR3

This may be specific to webwork/xwork.

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


Re: How to output a tab from a velocity template?

Posted by Nathan Bubna <nb...@gmail.com>.
On 12/14/05, Bryce Nesbitt <br...@obviously.com> wrote:
> Nathan Bubna wrote:
> >    if actual tabs aren't icky in the output, then i don't see why they're
> > icky in the input.  Velocity doesn't do anything special for or with
> > tab characters.
> Because the source code is in a multiplatform multideveloper environment
> that does not preserve (or allow,
> or tolerate) tabs.
> The export is in user-land.

ah, that makes sense.

> >   if you want a tab character in the output, the
> > simplest thing is to put it in the input.  but if you really don't
> > like that, you can always put a string containing just a tab in the
> > context:
> >
> > context.put("tab", "\t");
> >
> > and then use
> >
> > ${tab} in your template.
> >
> >
> Cool, could you give me one more hint on where to find the right
> context? I did this, without joy:

looks like some sort of WebWork context.  you want to get it into the
Velocity context.  i don't know much about WebWork's Velocity
integration...

>  // Action.java
> ...extends ActionSupport...
>
>  public String execute() throws Exception {
>         ActionContext.getContext().put("tab","\t");
>         return "tabexport";
>     }
>
>
> <!-- something.vm -->
> $res.setHeader("content-type", "text/plain")
> $res.setHeader("Content-Disposition", "attachment;
> filename=cust_-xxxxxx.txt")TFLD4
> TEST$tab${tab}TEST
> TEST$tab${tab}TEST

if the response is available as $res, perhaps the request is available
as $req (old VelocityServlet style).  if so, then at worst you could
do:

request.setAttribute("tab", "\t")

and

#set( $tab = $req.getAttribute('tab') )
TEST${tab}${tab}TEST

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

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


Re: How to output a tab from a velocity template?

Posted by Bryce Nesbitt <br...@obviously.com>.
Nathan Bubna wrote:
>    if actual tabs aren't icky in the output, then i don't see why they're
> icky in the input.  Velocity doesn't do anything special for or with
> tab characters.
Because the source code is in a multiplatform multideveloper environment
that does not preserve (or allow,
or tolerate) tabs.
The export is in user-land.

>   if you want a tab character in the output, the
> simplest thing is to put it in the input.  but if you really don't
> like that, you can always put a string containing just a tab in the
> context:
>
> context.put("tab", "\t");
>
> and then use
>
> ${tab} in your template.
>
>   
Cool, could you give me one more hint on where to find the right
context? I did this, without joy:


 // Action.java
...extends ActionSupport...

 public String execute() throws Exception {
        ActionContext.getContext().put("tab","\t");
        return "tabexport";
    }


<!-- something.vm -->
$res.setHeader("content-type", "text/plain")
$res.setHeader("Content-Disposition", "attachment;
filename=cust_-xxxxxx.txt")TFLD4
TEST$tab${tab}TEST
TEST$tab${tab}TEST

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


Re: How to output a tab from a velocity template?

Posted by Nathan Bubna <nb...@gmail.com>.
On 12/14/05, Bryce Nesbitt <br...@obviously.com> wrote:
> I'm using a velocity/xwork/WebWork template to write a text file, which
> needs to have tabs between each record:
>
> $res.setHeader("content-type", "text/plain")#*
> *#$res.setHeader("Content-Disposition", "attachment; filename=xxxxx.tsv")
> #foreach( $step in $result )
> RECORD&tab;$!step.PrimaryContact.firstName&tab;$!step.PrimaryContact.lastName
> #end
>
> How can I get tabs or other special characters out of Velocity? \t does
> not work.  &tab; and &#09; won't work, because the target is not a HTML
> browser.
>
> Putting actual tabs in the text file might work, but that's icky.

if actual tabs aren't icky in the output, then i don't see why they're
icky in the input.  Velocity doesn't do anything special for or with
tab characters.  if you want a tab character in the output, the
simplest thing is to put it in the input.  but if you really don't
like that, you can always put a string containing just a tab in the
context:

context.put("tab", "\t");

and then use

${tab} in your template.

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

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


Re: Fairly simple page returns wrong Content-Length in HTTP headers

Posted by Bryce Nesbitt <br...@obviously.com>.
The following very simple .html file is enough to trigger the issue I'm
seeing:

-----------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

#macro( screwthingsupmacro $values )
    <p>I cause the Content-Length: header to be wrong!</p>
#end

<html>
<head>
    <title>Individual Member Application</title>
</head>
<body>
<form action="signup.action" method="POST">
</form>
</body>
</html>
-----------------------------------------------

host> wget --save-headers http://localhost:8080/exploded/signup/e_test.html

HTTP request sent, awaiting response... 200 OK
Length: 350 [text/html]
71% [=========================>           ] 249           --.--K/s   
ETA 00:02
Connection closed at byte 249. Retrying.



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


Fairly simple page returns wrong Content-Length in HTTP headers

Posted by Bryce Nesbitt <br...@obviously.com>.
I have a fairly simple velocity page which I have inherited.

When loaded, on some platforms and browsers, it mostly 'works' but never
'finishes' loading.
Turns out the HTTP headers claim the file is 31,940 bytes, and the
actual file (as loaded)
is only 19,000.  So any client that looks at the length hangs.  Others
get it instantly.

The returned HTTP headers are:
----------------------------------
HTTP/1.1 200 OK
Date: Fri, 16 Dec 2005 05:11:12 GMT
Server: Apache/1.3.29 (Unix) Resin/2.1.12 mod_ssl/2.8.16 OpenSSL/0.9.6l
Cache-Control: max-age=86400
Expires: Sat, 17 Dec 2005 05:11:12 GMT
Last-Modified: Wed, 14 Dec 2005 20:02:07 GMT
Content-Length: 31940
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html

The file is no more complex than:
-----------------------------------
#macro( errorMessageLocal $message )
    #if( $fieldErrors.size() > 0 )
    <tr><td>
    <div style="border: 1px solid #f00; background-color: #fdd;
font-size:9pt;">
    #if( $message ) <strong>$!{message}</strong> #end
    <ul style="font-size:9pt;">
        #foreach( $error in $fieldErrors )
        <li>$error</li>
        #end
    </ul>
    </div>
    </td></tr>
    #end
#end

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>Individual Member Application</title>
    <link rel="stylesheet" type="text/css" href="application_style.css" />
</head>
<body>
....
#errorMessageLocal( "Please fix the following errors:" )
...


Has anyone seen things like this before?  Any clues before I brute force
binary search the dang thing?


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


Re: How to output a tab from a velocity template?

Posted by Will Glass-Husain <wg...@forio.com>.
Define an reference $tab in the context?

context.put("tab","\t");

WILL

----- Original Message ----- 
From: "Bryce Nesbitt" <br...@obviously.com>
To: <ve...@jakarta.apache.org>
Sent: Wednesday, December 14, 2005 4:38 PM
Subject: How to output a tab from a velocity template?


> I'm using a velocity/xwork/WebWork template to write a text file, which
> needs to have tabs between each record:
>
> $res.setHeader("content-type", "text/plain")#*
> *#$res.setHeader("Content-Disposition", "attachment; filename=xxxxx.tsv")
> #foreach( $step in $result )
> RECORD&tab;$!step.PrimaryContact.firstName&tab;$!step.PrimaryContact.lastName
> #end
>
> How can I get tabs or other special characters out of Velocity? \t does
> not work.  &tab; and &#09; won't work, because the target is not a HTML
> browser.
>
> Putting actual tabs in the text file might work, but that's icky.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 


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


Re: How to Internationalize the text in a velocity template?

Posted by Carfield Yim <ca...@carfield.com.hk>.
For me, just simple press the resourcebundle as the parameter

On 12/15/05, Rakesh Reddy <ai...@yahoo.com> wrote:
> Hi Group --
>
>     I am new to use the velociity framework. How do we Internationalize the textx in a velocity template ?
>
> For example, if I have the following template.
>
> ###############################
> The following students must be required to attend the Gelogy Class:
> #foreach ($name in $list)
>   $name should attend Geology
> end
> ###############################
>
> Now in the above example how do I make the text "The following students must be required to attend the Gelogy Class:" a label.
>
> label.student.instruction=The following students must be required to attend the Gelogy Class:
>
> How I do use this label in the velocity template ? To do this do we need to do any special processing in the velocity template processor.
>
> Thanks
> Rakesh
>
>
>
>
> ---------------------------------
> Yahoo! Shopping
>  Find Great Deals on Holiday Gifts at Yahoo! Shopping
>

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


How to Internationalize the text in a velocity template?

Posted by Rakesh Reddy <ai...@yahoo.com>.
Hi Group --

    I am new to use the velociity framework. How do we Internationalize the textx in a velocity template ? 

For example, if I have the following template.

###############################
The following students must be required to attend the Gelogy Class:
#foreach ($name in $list)
  $name should attend Geology
end
###############################

Now in the above example how do I make the text "The following students must be required to attend the Gelogy Class:" a label.

label.student.instruction=The following students must be required to attend the Gelogy Class:

How I do use this label in the velocity template ? To do this do we need to do any special processing in the velocity template processor.

Thanks
Rakesh



			
---------------------------------
Yahoo! Shopping
 Find Great Deals on Holiday Gifts at Yahoo! Shopping