You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by "Davor Hrg (JIRA)" <de...@tapestry.apache.org> on 2007/12/02 11:53:43 UTC

[jira] Issue Comment Edited: (TAPESTRY-1830) allow local value and index parameters (i.e. not page class variables) in loop, count ... components

    [ https://issues.apache.org/jira/browse/TAPESTRY-1830?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12547610 ] 

hrgdavor edited comment on TAPESTRY-1830 at 12/2/07 2:52 AM:
--------------------------------------------------------------

I tried this out some time ago,
it is actualy very simple to do.

I added another prefix, used string until first dot
as component id, and delegated the rest of the expression
to prop binding and using just found component as root object.

the only problem was that this worked for my own components,
and not for Loop component. The reason for this is simple, Loop
component omitted getter on purpose.

my idea was to upgrade prop binding with a simple new syntax change
that is familiar to all playing with css.

${#loop_id.index}

.....


for those interested in the code :

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);
    }
}

of course,
for it to work .. add this to your app module...

    public static void contributeBindingSource(
            MappedConfiguration<String, BindingFactory> configuration,
            BindingSource bindingSource
            )
    {
        configuration.add("cprop",new ComponentPropBindingFactory(bindingSource));
    }    


      was (Author: hrgdavor):
    I tried this out some time ago,
it is actualy very simple to do.

I added another prefix, used string until first dot
as component id, and delegated the rest of the expression
to prop binding and using just found component as root object.

the only problem was that this worked for my own components,
and not for Loop component. The reason for this is simple, Loop
component omitted getter on purpose.

my idea was to upgrade prop binding with a simple new syntax change
that is familiar to all playing with css.

${#loop_id.index}

.....


for those interested in the code :

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);
    }
}
  
> allow local value and index parameters (i.e. not page class variables) in loop, count ... components
> ----------------------------------------------------------------------------------------------------
>
>                 Key: TAPESTRY-1830
>                 URL: https://issues.apache.org/jira/browse/TAPESTRY-1830
>             Project: Tapestry
>          Issue Type: Improvement
>          Components: tapestry-core
>    Affects Versions: 5.0.5
>            Reporter: M. H. Shamsi
>             Fix For: 5.0.7
>
>
> index and value parameter in loop (and all components like it) often used just in page templates and there is no need to access or change them in page class.
> sharing this parameters to use directly in page templates, may help developers to write most cleaner page classes.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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