This is the development blog of the Spring Rich Client Project Team.

Monday, January 7, 2008

How to use the ListSelectionDialogBinder

This tutorial is based on the Simple Sample.

We will add new property "favorite fruit" to the Contact class.

First we create a new Fruit class:
public class Fruit {
private String name;
public Fruit(String name) {
this.name = name;
}

public String getName() {
return name;
}
}

Then we add the favoriteFruit property:
public class Contact {
...
private Fruit favoriteFruit;
...
public Fruit getFavoriteFruit() {
return favoriteFruit;
}
public void setFavoriteFruit(Fruit fruit) {
this.favoriteFruit = fruit;
}
}

In the richclient-application-context.xml we have to define the ListSelectionDialogBinder for properties of the type Fruit:

<bean id="binderSelectionStrategy" class="org.springframework.richclient.form.binding.swing.SwingBinderSelectionStrategy">
<property name="bindersForPropertyTypes">
<map>
<entry>
<key><value type="java.lang.Class">org.springframework.richclient.samples.simple.domain.Fruit</value></key>
<bean class="org.springframework.richclient.selection.binding.ListSelectionDialogBinder"/>
</entry>
</map>
</property>
</bean>

The only thing that's left is the ContactForm.

For the ListSelectionDialogBinder it's necessary to build a context to feed to the binding.

A context is nothing more than a Map.
    Map fruitContext = new HashMap();


Here we build the list of fruits the user can choose from, but in real life this will probably come from the database ...
    List fruits = new ArrayList();
fruits.add(new Fruit("apple"));
fruits.add(new Fruit("banana"));
fruits.add(new Fruit("kiwi"));
fruits.add(new Fruit("orange"));
fruits.add(new Fruit("pear"));


We use the fruit in the selectable items:
    fruitContext.put(ListSelectionDialogBinder.SELECTABLE_ITEMS_KEY, fruits);


The following code will use the name of the fruit as label, and will show "<no>" for null values:
    fruitContext.put(ListSelectionDialogBinder.LABEL_PROVIDER_KEY, new LabelProvider() {
public String getLabel(Object item) {
Fruit bean = (Fruit) item;
return bean == null ? "" : bean.getName();
}
});


If you want filtering, add the following entries. This will allow the user to filter the dialog on the name property of the fruit.
    fruitContext.put(ListSelectionDialogBinder.FILTERED_KEY, Boolean.TRUE);
fruitContext.put(ListSelectionDialogBinder.FILTER_PROPERTIES_KEY,
new String[] { "name" });


And finally we add the binding to the form:
    formBuilder.addSeparator("Fun stuff");
formBuilder.row();
formBuilder.add(getBindingFactory().createBinding("favoriteFruit", fruitContext),
"colSpan=1");


And this is the result:

Nothing selected:


And when we click on the select button:


And select "orange" we get this:

38 comments:

ObjectLab/Appendium said...

Excellent post. I'd love to see more of these. Question: how would you envisage a system where the list would vary AFTER the screen has been created?

Would replacing the values in the context be enough via ListSelectionDialogBinder.SELECTABLE_ITEMS_KEY

I think it would be a good follow-up on this article.

Thanks

Dominik Dorn said...

there is an error in your post... instead of

[code]
fruitContext.put(ListSelectionDialogBinder.SELECTABLE_ITEMS_KEY, fruits);
[/code]

one have to code

[code]
fruitContext.put(ListSelectionDialogBinder.SELECTABLE_ITEMS_HOLDER_KEY, new ValueHolder(fruits));
[/code]

also it would be nice if you could also post the sample application (zip/tgz) additionally to the screenshots.

thx,
dominik

Quinten Verheyen said...

Very usefull post !!

Going on that road, I think it would be even more intuitive w/o the dialog window. I imagine instead the list popping up, like google does (or any Ajax web application). Don't know the feasibility of this though, and what factors make this approach difficult/impossible ?

James praker said...

The using of the list selection dialog blinder is a very good tutorial, i am thinking to add the information about these kind of tutorials in my websites!
Thanks for sharing this useful post!
cheers mate!

-J.
graphic design company

Unknown said...

HI

Good and some useful information about Web Solutions you have shared.

zcocorporation said...
This comment has been removed by the author.
tania said...

I got very good blog to read ofter a long time on this topic. thank you.

- Tanya
Web Design Firm

Jhon Davis said...

@ ObjectLab
"Would replacing the values in the context be enough via ListSelectionDialogBinder.SELECTABLE_ITEMS_KEY"

This applies to whole data?

- John Devis
Magento Themes

Magento Templates said...
This comment has been removed by the author.
Magento Templates said...

A great post for sure in describing as too what all is the use of a list selection dialog binder.....

Magento Themes

Maninder Kaur said...

I can see that you’re an expert in this region. I am starting an internet site soon, and your information will be very helpful for me.. Thank you for all of your help and wishing you all the success inside your business.

Kiosk Manufacturers

SEO Services Consultants said...

Hi, interesting post. I have been wondering about this topic, so thanks for posting. I’ll definitely be subscribing to your site. Keep up the good posts
Lose Weight Running

SEO Services Consultants said...

You’ve some really useful information written here. Excellent job and keep posting terrific stuff.
virtual assistant

Anonymous said...

excellenct information you give

Thank
Regards
Poh
Cuisinart TOB-195
Acne Conglobata
Acer 11.6 Netbook
500 payday loan
acne inversa
VIZIO M261VP
checkmate payday loans

Vasectomy said...
This comment has been removed by the author.
Vasectomy said...

This is a good common sense article. Very helpful to one who is just finding the resources about this part. It will certainly help educate me.



Vasectomy

Unknown said...

Wow a great post, the information posted about as how to use a link dialog binder is great.....

Commercial Buildings for Sale

businesscoach said...

I’ve learned a lot from your blog here, Keep on going, my friend, I will keep an eye on it,

Nassau County business coach

Ultimate Appliances said...

This Blog is going places, the people, the layout, amazing to see such dedication and focus.
Hotpoint RFA52S

peter north said...

Keep doing nice work. I am waiting for some fresh helpful posts.

rushmore casino

peter north said...

List selection dialog binder!! that is what for which i was looking for. Thanks

Party Casino Bonus

SEO Services Consultants said...

Thank you, thats very interesting information. I need to share with my friends.

Fort Lauderdale criminal lawyer

Sunitha M said...

I am really inspired together with your writing abilities as smartly as with the structure for your weblog. Keep up the excellent quality writing, it's uncommon to see a nice blog like this one nowadays.joomla development | joomla developers

wyntech solutions said...

This Blog is going places, the people, the layout, amazing to see such dedication and focus.
Vancouver Internet Marketing

Dinar Inc said...

Great Post with the ability to explain things very well, Thanks for sharing it.

Iraqi Dinar

Anonymous said...

An excellent post really amazing things found here.Thanks for this great blog sharing..
web designing company

hassan said...

amazing post love your blog
party casino bonus code

hassan said...

thanks for the great post
PokerStars Review

Unknown said...

Nice posting dear...

Migraine headaches relief

Unknown said...

Thanks for such a great blog. Keep it up..
Miranda Kerr Workout

Unknown said...

This is a good common sense Blog. Very helpful to one who is just finding the resources about this part. It will certainly help educate me.
Advanced Amino Acids

Unknown said...

Thank you for sharing the knowledge
Magento extensions Magento extension Magento modules Magento Magento gift card Magento blog Magento tutorial Magento affiliate Magento menu Magento SEO

Unknown said...

This internet site is my intake , rattling wonderful design and style and perfect subject material.

Magento Checkout
Magento Facebook
Magento tutorials
Magento tutorial for beginners

CK TAN said...

Canon EOS T4i
Canon EOS Rebel T4i
canon EOS T4i is a powerful camera and this is show the detail info, video how to use canon eos t4i and the user review.

Unknown said...

Great!

Magento form validation
livezilla magento

Unknown said...

I imagine instead the list popping up, like google does (or any Ajax web application). Don't know the feasibility of this though, and what factors make this approach difficult/impossible ?Can you give me better example ?
Computer Enclosures

Unknown said...

Magento Themes
Magento Extensions
Virtuemart Extensions
Virtuemart Templates
One Page Checkout Virtuemart
Magento One Step Checkout

rubik_hd said...

like this post!

Thanks for sharing

http://blog.magestore.com/category/magento-tutorials/
http://blog.magestore.com/category/magento-certification