VRaptor + linkTo + Freemarker

46 views
Skip to first unread message

Emanuell Faustino

unread,
Apr 17, 2014, 12:01:55 PM4/17/14
to caelum-...@googlegroups.com
Olá todos.

Estou tentando usar o linkTo juntamente com o freemarker, mas está acontecendo o erro abaixo. É necessário alguma configuração extra ou realmente não funciona?

freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
==> linkTo[LoginController]  [in template "WEB-INF/jsp/index/index.jsp" at line 6, column 20]

Tip: If the failing expression is known to be legally null/missing, either specify a default value with myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthessis: (myOptionVar.foo)!myDefault, (myOptionVar.foo)??

The failing instruction:
==> ${linkTo[LoginController].logout}  [in template "WEB-INF/jsp/index/index.jsp" at line 6, column 18]
Abs,
--
Emanuell Faustino

Chico Sokol

unread,
Apr 17, 2014, 12:10:57 PM4/17/14
to caelum-vraptor
Você está usando o plugin do freemarker? Ou chamando o freemarker na mão?



--
Chico Sokol


--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caelum-vrapto...@googlegroups.com.
To post to this group, send email to caelum-...@googlegroups.com.
Visit this group at http://groups.google.com/group/caelum-vraptor.
For more options, visit https://groups.google.com/d/optout.

Emanuell Faustino

unread,
Apr 17, 2014, 12:18:30 PM4/17/14
to caelum-...@googlegroups.com
O freemarker na mão. Da certa forma, estava tentando deixar transparente o uso do freemarker. Ou seja, sem que precise fazer result.use(FreemarkerView.class) no controller.
--
Emanuell Faustino

Chico Sokol

unread,
Apr 17, 2014, 12:25:22 PM4/17/14
to caelum-vraptor
Pelo que eu me lembro, o plugin coloca todos os atributos do request no contexto do freemarker, você está fazendo isso? 

Se estiver, deveria existir o objeto linkTo no seu ftl, então seria só uma questão de chamar os métodos certos desse objeto com a sintaxe do freemarker.

Se vc fizer um freemarker só com "${linkTo}" o que acontece?



--
Chico Sokol

Emanuell Faustino

unread,
Apr 19, 2014, 6:54:14 PM4/19/14
to caelum-...@googlegroups.com
De fato, faltava os atributos do request. Voltei a utilizar o plugin vraptor-freemarker e fiz o teste só com o ${linkTo}... não funcionou. Listei também os atributos que o plugin coloca na requisição, e nenhum é parecido com o LinkToHandler. É necessário algo de diferente para funcionar em um .ftl?

FreeMarker template error:

The following has evaluated to null or missing:

==> linkTo  [in template "teste/index.ftl" at line 8, column 49]


Tip: If the failing expression is known to be legally null/missing, either specify a default value with myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthessis: (myOptionVar.foo)!myDefault, (myOptionVar.foo)??


The failing instruction (FTL stack trace):

----------

==> ${linkTo}  [in template "teste/index.ftl" at line 8, column 47]

----------

Chico Sokol

unread,
Apr 19, 2014, 8:01:58 PM4/19/14
to caelum-vraptor
Opa, parece que o linkTo é colocado no ServletContext, no startup da aplicação:


O plugin deveria colocar os objetos do ServletContext (e da session tb) no contexto do freemarker. Ele não faz isso? Quer mandar um pull request para corrigir?



--
Chico Sokol

Emanuell Faustino

unread,
Apr 19, 2014, 10:53:06 PM4/19/14
to caelum-...@googlegroups.com
Chico, ainda estou iniciando com o Freemarker e não conheço totalmente a sintaxe. Como deve ser a sintaxe do linkTo no template .ftl?

Chico Sokol

unread,
Apr 19, 2014, 11:07:49 PM4/19/14
to caelum-vraptor
Conseguiu colocar ele no .ftl?

Acho que você pode fazer: ${linkTo[UsuarioController]}. Só não sei se o UsuarioController vai estar disponível no contexto. Acho que precisa ser um Class<UsuarioController>. Olhando rapidamente, não encontrei onde o linkTo coloca isso na view (Lucas e/ou Otavio devem saber).



--
Chico Sokol

Emanuell Faustino

unread,
Apr 19, 2014, 11:43:31 PM4/19/14
to caelum-...@googlegroups.com
Consegui sim. 

Tentei dessa forma mas deu erro. Exibi os parâmetros do ServletContext e pro linkTo o map estava vazio.



Emanuell Faustino

unread,
Apr 20, 2014, 4:53:55 PM4/20/14
to caelum-...@googlegroups.com, lucasm...@gmail.com
Lucas, você sabe como fica a utilização do linkTo na sintaxe do Freemarker?
--
Emanuell Faustino

Lucas Cavalcanti

unread,
Apr 22, 2014, 2:10:35 PM4/22/14
to Emanuell Faustino, caelum-vraptor
Não conheço muito de Freemarker... mas no VRaptor 3 tudo é mapa, então vc pode usar sintaxe de mapas

${linkTo[BlaController]['metodo'][arg1]}

no vraptor 4 são proxies, então deve funcionar do mesmo jeito que jsp:

${linkTo[BlaController].metodo(arg1)}
Reply all
Reply to author
Forward
0 new messages