component binding is meant only for retreiving a component,
you can add you own binding
http://wiki.apache.org/tapestry/Tapestry5HowToAddBindingPrefix
the impl that suites your need is probably this:
add to your app module:
public static void contributeBindingSource(
MappedConfigurationString, BindingFactory configuration,
BindingSource bindingSource)
{
configuration.add(cprop,new
ComponentPropBindingFactory(bindingSource));
}
create the binding factory: ComponentPropBindingFactory.java:
package test.tapestry.services;
import org.apache.tapestry.Binding;
import org.apache.tapestry.ComponentResources;
import org.apache.tapestry.TapestryConstants;
import org.apache.tapestry.ioc.Location;
import org.apache.tapestry.runtime.Component;
import org.apache.tapestry.services.BindingFactory;
import org.apache.tapestry.services.BindingSource;
/** The cprop: binding prefix, which allows access to a child component's
prop via
* normal prop: expression prefixed with component id.*/
public class ComponentPropBindingFactory implements BindingFactory
{
private final BindingSource _propBindingFactory;
public ComponentPropBindingFactory(BindingSource bindingSource){
_propBindingFactory = bindingSource;
}
public Binding newBinding(String description, ComponentResources
container, ComponentResources component,
String expression, Location location)
{
int idx=expression.indexOf(.);
ComponentResources propSource = null;
if(idx == -1)
throw new RuntimeException(Invalid expression:
'+expression+'. You must provide component id );
else{
String componentId = expression.substring(0,idx);
expression = expression.substring(idx+1);
Component embeddedComponent = container.getEmbeddedComponent
(componentId);
if(embeddedComponent == null) throw new
RuntimeException(Component +componentId+ not found);
propSource = embeddedComponent.getComponentResources();
}
return _propBindingFactory.newBinding(description, propSource,
component, TapestryConstants.PROP_BINDING_PREFIX, expression, location);
}
}
test it:
page class: ${class}br/
t:loop id=loop source=data value=value
${value}, loop class: ${cprop:loop.class}br/
/t:loop
On 8/11/07, Thomas Beckmann [EMAIL PROTECTED] wrote:
Our customer should be able to place a component in any of the available
page
templates. He has no access to the Page classes. The component works as a
loop component but instead of providing a list of elements to the
component,
the user has to provide a query string and the component uses an injected
service to get the list. The customer will write the body part of the loop
on
his own but he needs a loop variable to access the properties of the
elements.
For example:
t:ProductLoop
t:id=cheapestProducts
t:query=cheapest products
t:value=product
a class=small_pic img src=${product.image} //a
/t:ProductLoop
One solution is to implement a setProduct() and getProduct() in every page
but
I'm looking for a solution that is independent of the page.
Thomas
Am Samstag, 11. August 2007 22:34 schrieb Davor Hrg:
please elaborate your use case a bit more,
maybe an alternative will be sufficient.
Davor Hrg
On 8/11/07, Thomas Beckmann [EMAIL PROTECTED] wrote:
Hi,
I'm looking for a way to access a component variable the same way as a
page
variable.
So for example when using a loop component I want to provide a setter
and getter of a component as the loop value instead of a setter and
getter of the
page.
I want to implement a component that works as a loop but provides a
list
of
elements on it's own. I want to use this component on any page without
the need to implement a loop value on each page.
I tried value=component:someComponent.someMethod but got an error
telling
that there is no such component.
Any ideas?
Thanks
Thomas
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]