velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claude Brisson <cla...@renegat.net>
Subject Re: Possible to align strings?
Date Wed, 01 Dec 2010 15:16:10 GMT
Yes, there is. You have to put a DisplayTool in your velocity context.

Check the cell() method in:

http://velocity.apache.org/tools/releases/2.0/javadoc/org/apache/velocity/tools/generic/DisplayTool.html

You would typically write: $disp.cell($jobinfo.localNameOfJobInXml,30)


   Claude


On 01/12/2010 15:56, Johannes Homuth wrote:
> Hi everybody
>
> I want to use velocity to create a "let's say" table. Therefore I have 
> a created a simple template.
>
> ================================================================================ 
>
> ENGINE STATE
> ================================================================================ 
>
> Jobname                    |   Execution State     | Duration   
> -------------------------------------------------------------------------------- 
>
> #foreach( $jobinfo in $infoList )
> $jobinfo.localNameOfJobInXml | $jobinfo.executionState | 
> $jobinfo.executionDuration
> -------------------------------------------------------------------------------- 
>
> #end
> ================================================================================ 
>
>
> Everything allright so far, but now I want to align the strings. The 
> inserted values for the variables in the template don't
> have the same length. So the generated output looks like this
>
> ....
> Jobname                    |   Execution State     | Duration   
> -------------------------------------------------------------------------------- 
>
> CheckDclStatusJob | EXECUTED_WITH_ERRORS | 00:00:00
> -------------------------------------------------------------------------------- 
>
> PcImportJob | NOT_EXECUTED_FAILED_DEPENDENCY | --:--:--
> -------------------------------------------------------------------------------- 
>
> OeImportJob | NOT_EXECUTED_FAILED_DEPENDENCY | --:--:--
> -------------------------------------------------------------------------------- 
>
> ....
>
> Looks like crap! Thats why I want to align the strings. Is there 
> anything like String.format("%-20s",test) which reserves a number of 
> columns of a String?
>
>
> Output should be something like this
>
> ....
> Jobname                | Execution State                   | 
> Duration   
> -------------------------------------------------------------------------------- 
>
> CheckDclStatusJob      | EXECUTED_WITH_ERRORS              | 00:00:00
> -------------------------------------------------------------------------------- 
>
> PcImportJob            | NOT_EXECUTED_FAILED_DEPENDENCY    | --:--:--
> -------------------------------------------------------------------------------- 
>
> OeImportJob            | NOT_EXECUTED_FAILED_DEPENDENCY    | --:--:--
> -------------------------------------------------------------------------------- 
>
> ....
>
>
> Thx for sugestions
>


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


Mime
View raw message