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:

51 comments:

ObjectLab 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 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

Mordred 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 ?

seo expert said...

Thanks ur information

web design company, web designer,
web design India,website design,web design

milf said...

new houston house houston house tx stains removal dye
stains removal clothes stains removal teeth whitening
teeth whiteningbright teeth jennifer grey nose
jennifer nose jobs calebrities nose jobs Women with Big Noses
Women hairstyles Big Nose Women, hairstylesdvd player troubleshootingtroubleshooting with the dvd player

milf said...

dessicant air dryer pediatric asthma asthma specialist
carpet cleaning dallas tx carpet cleaners dallas carpet cleaning dallas
beach vacations your beach vacations
bob hairstyle
bob haircuts bob layered pob hairstyle
bobbed classic bob Care for Curly Hair
Tips for Curly Hair curly hair 12r 22.5 best price
tires truck bus tires 12r 22.5 washington new house
new house Houston new house san Antonio new house ventura
sealy air beds portable portables air beds
antique doorknobs drying desiccant
air drying desiccantlipitor allergic reactionsApple prodam iphone prahaflorida headache clinic
cheap beach vacationsnight vision binoculars bargains

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

Sybo said...

HI

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

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

Really nice blog, very informative. Thanks dude for wonderful posting. Keep it up in the future as well. SEO Services UK

Pooja said...

Nice information, many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again and good luck! Web Design Company

tania said...

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

- Tanya
Web Design Firm

Jhon 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

poh 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

poh said...

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

poh said...

Thank
Regards
Poh
Counter Depth French Door Refrigerator
How to Get Into Acting
Breville Smart Oven
How to Impress Woman
Picking Lottery Numbers
Canon Powershot A800
Adidas Barricade
Adidas Barricade 6.0
Cuisinart TOB-195
Acne Conglobata
Acer 11.6 Netbook
500 payday loan
acne inversa
VIZIO M261VP
checkmate payday loans
Pengurusan Masa

poh said...

now that great
Thank
Regards
Poh
Counter Depth French Door Refrigerator
How to Get Into Acting
Breville Smart Oven
How to Impress Woman
Picking Lottery Numbers
Canon Powershot A800
Adidas Barricade
Adidas Barricade 6.0
Cuisinart TOB-195
Acne Conglobata
Acer 11.6 Netbook
500 payday loan
acne inversa
VIZIO M261VP
checkmate payday loans
Pengurusan Masa

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

Chloe said...

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

Commercial Buildings for Sale

poh said...

Counter Depth French Door Refrigerator
How to Get Into Acting
Breville Smart Oven
How to Impress Woman
Picking Lottery Numbers
Canon Powershot A800
Adidas Barricade
Cuisinart TOB-195
Acne Conglobata
Acer 11.6 Netbook
500 payday loan
acne inversa
VIZIO M261VP
checkmate payday loans
Pengurusan Masa
How To Stop Panic Attacks
Didik anak
Langsing
Adidas Barricade 6.0
Adidas Barricade V

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

Inventory said...

Another informative blog… Thank you for sharing it… Best of luck for further endeavor too.Dropshipper

Hotpoint RFA52S 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 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

Adol said...

I am not that much familiar with this information. So I can't understand. Can you explain me with more information? buy domain name India

mumtaz 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

Migracapusa said...

Nice posting dear...

Migraine headaches relief

Fortius Fitness said...

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

Donald Wiencek 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

Hung Tran 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

rocky case said...

Really your blog is very interesting.... it contains great and unique information. I enjoyed to visiting your blog. It's just amazing.... Thanks very much for the share.

ngọc anh bùi 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.

cmsmart said...

Magento Jewelry Theme
Magento Printing Website Theme
Magento Facebook Login
Magento Themes
Magento Extensions

Dao Tan said...

Great!

Magento form validation
livezilla magento

amelie adam 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

Asiatica Exchanglink 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