The Idea of the Code:
i want to measure the powerconsumption for my house. i want to create an electric meter for every rent payer living int the house. for every electric meter i want to add every month a date and the value of the counter. at the end of the year i want to have an overview to see the power consumption.
Hi,
i have a problem to understand how to set a datasource or item for a combobox. My steps:
- I have a class, extended from “Form” with 2 Textfields to get the “name” and “number” of a Counter (e.g. Number 1234, Name = “rent payer mr. T”) . i can add these 2 values to the datasource with following code:
(class extende from Form)
Counter c = new Counter();
setItemDataSource(new BeanItem(c));
In the Clickhandler for the Button “Save” i do:
if(source == save){
...!isValid();... /short form written here
...commit();...
Item addedItem = app.getCounterDataSource().addItem(c);
setItemDataSource(addedItem);
Until here everything is ok. i can add this datasource to a table an see my entries:
Table t = new Table();
t.setContainerDataSource(app.getCounterDataSource());
With the next Step i have problems:
I want to have a combobox filled with the names of counters in the datasource. if a counter is selected by name i want to add “Countervalues” to the Vector of the “Counter” class.
My Sourcecode:
public class Counter implements Serializable{
private String Name;
private String Number;
private Vector<CounterValues> Values = new Vector<CounterValues>();
public Vector<CounterValues> getValues () {
return Values ;
}
public void setValues (CounterValues Value) {
this.Values.push_back(Values) ;
}
public Counter (){
}
setter() and getter()....
public class CounterValues implements Serializable{
private Date CDate;
private float CValues;
public CounterValues(Date _Date ,float _CValue){
this.CDate= _Date;
this.CValues= _CValue;
}
setter() and getter()....
public class CounterValuesContainer extends BeanItemContainer<Zähler> implements Serializable {
createwithTestdata(){
....
}
...
}
- how do i create a combobox with all available counters?
- how do i add the values of a form to the vector of a counter?
How it should work:
- creating a Counter with Name and Number (works)
- show Combobox with available counters
- if one is selected show new Form to add to the selected Count a CounterValue (Date and value)