You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by George Christman <gc...@cardaddy.com> on 2013/10/16 19:49:20 UTC

Does a Tap service method exist similar to a SelectModelFactory for use in autocompletes.

I'm wondering if there is already a tapestry service available for creating
a string array from an object list similar to the
SelectModelFactory.createSelectModel.

I find myself creating similar code to below in my autocompletes.

public List<String> onProvideCompletionsFromSupervisor(String keyword) {
    List<LDAPProfile> ldapProfiles = ldapCache.findAllLDAPUsers(keyword);

    List<String> results = new ArrayList<>()';

    for(LDAPProfile ldapProfile : ldapProfiles) {
        results.add(ldapProfile.getName);
    }

return results;

Re: Does a Tap service method exist similar to a SelectModelFactory for use in autocompletes.

Posted by Lance Java <la...@googlemail.com>.
Slightly off topic but this is where groovy excels.

List<LDAPProfile> ldapProfiles =
ldapCache.findAllLDAPUsers(keyword)
List<String> names = ldapProfiles*.name

Re: Does a Tap service method exist similar to a SelectModelFactory for use in autocompletes.

Posted by George Christman <gc...@cardaddy.com>.
Ah yes I am, I just created a generic service similar to the
selectModelFactory service to handle this for me. Now all I need is the
following code to get all my autocompletes up and running. It would be
really nice to have it as a part of the core.

    @Inject
    private ListLabelFactory listLabelFactory ;

    public List<Object> onProvideCompletionsFromSupervisor(String keyword) {
        List<LDAPProfile> ldapProfiles =
ldapCache.findAllLDAPUsers(keyword);
        return listLabelFactory .create(ldapProfiles, "label");
    }


On Wed, Oct 16, 2013 at 3:22 PM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Wed, 16 Oct 2013 16:09:15 -0300, George Christman
> <gc...@cardaddy.com> wrote:
>
>  Thiago, do you have any more info on the ValueProvider? I'm just
>> wondering if what's already built into tap will accomplish the goal of my
>> above code snippet. If not, that code snippet would be a nice addition to
>> the
>> SelectModelFactory since it's so commonly used.
>>
>
> I'm sorry, I typed the wrong name: it's ValueLabelProvider, available
> since 5.4, and you're already using it.
>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<us...@tapestry.apache.org>
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York

Re: Does a Tap service method exist similar to a SelectModelFactory for use in autocompletes.

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 16 Oct 2013 16:09:15 -0300, George Christman
<gc...@cardaddy.com> wrote:

> Thiago, do you have any more info on the ValueProvider? I'm just  
> wondering if what's already built into tap will accomplish the goal of  
> my above code snippet. If not, that code snippet would be a nice  
> addition to the
> SelectModelFactory since it's so commonly used.

I'm sorry, I typed the wrong name: it's ValueLabelProvider, available  
since 5.4, and you're already using it.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


Re: Does a Tap service method exist similar to a SelectModelFactory for use in autocompletes.

Posted by George Christman <gc...@cardaddy.com>.
Thiago, do you have any more info on the ValueProvider? I'm just wondering
if what's already built into tap will accomplish the goal of my above code
snippet. If not, that code snippet would be a nice addition to the
SelectModelFactory since it's so commonly used.


On Wed, Oct 16, 2013 at 2:56 PM, George Christman
<gc...@cardaddy.com>wrote:

> It's not quite as elegant as I would have hoped. I only asked because I've
> found over the years of using Tap you never know what these guys may have
> already built, hoping not to reinvent the wheel. Anyhow, unless the tap
> guys have something already built, this ended up being my reusable
> solution.
>
> public class ObjectModelFactoryImpl implements ObjectModelFactory {
>
>     private final PropertyAccess propertyAccess;
>     private final ValueEncoderSource valueEncoderSource;
>     private final ValueLabelProvider<Object> valueLabelProvider;
>
>     public ObjectModelFactoryImpl(PropertyAccess propertyAccess,
> ValueEncoderSource valueEncoderSource, ValueLabelProvider<Object>
> valueLabelProvider) {
>         this.propertyAccess = propertyAccess;
>         this.valueEncoderSource = valueEncoderSource;
>         this.valueLabelProvider = valueLabelProvider;
>     }
>
>     public List<Object> create(List<?> objects, String labelProperty) {
>         PropertyValueLabelProvider propertyValueLabelProvider = new
> PropertyValueLabelProvider(
>                 valueEncoderSource, propertyAccess, labelProperty);
>
>         return createSelectModel(objects, propertyValueLabelProvider);
>     }
>
>     private List<Object> createSelectModel(List<?> objects,
> ValueLabelProvider<Object> labelProvider) {
>         final List<Object> options = CollectionFactory.newList();
>
>         for (Object object : objects) {
>             String label = labelProvider.getLabel(object);
>
>             options.add(label);
>         }
>
>         return options;
>     }
> }
>
> public interface ObjectModelFactory {
>
>     public List<Object> create(List<?> objects, String labelProperty);
>
> }
>
>
>
> On Wed, Oct 16, 2013 at 2:34 PM, Dimitris Zenios <
> dimitris.zenios@gmail.com> wrote:
>
>> What about these?
>>
>> return F.flow(ldapCache.findAllLDAPUsers(keyword)).map(new
>> Mapper<LDAPProfile,String>() {
>>     public String map(LDAPProfile element) {
>>         return element.getName();
>>     }
>> }).toList();
>>
>>
>> On Wed, Oct 16, 2013 at 8:49 PM, George Christman
>> <gc...@cardaddy.com>wrote:
>>
>> > I'm wondering if there is already a tapestry service available for
>> creating
>> > a string array from an object list similar to the
>> > SelectModelFactory.createSelectModel.
>> >
>> > I find myself creating similar code to below in my autocompletes.
>> >
>> > public List<String> onProvideCompletionsFromSupervisor(String keyword) {
>> >     List<LDAPProfile> ldapProfiles =
>> ldapCache.findAllLDAPUsers(keyword);
>> >
>> >     List<String> results = new ArrayList<>()';
>> >
>> >     for(LDAPProfile ldapProfile : ldapProfiles) {
>> >         results.add(ldapProfile.getName);
>> >     }
>> >
>> > return results;
>> >
>>
>
>
>
> --
> George Christman
> www.CarDaddy.com
> P.O. Box 735
> Johnstown, New York
>
>


-- 
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York

Re: Does a Tap service method exist similar to a SelectModelFactory for use in autocompletes.

Posted by George Christman <gc...@cardaddy.com>.
It's not quite as elegant as I would have hoped. I only asked because I've
found over the years of using Tap you never know what these guys may have
already built, hoping not to reinvent the wheel. Anyhow, unless the tap
guys have something already built, this ended up being my reusable
solution.

public class ObjectModelFactoryImpl implements ObjectModelFactory {

    private final PropertyAccess propertyAccess;
    private final ValueEncoderSource valueEncoderSource;
    private final ValueLabelProvider<Object> valueLabelProvider;

    public ObjectModelFactoryImpl(PropertyAccess propertyAccess,
ValueEncoderSource valueEncoderSource, ValueLabelProvider<Object>
valueLabelProvider) {
        this.propertyAccess = propertyAccess;
        this.valueEncoderSource = valueEncoderSource;
        this.valueLabelProvider = valueLabelProvider;
    }

    public List<Object> create(List<?> objects, String labelProperty) {
        PropertyValueLabelProvider propertyValueLabelProvider = new
PropertyValueLabelProvider(
                valueEncoderSource, propertyAccess, labelProperty);

        return createSelectModel(objects, propertyValueLabelProvider);
    }

    private List<Object> createSelectModel(List<?> objects,
ValueLabelProvider<Object> labelProvider) {
        final List<Object> options = CollectionFactory.newList();

        for (Object object : objects) {
            String label = labelProvider.getLabel(object);

            options.add(label);
        }

        return options;
    }
}

public interface ObjectModelFactory {

    public List<Object> create(List<?> objects, String labelProperty);

}



On Wed, Oct 16, 2013 at 2:34 PM, Dimitris Zenios
<di...@gmail.com>wrote:

> What about these?
>
> return F.flow(ldapCache.findAllLDAPUsers(keyword)).map(new
> Mapper<LDAPProfile,String>() {
>     public String map(LDAPProfile element) {
>         return element.getName();
>     }
> }).toList();
>
>
> On Wed, Oct 16, 2013 at 8:49 PM, George Christman
> <gc...@cardaddy.com>wrote:
>
> > I'm wondering if there is already a tapestry service available for
> creating
> > a string array from an object list similar to the
> > SelectModelFactory.createSelectModel.
> >
> > I find myself creating similar code to below in my autocompletes.
> >
> > public List<String> onProvideCompletionsFromSupervisor(String keyword) {
> >     List<LDAPProfile> ldapProfiles = ldapCache.findAllLDAPUsers(keyword);
> >
> >     List<String> results = new ArrayList<>()';
> >
> >     for(LDAPProfile ldapProfile : ldapProfiles) {
> >         results.add(ldapProfile.getName);
> >     }
> >
> > return results;
> >
>



-- 
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York

Re: Does a Tap service method exist similar to a SelectModelFactory for use in autocompletes.

Posted by Dimitris Zenios <di...@gmail.com>.
What about these?

return F.flow(ldapCache.findAllLDAPUsers(keyword)).map(new
Mapper<LDAPProfile,String>() {
    public String map(LDAPProfile element) {
        return element.getName();
    }
}).toList();


On Wed, Oct 16, 2013 at 8:49 PM, George Christman
<gc...@cardaddy.com>wrote:

> I'm wondering if there is already a tapestry service available for creating
> a string array from an object list similar to the
> SelectModelFactory.createSelectModel.
>
> I find myself creating similar code to below in my autocompletes.
>
> public List<String> onProvideCompletionsFromSupervisor(String keyword) {
>     List<LDAPProfile> ldapProfiles = ldapCache.findAllLDAPUsers(keyword);
>
>     List<String> results = new ArrayList<>()';
>
>     for(LDAPProfile ldapProfile : ldapProfiles) {
>         results.add(ldapProfile.getName);
>     }
>
> return results;
>

Re: Does a Tap service method exist similar to a SelectModelFactory for use in autocompletes.

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
ValueProvider?

On Wed, 16 Oct 2013 14:49:20 -0300, George Christman  
<gc...@cardaddy.com> wrote:

> I'm wondering if there is already a tapestry service available for  
> creating
> a string array from an object list similar to the
> SelectModelFactory.createSelectModel.
>
> I find myself creating similar code to below in my autocompletes.
>
> public List<String> onProvideCompletionsFromSupervisor(String keyword) {
>     List<LDAPProfile> ldapProfiles = ldapCache.findAllLDAPUsers(keyword);
>
>     List<String> results = new ArrayList<>()';
>
>     for(LDAPProfile ldapProfile : ldapProfiles) {
>         results.add(ldapProfile.getName);
>     }
>
> return results;


-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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