But why would you want that? I can see the benefit but I am afraid that
that will just make your tml more complicated where in my mind logic like
that belongs in .java

just my 2 cents

cheers


On Sun, Nov 17, 2013 at 6:30 PM, 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
>
>


-- 
Sincerely
*Boris Horvat*

Reply via email to