File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Binding a selectOneMenu component to a managed bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Binding a selectOneMenu component to a managed bean" Watch "Binding a selectOneMenu component to a managed bean" New topic
Author

Binding a selectOneMenu component to a managed bean

ernest fakudze
Ranch Hand

Joined: Aug 27, 2001
Posts: 216
Hi guys,

I'm new to JSF and find it very exciting. I've been trying to figure out the basics but today I've spent the whole day trying to work out how to bind a
selectOneMenu component to a backend bean method which returns an HtmlSelectOneMenu component.

Here is what I have:

1. A Map of people's salutations as follows:

This is then configured as a manages bean as follows:



Againg I'n not sure if this is correct.

I've read somewhere that it makes for cleaner JSP code to do it this way although you end up with extra Java code. I agree with this and i wan to follow it.

So can someone please shed some light. Where am I goign wrong.
Gregg Bolinger talked about this in the thread here: http://www.coderanch.com/t/211197/JSF/java/JSF-drop-down
but I haven't managed to get oit to work.

Oo, the error I got was



In a time of drastic change it is the learners who inherit the future. The learned usually find themselves equipped to live in a world that no longer exists.<br />Eric Hoffer
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Your map is a good idea, and you can bind it to the select items of a menu as follows.

Now, if you want to bind the *selection* to a backing bean, write:

And in that backing bean there will be:

Unless you are doing something much more complex, don't bind the component itself.


There is no emoticon for what I am feeling!
ernest fakudze
Ranch Hand

Joined: Aug 27, 2001
Posts: 216
Thanks Jeff for your help. You explain it well and I understand. I've just realised that JSF is quite a beast and to get my head around it I have to spend many hours locked by myself in my study room I've been doing a great deal of reading and a lot of this binding stuff is now beginning to make sense.

You say..
Unless you are doing something much more complex, don't bind the component itself.


...I guess I'm making it too complicated unnecessarily. However, I 've got one question: eventually the data to populate the drop down list is going to come from a dtabase table. Wouldn't it be a good idea to bind the component itself in that case? I will be looping over a ResultSet and populating SelectItems for that selectOneMenu. Am I thinking straight?

I think the jstl:sql tag is not supported inside a JSF view. I tried and my c:foreach loop did not work

Regards,
Ernest
[ February 14, 2006: Message edited by: ernest fakudze ]
ernest fakudze
Ranch Hand

Joined: Aug 27, 2001
Posts: 216
Ah never mind, I've just been to lunch and while I was out there I remembered that this time the map is going to be populated using the database (2 columns) and there is still no need to bind the component itself.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Binding a selectOneMenu component to a managed bean