cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thorsten Scherler <scher...@gmail.com>
Subject Re: [c3] Implementing presentation logic in c3
Date Fri, 28 Oct 2011 09:17:49 GMT
On Fri, 2011-10-28 at 10:05 +0200, Francesco Chicchiriccò wrote:
> 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.

Thanks for linking to that discussion. I read it before but I did not
remember the subject. ;)

However I tend to support Thomas "JXGenerator is really useful, its a
must have for me." stringtemplate brings you loops and limited if but
nothing where you need to do e.g. ${foo.substring(1)}

...but for me we may even want to look into supporting jsp + taglibs to
produce sax/stax events since then we could reuse taglibs which are very
powerful and clean.

Anyway IMO stringtemplate is not enough as for supporting the needs of
presentation logic of most situations. I agree with the point they have
"enforce strict separation" but sometimes to enforce this separation the
effort is just too much.

> 
> 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.

Well for people that needs:
a) print out a value
b) use only simple boolean conditions
c) loops through sets

Th biggest problem I am facing is that b) is not even working, but you
mentioned that could be a bug. Anyway I suspect people coming from <3
that are use to jx and xsp finding StringTemplate too restrictive (more
if you have heavily used xsp before you will bang your head ;)).

> 
> > 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.

Ok I will have a look. 

> 
> > 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]?

It is returning a boolean BUT
public class ShiroInterpreter implements LanguageInterpreter {
public String resolve(String expression, ObjectModel objectModel) {
...
}

Trying to say 
 <map:parameter name="isUser" value="{shiro:authenticated}" />
will always be casted to a string when resolved. 

I actually suspect that "public Object resolve" would fix the problem
you mentioned in the transformer since then the string-template context
gets it as boolean and not as string representation.

salu2


> 
> > 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
> 

-- 
Thorsten Scherler <thorsten.at.apache.org>
codeBusters S.L. - web based systems
<consulting, training and solutions>
http://www.codebusters.es/


Mime
View raw message