cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Francesco Chicchiriccò <ilgro...@apache.org>
Subject Re: [c3] Implementing presentation logic in c3
Date Fri, 28 Oct 2011 08:05:39 GMT
On 28/10/2011 00:39, Thorsten Scherler wrote:
> Hi all,
>
> what is the recommended way to implement presentation logic in c3? JX was our former
choice but I could not find it in c3.
>
> What should we use to implement simple presentation logic like we did with jx? What are
people using? Or do I need to migrate jx?

Hi Thorsten,
this sounds like something we started discussing about a while ago [2]: 
as you can see from there, we ended up by not porting JX-related (or 
Velocity-related) components.

Personally, I think that StringTemplate should be enough for the moment; 
anyway, maybe not now, I still do believe that Cocoon 3 would really 
benefit from something like JX.

> I tried to use the "string-template" component but I am running into a problem when using
$if(boolean)$.
>
> I am ATM integrating Apache Shiro, a security framework that performs authentication,
authorization, cryptography, and session management, into c3 and want to use something in
the spirit of their taglibs
> <shiro:notAuthenticated>
>      Please<a href="login.jsp">login</a>.
> </shiro:notAuthenticated>
>
> So what I did is I wrote a ShiroInterpreter implements LanguageInterpreter that can extract
this info.
> However the interface LanguageInterpreter defines the return type to String.
>
> <map:transform type="string-template">
>    <map:parameter name="isUser" value="{shiro:authenticated}"/>
> </map:transform>
>
> will fail then interpreting
> $if(!isUser)$
>    <a href="/logout">/logout</a>
> $else$
>    <a href="/login">/login</a>
> $endif$
>
> with
> ...
> Caused by: org.stringtemplate.v4.compiler.STException: null
> 	at org.stringtemplate.v4.compiler.Compiler.reportMessageAndThrowSTException(Compiler.java:213)
~[ST4-4.0.4.jar:na]
>
> If I use only $isUser$ I get the correct value. Reading "Conditional subtemplates" [1]
> "You may only test whether an attribute is present or absent, preserving separation of
model
> and view. The only exception is that if an attribute value is a Boolean object, it will
test it for true/false."

I think you've hit a bug of StringTemplate transformer: see the attached 
patch (for cocoon-sample in C3 sources) using conditional and boolean 
value from sitemap; ST generator works well and ST transformer raises an 
exception similar to the one reported above.

> So for me the exception either mean we do not support $if(condition)$ or that the compiler
do not likes that $isUser$ is a String and not a boolean.

Are you sure that $isUser$ is a String? Shouldn't it be a boolean 
instead [3]?

> TIA for any feedback!
>
> salu2
>
> [1] http://www.cs.usfca.edu/~parrt/course/601/lectures/stringtemplate.html
[2] 
http://old.nabble.com/-C3--Passing-parameters-from-sitemap-to-generator-td31971810.html
[3] 
https://shiro.apache.org/static/current/apidocs/org/apache/shiro/subject/Subject.html#isAuthenticated%28%29

-- 
Francesco Chicchiriccò

Apache Cocoon Committer and PMC Member
http://people.apache.org/~ilgrosso/


Mime
View raw message