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:
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
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
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 ?
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
HI
Good and some useful information about Web Solutions you have shared.
I got very good blog to read ofter a long time on this topic. thank you.
- Tanya
Web Design Firm
@ ObjectLab
"Would replacing the values in the context be enough via ListSelectionDialogBinder.SELECTABLE_ITEMS_KEY"
This applies to whole data?
- John Devis
Magento Themes
A great post for sure in describing as too what all is the use of a list selection dialog binder.....
Magento Themes
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
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
You’ve some really useful information written here. Excellent job and keep posting terrific stuff.
virtual assistant
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
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
Wow a great post, the information posted about as how to use a link dialog binder is great.....
Commercial Buildings for Sale
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
This Blog is going places, the people, the layout, amazing to see such dedication and focus.
Hotpoint RFA52S
Keep doing nice work. I am waiting for some fresh helpful posts.
rushmore casino
List selection dialog binder!! that is what for which i was looking for. Thanks
Party Casino Bonus
Thank you, thats very interesting information. I need to share with my friends.
Fort Lauderdale criminal lawyer
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
This Blog is going places, the people, the layout, amazing to see such dedication and focus.
Vancouver Internet Marketing
Great Post with the ability to explain things very well, Thanks for sharing it.
Iraqi Dinar
An excellent post really amazing things found here.Thanks for this great blog sharing..
web designing company
amazing post love your blog
party casino bonus code
thanks for the great post
PokerStars Review
Nice posting dear...
Migraine headaches relief
Thanks for such a great blog. Keep it up..
Miranda Kerr Workout
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
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
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
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.
Great!
Magento form validation
livezilla magento
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
Magento Themes
Magento Extensions
Virtuemart Extensions
Virtuemart Templates
One Page Checkout Virtuemart
Magento One Step Checkout
like this post!
Thanks for sharing
http://blog.magestore.com/category/magento-tutorials/
http://blog.magestore.com/category/magento-certification
Post a Comment