You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Chris Lewis <ch...@bellsouth.net> on 2007/11/16 13:53:54 UTC

T5: expression language

There's been a lot of interest in and expanded version of the T5 
expression language. I know T4 was equipped with ognl and people seem to 
have liked that very much. I could very well be off base here, and there 
may be a good reason for having chosen ognl before - but I'm curious - 
if what is desired is a full expression language, why not tap into a 
real scripting language? We could have a binding like 'script:' and 
provide complete expressions that get passed to an interpreter. This 
interpreter could even language agnostic (bsf?), as is jdk6's 
ScriptEngine, and developers could use what they like (rhino, jython, 
bsh, ...).

Perhaps this is a horrible idea, but if so I think it is transitive and 
the actual bad idea is having an expression language at all. Its 
certainly true that with such power one has enough rope to hang oneself, 
at least from the view point of what a 'view' should be able to do. 
Thoughts?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: expression language

Posted by Peter Stavrinides <p....@albourne.com>.
I think for T5 as default:
Tapestry's binding language might be extended to do some simple 
evaluation at best, and nothing more! .... the simpler the better in my 
view, isn't this the general idea of using components and moving away 
from embedded scripting? I think, in general, support for pulggable 
views for different devices, platforms and resolutions is becoming more 
and more important, and is served best through using components.

OGNL is now super fast and powerful, good in many respects... but I am 
glad it's no longer in the picture (no offence intended Jessie). 
Expression binding is not something I want to even think about ever, nor 
do I want to do wonderful things with it, Java is best for this in my 
view... besides OGNL has caused me some pain in the past.

I think for a T5 as optional:
Some people require stuff like true recursion with fine grained control 
and complex evaluation of templates (there was a post on this a while back)
Components can be too inflexible for this type of thing, wheras 
scripting makes sense and almost effortlessly can do it. So there is a 
very valid argument, which I support, for some real scripting support in 
the framework and not just a more powerful expression binding 
language... as important as this is, it serves a niche so is best made 
optional in my view.

If you say that scripting support can be pluggable or language agnostic, 
then this is a MUST HAVE feature for Tapestry... is it a 'bad idea'? as 
you have correctly said, having an expression binding language to do the 
job of a scripting language is the only bad idea IMHO.

Peter

Jesse Kuhnert wrote:
> Oh well....it wouldn't hurt my feelings if anyone used MVEL.   I'm
> only as loyal to the best technology and hope everyone else would be
> too.
>
> On Nov 16, 2007 4:35 PM, Davor Hrg <hr...@gmail.com> wrote:
>   
>> thanks,
>> I've played with it only a bit...
>>
>> It was that time that MVEL was said to be much faster than OGNL
>> and very long flame on serverside.
>>
>> I've just wanted try both, and made a small project that adds
>> both binding prefixes..
>> (I was not testing speeds .. just integration...)
>>
>> after playing with it I was more satisfied with OGNL,
>> and MVEL crashed on some simple examples when
>> byte code optimizer was turned on for it.
>>
>> Davor Hrg
>>
>>
>>
>> On Nov 16, 2007 10:06 PM, Jesse Kuhnert <jk...@gmail.com> wrote:
>>
>>     
>>> You can know the type in advance by calling
>>> OgnlContext.getCurrentType() after evaluating an expression (or
>>> getPreviousType() / getFirstType() / the type and accessor types are
>>> all pushed on to a stack now)..
>>>
>>> It also supports generics / enums / varargs / etc now..
>>>
>>> On Nov 16, 2007 2:42 PM, Davor Hrg <hr...@gmail.com> wrote:
>>>       
>>>> ognl can be easily added as a binding prefix,
>>>> however expect some features to not work
>>>> because tapestry in some occasions needs to
>>>> know in advance type that the expression will return
>>>>
>>>>         
>>> <snipped>
>>>
>>>
>>> --
>>> Jesse Kuhnert
>>> Tapestry/Dojo team member/developer
>>>
>>> Open source based consulting work centered around
>>> dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com
>>>
>>>       
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>>       
>
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: expression language

Posted by Jesse Kuhnert <jk...@gmail.com>.
Oh well....it wouldn't hurt my feelings if anyone used MVEL.   I'm
only as loyal to the best technology and hope everyone else would be
too.

On Nov 16, 2007 4:35 PM, Davor Hrg <hr...@gmail.com> wrote:
> thanks,
> I've played with it only a bit...
>
> It was that time that MVEL was said to be much faster than OGNL
> and very long flame on serverside.
>
> I've just wanted try both, and made a small project that adds
> both binding prefixes..
> (I was not testing speeds .. just integration...)
>
> after playing with it I was more satisfied with OGNL,
> and MVEL crashed on some simple examples when
> byte code optimizer was turned on for it.
>
> Davor Hrg
>
>
>
> On Nov 16, 2007 10:06 PM, Jesse Kuhnert <jk...@gmail.com> wrote:
>
> > You can know the type in advance by calling
> > OgnlContext.getCurrentType() after evaluating an expression (or
> > getPreviousType() / getFirstType() / the type and accessor types are
> > all pushed on to a stack now)..
> >
> > It also supports generics / enums / varargs / etc now..
> >
> > On Nov 16, 2007 2:42 PM, Davor Hrg <hr...@gmail.com> wrote:
> > > ognl can be easily added as a binding prefix,
> > > however expect some features to not work
> > > because tapestry in some occasions needs to
> > > know in advance type that the expression will return
> > >
> > <snipped>
> >
> >
> > --
> > Jesse Kuhnert
> > Tapestry/Dojo team member/developer
> >
> > Open source based consulting work centered around
> > dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com
> >
>
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>



-- 
Jesse Kuhnert
Tapestry/Dojo team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: expression language

Posted by Davor Hrg <hr...@gmail.com>.
thanks,
I've played with it only a bit...

It was that time that MVEL was said to be much faster than OGNL
and very long flame on serverside.

I've just wanted try both, and made a small project that adds
both binding prefixes..
(I was not testing speeds .. just integration...)

after playing with it I was more satisfied with OGNL,
and MVEL crashed on some simple examples when
byte code optimizer was turned on for it.

Davor Hrg


On Nov 16, 2007 10:06 PM, Jesse Kuhnert <jk...@gmail.com> wrote:

> You can know the type in advance by calling
> OgnlContext.getCurrentType() after evaluating an expression (or
> getPreviousType() / getFirstType() / the type and accessor types are
> all pushed on to a stack now)..
>
> It also supports generics / enums / varargs / etc now..
>
> On Nov 16, 2007 2:42 PM, Davor Hrg <hr...@gmail.com> wrote:
> > ognl can be easily added as a binding prefix,
> > however expect some features to not work
> > because tapestry in some occasions needs to
> > know in advance type that the expression will return
> >
> <snipped>
>
>
> --
> Jesse Kuhnert
> Tapestry/Dojo team member/developer
>
> Open source based consulting work centered around
> dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5: expression language

Posted by Jesse Kuhnert <jk...@gmail.com>.
You can know the type in advance by calling
OgnlContext.getCurrentType() after evaluating an expression (or
getPreviousType() / getFirstType() / the type and accessor types are
all pushed on to a stack now)..

It also supports generics / enums / varargs / etc now..

On Nov 16, 2007 2:42 PM, Davor Hrg <hr...@gmail.com> wrote:
> ognl can be easily added as a binding prefix,
> however expect some features to not work
> because tapestry in some occasions needs to
> know in advance type that the expression will return
>
<snipped>


-- 
Jesse Kuhnert
Tapestry/Dojo team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: expression language

Posted by Davor Hrg <hr...@gmail.com>.
of course, youll need the dependancy in your pom:

    <dependency>
        <groupId>ognl</groupId>
        <artifactId>ognl</artifactId>
        <version>2.6.9</version>
    </dependency>


On Nov 16, 2007 8:42 PM, Davor Hrg <hr...@gmail.com> wrote:

> ognl can be easily added as a binding prefix,
> however expect some features to not work
> because tapestry in some occasions needs to
> know in advance type that the expression will return
> (and this is statically, when bindings are prepared)
>
> I think I saw that ognl has methods that calculate
> return type for the expression ...
>
>
> read this:
> http://wiki.apache.org/tapestry/Tapestry5HowToAddBindingPrefix
>
>
> I didn't put the ognl example because it seems unwanted in T5
> (although byte code optimizer was introduced and it performs very well)
>
>
> here are classes you'll need to get it running
>
> /**
>  *
>  */
> package test.tapestry.services;
>
> import java.util.Map;
>
> import ognl.Node;
> import ognl.Ognl;
> import ognl.OgnlException;
> import ognl.TypeConverter;
>
> import org.apache.tapestry.ComponentResources ;
> import org.apache.tapestry.internal.bindings.AbstractBinding;
> import org.apache.tapestry.ioc.Location;
> import org.apache.tapestry.ioc.internal.util.TapestryException;
>
> public class OgnlBinding extends AbstractBinding{
>     private final Object _root;
>     private final Object _compiledExpression;
>     private final String _expression;
>     private final Location _location;
>     private Map _defaultContext;
>
>     public OgnlBinding(final ComponentResources resources, final String
> expression, final Location location, TypeConverter typeConverter) throws
> OgnlException {
>         _root = resources.getComponent();
>         _compiledExpression = Ognl.parseExpression(expression);
>         _expression = expression;
>         _location = location;
>         _defaultContext = Ognl.createDefaultContext (_root, null,
> typeConverter);
>     }
>
>
>     public Object get(){
>         try{
>             return Ognl.getValue(_compiledExpression, _defaultContext,
> _root);
>         }catch(Throwable t){
>             throw new TapestryException("ERROR evaluating expression:
> "+_expression,_location, t);
>         }
>     }
>
>     @Override
>     public void set(final Object value) {
>         try{
>             Ognl.setValue(_compiledExpression, _defaultContext, _root,
> value);
>         }catch(Throwable t){
>             throw new TapestryException("ERROR evaluating expression:
> "+_expression,_location, t);
>         }
>     }
>
>     @Override
>     public boolean isInvariant() {
>         return false;
>     }
>
>     @Override
>     public Class<Object> getBindingType() {
>         return Object.class;
>     }
> }
>
> package test.tapestry.services;
>
> import ognl.OgnlException;
> import ognl.TypeConverter ;
>
> import org.apache.tapestry.Binding;
> import org.apache.tapestry.ComponentResources;
> import org.apache.tapestry.ioc.Location;
> import org.apache.tapestry.ioc.internal.util.TapestryException;
> import org.apache.tapestry.services.BindingFactory ;
>
> /**
>  * Implementation of the ognl: binding prefix -- the expression is passed
> to ognl library,
>  * and the component is set as context for the code
>  */
> public class OgnlBindingFactory implements BindingFactory {
>     private final TypeConverter _typeConverter;
>
>     public OgnlBindingFactory(TypeConverter typeConverter){
>         _typeConverter = typeConverter;
>     }
>
>     public Binding newBinding(String description, ComponentResources
> container, ComponentResources component,
>             String expression, Location location)
>     {
>         try {
>             return new OgnlBinding(container, expression, location,
> _typeConverter);
>         } catch (OgnlException e) {
>             throw new TapestryException( e.getMessage(),location,e);
>         }
>     }
> }
>
>
>
>
> package test.tapestry.services;
>
> import java.lang.reflect.Member;
> import java.util.Map;
>
> import ognl.TypeConverter;
>
> import org.apache.tapestry.ioc.services.TypeCoercer ;
>
> public class OgnlTypeConverter implements TypeConverter{
>
>     private final TypeCoercer _coercer;
>
>     public OgnlTypeConverter(TypeCoercer coercer){
>         _coercer = coercer;
>     }
>
>     public Object convertValue(Map context, Object target, Member member,
> String propertyName, Object value, Class toType) {
>         return _coercer.coerce(value, toType);
>
>     }
> }
>
>
>
>
>
>
>
> On Nov 16, 2007 3:52 PM, Massimo Lusetti <ml...@gmail.com> wrote:
>
> > On Nov 16, 2007 1:53 PM, Chris Lewis <ch...@bellsouth.net> wrote:
> >
> > > Perhaps this is a horrible idea, but if so I think it is transitive
> > and
> > > the actual bad idea is having an expression language at all. Its
> > > certainly true that with such power one has enough rope to hang
> > oneself,
> > > at least from the view point of what a 'view' should be able to do.
> > > Thoughts?
> >
> > I've never used the whole power of OGNL during T4 days, always used it
> > as a simple binding language.
> > So by me there's no interest in having OGNL of any other scrpting
> > language inside T5.
> >
> > Just my .02 EURO.
> >
> > --
> > Massimo
> > http://meridio.blogspot.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>

Re: T5: expression language

Posted by Davor Hrg <hr...@gmail.com>.
ognl can be easily added as a binding prefix,
however expect some features to not work
because tapestry in some occasions needs to
know in advance type that the expression will return
(and this is statically, when bindings are prepared)

I think I saw that ognl has methods that calculate
return type for the expression ...


read this:
http://wiki.apache.org/tapestry/Tapestry5HowToAddBindingPrefix


I didn't put the ognl example because it seems unwanted in T5
(although byte code optimizer was introduced and it performs very well)


here are classes you'll need to get it running

/**
 *
 */
package test.tapestry.services;

import java.util.Map;

import ognl.Node;
import ognl.Ognl;
import ognl.OgnlException;
import ognl.TypeConverter;

import org.apache.tapestry.ComponentResources;
import org.apache.tapestry.internal.bindings.AbstractBinding;
import org.apache.tapestry.ioc.Location;
import org.apache.tapestry.ioc.internal.util.TapestryException;

public class OgnlBinding extends AbstractBinding{
    private final Object _root;
    private final Object _compiledExpression;
    private final String _expression;
    private final Location _location;
    private Map _defaultContext;

    public OgnlBinding(final ComponentResources resources, final String
expression, final Location location, TypeConverter typeConverter) throws
OgnlException {
        _root = resources.getComponent();
        _compiledExpression = Ognl.parseExpression(expression);
        _expression = expression;
        _location = location;
        _defaultContext = Ognl.createDefaultContext(_root, null,
typeConverter);
    }


    public Object get(){
        try{
            return Ognl.getValue(_compiledExpression, _defaultContext,
_root);
        }catch(Throwable t){
            throw new TapestryException("ERROR evaluating expression:
"+_expression,_location, t);
        }
    }

    @Override
    public void set(final Object value) {
        try{
            Ognl.setValue(_compiledExpression, _defaultContext, _root,
value);
        }catch(Throwable t){
            throw new TapestryException("ERROR evaluating expression:
"+_expression,_location, t);
        }
    }

    @Override
    public boolean isInvariant() {
        return false;
    }

    @Override
    public Class<Object> getBindingType() {
        return Object.class;
    }
}

package test.tapestry.services;

import ognl.OgnlException;
import ognl.TypeConverter;

import org.apache.tapestry.Binding;
import org.apache.tapestry.ComponentResources;
import org.apache.tapestry.ioc.Location;
import org.apache.tapestry.ioc.internal.util.TapestryException;
import org.apache.tapestry.services.BindingFactory;

/**
 * Implementation of the ognl: binding prefix -- the expression is passed to
ognl library,
 * and the component is set as context for the code
 */
public class OgnlBindingFactory implements BindingFactory {
    private final TypeConverter _typeConverter;

    public OgnlBindingFactory(TypeConverter typeConverter){
        _typeConverter = typeConverter;
    }

    public Binding newBinding(String description, ComponentResources
container, ComponentResources component,
            String expression, Location location)
    {
        try {
            return new OgnlBinding(container, expression, location,
_typeConverter);
        } catch (OgnlException e) {
            throw new TapestryException(e.getMessage(),location,e);
        }
    }
}




package test.tapestry.services;

import java.lang.reflect.Member;
import java.util.Map;

import ognl.TypeConverter;

import org.apache.tapestry.ioc.services.TypeCoercer;

public class OgnlTypeConverter implements TypeConverter{

    private final TypeCoercer _coercer;

    public OgnlTypeConverter(TypeCoercer coercer){
        _coercer = coercer;
    }

    public Object convertValue(Map context, Object target, Member member,
String propertyName, Object value, Class toType) {
        return _coercer.coerce(value, toType);
    }
}







On Nov 16, 2007 3:52 PM, Massimo Lusetti <ml...@gmail.com> wrote:

> On Nov 16, 2007 1:53 PM, Chris Lewis <ch...@bellsouth.net> wrote:
>
> > Perhaps this is a horrible idea, but if so I think it is transitive and
> > the actual bad idea is having an expression language at all. Its
> > certainly true that with such power one has enough rope to hang oneself,
> > at least from the view point of what a 'view' should be able to do.
> > Thoughts?
>
> I've never used the whole power of OGNL during T4 days, always used it
> as a simple binding language.
> So by me there's no interest in having OGNL of any other scrpting
> language inside T5.
>
> Just my .02 EURO.
>
> --
> Massimo
> http://meridio.blogspot.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5: expression language

Posted by Massimo Lusetti <ml...@gmail.com>.
On Nov 16, 2007 1:53 PM, Chris Lewis <ch...@bellsouth.net> wrote:

> Perhaps this is a horrible idea, but if so I think it is transitive and
> the actual bad idea is having an expression language at all. Its
> certainly true that with such power one has enough rope to hang oneself,
> at least from the view point of what a 'view' should be able to do.
> Thoughts?

I've never used the whole power of OGNL during T4 days, always used it
as a simple binding language.
So by me there's no interest in having OGNL of any other scrpting
language inside T5.

Just my .02 EURO.

-- 
Massimo
http://meridio.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org