aspose file tools
The moose likes JSF and the fly likes Populated UISelect components via Database Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Populated UISelect components via Database" Watch "Populated UISelect components via Database" New topic
Author

Populated UISelect components via Database

Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

Here is how I deal with UISelect components and populating them with a database.



Now to discuss that second method. What happens when the page is posted back for whatever reason, validation error etc, is I have to know which value the select menu should be sitting on. So I have to get the value I stored in the bean and lookup that up in the database. Not a big deal really, just extra code. Here is the JSP section.



So you see, when the page is submitted I store the value in newIssueForm.visit.currentIssue.issueType.id where issueType is JavaBean IssueType and has a property called id. The selectItems calls the getTypeList method shown above to populate the list with all the values I need.

Now, I show all this to ask if this is the best way. Is there a cleaner, smoother, easier way to do this or am I going about it about the best way possible?
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

Ok, here is another way of handling this that I got through after some trial and error.

The following I placed in the constructor. I am currently looking for a better place to put this code.



I also have the following in the same backing bean





That seems to work as well. Not sure if it's really any better. But it uses component binding.
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

Ok, I was trying to get the JSP as simple as possible, so I was able to get rid of the value attribute. But at a cost.

Taking a bit from my code above, if I leave everything as is, I get an error that the value of selectOneMenu (whatever is chosen) is not a String and does not have a converter. Well, it's not a String, it's an Integer. Oddly, if I keep the value attribute with the getters and setters for it, I don't get this error. But with just the binding attribute I get this error. So I modified my code a bit to compinsate..

BEFORE


AFTER


And everything works. Anyone know of a way to make a converter that works with this scenerio?
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Populated UISelect components via Database
 
Similar Threads
DataTable with CommandLinks
Simple list table
Bean request Scope won't Call method
How to prepopulate combo boxes on page startup
JSF drop down.