Drop Down List

Hi there

I've searched the archives, but dont really get what I look for. I have a drop down list. I filled in the Default options to be Active, 1 and Non Active, 0

When a user selects Active I want to save the 1 (int) to my database. I keep on getting the value Null or sometimes one, but never 0... how do I do this? Thanks

[345 byte] By [mpraath] at [2007-11-26 11:46:23]
# 1
What does you code look like (that is saving the getSelected() value to the database)?
jetsons at 2007-7-7 11:56:49 > top of Java-index,Development Tools,Java Tools...
# 2

Hi there - thanks for your reply:

My code is:

if (stock_stockAddDataProvider.canAppendRow()) {

try {

RowKey rowKey = stock_stockAddDataProvider.appendRow();

stock_stockAddDataProvider.setCursorRow(rowKey);

stock_stockAddDataProvider.setValue("Active", rowKey, cboActive.getSelected());

stock_stockAddDataProvider.commitChanges();

info("New Stock " + txtDescr.getText() + " added");

txtDescr.setText(null);

} catch (Exception ex) {

log("Cannot add New Stock ", ex);

error("Cannot add New Stock: " + ex.getMessage());

}

} else {

log("Cannot add New Stock");

error("Cannot add New Stock");

}

return "stock";

}

mpraath at 2007-7-7 11:56:49 > top of Java-index,Development Tools,Java Tools...
# 3
I think the problem is that getSelected is returning an Object and you need to convert that to an int.Try this:Integer selectedInteger = (Integer) cboActive.getSelected();stock_stockAddDataProvider.setValue("Active", rowKey, selectedInteger.intValue());
jetsons at 2007-7-7 11:56:49 > top of Java-index,Development Tools,Java Tools...
# 4

Thanks SO much... I've tried that now, but now it gives me this error...

symbol : method setValue(java.lang.String,com.sun.data.provider.RowKey,int)

location: class com.sun.data.provider.impl.CachedRowSetDataProvider

stock_stockAddDataProvider.setValue("Active", rowKey, selectedInteger.intValue());

1 error

Weird thing is that if I just put a drop down list and customize its options, when I write the getSelected to the info... it writes it as a o or a 1, but if I do it in THIS add event... it always shows NULL... I dont get it...

Cant believe I'm struggling SO much just to get a value from a drop down list. I'm used to doing this in a few minutes in asp :) Maybe its just the learning curve...?

mpraath at 2007-7-7 11:56:49 > top of Java-index,Development Tools,Java Tools...
# 5
PROBLEM SOLVED...Thanks for all your help.From all the changing I FORGOT to add the drop down list to the Virtual Forms....!!!!!! :) Works now.Thanks for your convertion tips, help, effort. Be blessed.
mpraath at 2007-7-7 11:56:49 > top of Java-index,Development Tools,Java Tools...