There's a databound UI:DROPDOWN on a page, let's say the dropdown shows the countries. I wanna insert a dummy value, let's say "Please select a country", and make this value as selected. How can I manage this with SJC?
You could do it using the way I did: change your database table to have the dummy value i.e.:
id country
--
1 Please select a country
2 Australia
3 Africa
4 America
Then you can do all your bindings accordingly, if it's ordered by id, then the "please select a country" will appear as the default. I believe there is another way to add it by code but I found it easier to modify the database table!
Assuming your items are an array of Option the thing you are probably looging for is an OptionTitle which you can add directly to the array and performs as you require.
And make sure you get all your target countries in the dropdown... Most sites are missing at least one of : Angola, Sudan, Zimbabwe, Sao Tome, Mozambique. It's extreamly irritating to have to enter a form with a drop down list that doesn't have the required items in it.
I made a request bean that generates an array of option from the underlying data and adds the dummy value. Obviously a similar approach with an application bean would work too.
Well, I've found that if I use standard components, that is h:selectOneMenu, I could add dummy value with f:selectItem. What I'm curious whether such thing is possible with ui:dropdown.