« Return to Thread: VWP - dropDown bound to DB question

Re: VWP - dropDown bound to DB question

by titan :: Rate this Message:

Reply to Author | View in Thread

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);
        }

====================================================

Paul Belleville wrote:
So, if the dropDown is bound to a DB table, how do you add in this extra option "select something from list" into the dropDown choices?
  Paul

Don Albertson <Don.Albertson@verizon.net> wrote:
  Paul Belleville said (on or about) 02/14/2007 14:39:
> What if I have a dropDown bound to a DB table so it provides the choices.
> However, I also want to add an empty selection since null is a valid
> choice for this field in which this data will eventually be saved.
> I guess I can add a null to the selection DB table.. is there a better way?
>
> Paul

I usually begin my dropDown lists and comboBoxes with a String
that says "". If that isthe selected Object from the list, then somewhere in my codethere will be a way to handle the fact that what was selected(or not selected) isn't a value that matches in the db andmy code will ensure that the db value is set to NULL.I find NULL values need extra care in many places. For exampleif the db column is a number column and the value is NULLResultSet.getLong() will return 0 which is not quite the samething as NULL.

 « Return to Thread: VWP - dropDown bound to DB question