• Post Reply Bookmark Topic Watch Topic
  • New Topic

Populated UISelect components via Database  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!