I get nervous about creating new binding factories that then try to parse the (rather complex) property binding syntax, that's all. We've kind of used up all the punctuation and delimiters.
On Sun, Nov 17, 2013 at 9:30 AM, Matthias <thegreatme...@gmail.com> wrote: > @Howard > Thanks for your reply. I know that it was possible with Java code, but i > tried to avoid to write extra methods for such simple tasks. > > @Michael > WOW! Thats really nice. Exactly what I was looking for. I improved it a > bit to make the false value optional. > > // constructor without falseBinding > public CondBinding(Binding conditionBinding, Binding trueBinding, > TypeCoercer resolver) { > this(conditionBinding, trueBinding, null, resolver); > } > > // just check if valueFalse is set > > @Override > public Object get() { > String valueTrue = resolver.coerce(trueBinding.get(), > String.class); > String valueFalse = falseBinding != null ? > resolver.coerce(falseBinding.get(), String.class) : null; > > Boolean condition = resolver.coerce(conditionBinding.get(), > Boolean.class); > return condition != null && condition ? valueTrue : valueFalse; > } > > > // in BindingFactory > > @Override > public Binding newBinding(String description, ComponentResources > container, ComponentResources component, String expression, > Location location) { > String[] parts = expression.split(DELIMETER, 3); > > // well i'm not sure what happens here if parts < 2 > > if (parts.length < 2) { > return bindingSource.newBinding(description, container, > component, "prop", expression, location); > } > > String condition = parts[0]; > String valueTrue = parts[1]; > Binding conditionBinding = makeBinding(condition, > DEFAULT_CONDITION_PREFIX, container, description); > Binding trueBinding = makeBinding(valueTrue, DEFAULT_VALUE_PREFIX, > container, description); > > if (parts.length == 3) { > > String valueFalse = parts[2]; > Binding falseBinding = makeBinding(valueFalse, > DEFAULT_VALUE_PREFIX, container, description); > return new CondBinding(conditionBinding, trueBinding, > falseBinding, resolver); > } > return new CondBinding(conditionBinding, trueBinding, resolver); > } > > // Usage > class="${cond:selected, selected}" > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > > -- Howard M. Lewis Ship Creator of Apache Tapestry The source for Tapestry training, mentoring and support. Contact me to learn how I can get you up and productive in Tapestry fast! (971) 678-5210 http://howardlewisship.com