For reference, adding this:
ObjectAutoCompleteRenderer<Person> renderer = new
ObjectAutoCompleteRenderer<Person>(){
protected String getIdValue(Person p) {
return p.getUuid();
}
protected String getTextValue(Person p) {
return p.getDisplayName();
}
};
and then:
builder.autoCompleteRenderer(renderer);
Does what I want. Thanks for the tip!
cheers,
Steve
On 22/12/2009, at 10:57 AM, Steve Swinsburg wrote:
> Actually I have just found in the javadocs the
> AbstractObjectAutoCompleteRenderer which does the separation.
>
> I'll give that a go.
>
> cheers,
> Steve
>
> On 22/12/2009, at 10:54 AM, Steve Swinsburg wrote:
>
>> I decided against using the ObjectAutoCompleteTextField because it was too
>> restrictive in the Object you supply. I went with the component on the wiki
>> and ended up adding another getter/setter to my page to separate the value
>> from the display when it gets the object selected.
>>
>> However, I revisited the Wicketstuff component with your suggestion, and
>> adding:
>> builder.idProperty("userId");
>>
>> works to set the value for the field that is submitted.
>>
>> However, there is no way to tell it the value to use for the display! It's
>> just serializing the Object I give it as the display (ie
>> my.package.model.per...@77aa0759])
>>
>> What I need is to give it a list of objects and to be able to specify what
>> properties to use for the display value and the submit value. It needs
>> something like:
>> builder.displayProperty("displayName");
>>
>> thanks,
>> Steve
>>
>> On 22/12/2009, at 10:00 AM, Albert Romanius wrote:
>>
>>> I am not sure, but you could try to set idProperty in
>>> ObjectAutoCompleteBuilder
>>>
>>>
>>> On Mon, Dec 21, 2009 at 10:54 AM, Steve Swinsburg
>>> <[email protected]> wrote:
>>>> On further investigation, the values aren't being separated after all. What
>>>> is added to the textfield is what is submitted in the form.
>>>> Is it possible to submit a different value than just the display text?
>>>> thanks,
>>>> Steve
>>>>
>>>> On 21/12/2009, at 1:54 PM, Steve Swinsburg wrote:
>>>>
>>>> Nevermind. I ended up going with this approach where I could separate the
>>>> values:
>>>> http://cwiki.apache.org/WICKET/autocomplete-using-a-wicket-model.html
>>>> I will add my code snippet to the page.
>>>> cheers,
>>>> Steve
>>>> On 21/12/2009, at 11:57 AM, Steve Swinsburg wrote:
>>>>
>>>> Hi,
>>>> I am using ObjectAutoCompleteField from WicketStuff and it looks like what
>>>> I
>>>> need for my scenario:
>>>> I have an object list with a bunch of fields and when the user searches, it
>>>> needs to match on a certain field and display the list of matches. The
>>>> examples do this with a Car object with an Integer field for the ID and a
>>>> String for the car name.
>>>> However, there seems to be no way to tell it *what* fields to use in the
>>>> supplied object. You can only give the component the Type of fields to look
>>>> up, and it gets the field to use by reflection. This assumes only one field
>>>> in that object will be of that Type.
>>>> ie
>>>> How could I make it would with a list of these objects:
>>>> class Person {
>>>> String userId;
>>>> String displayName;
>>>> ...
>>>> }
>>>> Giving the ObjectAutoCompleteField the types <Person,String> won't work, it
>>>> won't know what field to use.
>>>>
>>>> List<Person> persons = getPersons();
>>>> ObjectAutoCompleteBuilder<Person,String> builder = new
>>>> ObjectAutoCompleteBuilder<Person,String>(
>>>> new AutoCompletionChoicesProvider<User>() {
>>>> public Iterator<Person> getChoices(String input) {
>>>> List<Person> subSet = getPersonSubSet(persons, input);
>>>> return subSet.iterator();
>>>> }
>>>> }
>>>> );
>>>> ObjectAutoCompleteField toField = builder.build("toField", new
>>>> Model<String>());
>>>> form.add(toField);
>>>>
>>>> Any ideas?
>>>> thanks,
>>>> Steve
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Albert
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [email protected]
>>> For additional commands, e-mail: [email protected]
>>>
>>
>
smime.p7s
Description: S/MIME cryptographic signature
