I wonder how hard it would be to build this in to the dropdown component.
You could have a boolean property called "includeNotSelectedItem". If it is
true, then the component would render a "Not Selected" item as the first
item. If this item were selected, it would simply return null.
It seems that this sort of thing is common enough that it would be easier to
manage on the rendering side than mixing it up with all of your data logic,
especially where a simple binding to a datasource would be much cleaner.
j
-----Original Message-----
From:
msergei@... [mailto:
msergei@...] On Behalf Of Sergei
Mutovkin
Sent: Friday, February 23, 2007 8:30 AM
To:
nbusers@...
Subject: Re: [nbusers] VWP - dropDown bound to DB question
On 2/14/07, titan <
lawndale99@...> wrote:
>
> Add the extra option in your prerender method, i.e.
>
> if (dropDown.getSelected() == null) {
>
> // add value to dataprovider
>
> dropDownDataProvider.setCursorRow(dropdownDataProvider.appendRow());
> dropDownDataProvider.setValue("VALUE", -1);
> dropDownDataProvider.setValue("DISPLAY_NAME", "Select
> something from list");
>
> // set selected row for the dropdown list
> dropDown.setSelected(-1);
> }
>
There are two problems with this approach it seems:
1. Item is added at the very end of the list (not a big issue but really
inconsistent with the rest of the pages on the Internet).
2. If you hit the browser's Refresh button on just loaded page, you would
see your item two times.. click more - more items are added to the data
provider.
I do not yet know how to resolve #1 (I'm just a few days into a whole JEE
stuff), but for #2 it can be easily avoided by adding a property to the
SessionBean which will indicate if it is the first time page is loaded
during the session.
--
Sergei