Concatenação de variaveis string com o Velocity

Salve a todos.

Existe alguma maneira de concatenar variaveis do tipo String com o velocity?

experimentei fazer assim:

#set($variavel1 = variavel1 + " alguma string")

ou ainda

#set($variavel1 = variavel1 + variavel2)

e não funcionou.

Obrigado.

Estranho cara. O que não funcionou? Dá erro?

Nao seria

#set($variavel1 = $variavel1 + " alguma string")

? Note o “$”, que tem que ter em todas as vars.

Rafael

LIPE, valeu pela atenção.
Testei de duas formas:

Primeira:

#set($variavel1 = " Primeira String ") #set($variavel1 = $variavel1 + " Segunda String ") $variavel1

Segunda

#set($variavel1 = " Primeira String ") #set($variavel2 = " Segunda String ") #set($variavel3 = $variavel1 + $variavel2) $variavel3

acusam o seguinte erro:

[quote]2004-11-12 10:15:25,198 INFO [org.jboss.web.localhost.Engine] StandardContext[/mysite] Velocity [error] Left side of addition operation is not a valid type. Currently only integers (1,2,3…) and Integer type is supported. gestao/documentacao.vm [line 70, column 31]

será que pode ser coisa de configuração do velociy?

[quote=Rafael Steil]Nao seria

#set($variavel1 = $variavel1 + " alguma string")

? Note o “$”, que tem que ter em todas as vars.

Rafael[/quote]

Desculpe Rafael, é erro de digitação :oops:

outro detalhe: estou usando a versão 1.3.1

Cara, só para desencargo de consciência, fui testar … e também não funcionou hehe mas não deu erro algum:

#set( $test = "test" )
#set( $test = $test + " test" )
<label value="$test"/>

Só imprime “test”, e não “test test” como deveria @.@

E isso:

#set( $test = "test" )
#set( $concat = $test + " test" )
<label value="$concat"/>

Imprime “$concat”. O que quer dizer que alguma variável tem valor null ali no meio, então deu merda.

Percebi que nunca precisei fazer isso dessa forma … e já faz quase 1 ano que uso Velocity.

O que você pode fazer é:

#set( $test = "test" )
<label value="$test test"/>

Mas que é realmente uma droga é.

:oops: he he esquci de dizer, o erro dá é no log do JBoss

[quote=LIPE]
O que você pode fazer é:

#set( $test = "test" )
<label value="$test test"/>

Mas que é realmente uma droga é.[/quote]

Não sei se estou inventando moda, às vezes pode ser resolvido de outra forma, é que o caso que tenho existem duas variaveis de array uma com nomes de parametros e outra com valores, preciso concatenar pra ficar algo tipo

parametro1=valor1 & parametro2=valor2

e depois jogar isso em um link

Pessoal;

Consegui resolver o problema:

#set($variavel1 = " Primeira String ") #set($variavel1 = $variavel1.concat(" Segunda String ")) $variavel1

Oras eu posso chamar qualquer método, porque não chamar o método concat de String?

Ajuda para esta solução foi dada pelo colega Lucas Teixeira (lucastex) de Londrina/PR.

Valeu cara :smiley:

[quote=New__Radical]http://jakarta.apache.org/velocity/user-guide.html

CTRL + END

2x Page up[/quote]

Segui tua orientação, é algum enigma :stuck_out_tongue: ? não entendi :oops: , olha só onde caiu:

[quote]template is a VM at parsetime, #parse()-ing a set of VM declarations won’t work as expected. To get around this, simply use the velocimacro.library facility to have Velocity load your VMs at startup.

What is Velocimacro Autoreloading?
There is a property, meant to be used in development, not production :

velocimacro.library.autoreload

which defaults to false. When set to true along with

<type>.resource.loader.cache = false

(where <type> is the name of the resource loader that you are using, such as ‘file’) then the Velocity engine will automatically reload changes to your Velocimacro library files when you make them, so you do not have to dump the servlet engine (or application) or do other tricks to have your Velocimacros reloaded.

Here is what a simple set of configuration properties would look like.

 file.resource.loader.path = templates
file.resource.loader.cache = false
velocimacro.library.autoreload = true

Don’t keep this on in production. [/quote]

http://jakarta.apache.org/velocity/user-guide.html

CTRL + END

2x Page up