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 <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> wrote: > > > On Nov 16, 2007 1:53 PM, Chris Lewis <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > >