Cesar4
(Cesar Balzer)
February 27, 2011, 3:14pm
1
Hello, I’m trying to do two combobox of states and cities, but do not know how popular the data from the database, and one more thing, as I do to when to select a state, bringing the city its selected state, please help me.
You might want to take a look of
SQLContainer
and the documentation included in the SQLContainer package.
Cesar4
(Cesar Balzer)
March 3, 2011, 12:49pm
3
Joonas Hello, I’m still lost on how to populate the combobox, I’m still beginner and do not quite understand how I call SQLcontainer data to insert into the combobox, I’m doing this:
import com.vaadin.addon.sqlcontainer.SQLContainer;
import com.vaadin.addon.sqlcontainer.connection.JDBCConnectionPool;
import com.vaadin.addon.sqlcontainer.query.TableQuery;
import com.vaadin.data.Item;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.DefaultFieldFactory;
import com.vaadin.ui.Field;
import com.vaadin.ui.Form;
public class EnderecoForm extends Form {
private SQLContainer statesContainer = null;
private JDBCConnectionPool conexao;
private ComboBox Combostate;
private void initContainers() {
try {
TableQuery q1 = new TableQuery(“state”, conexao);
setEnderecoContainer(new SQLContainer(q1));
} catch (SQLException e) {
e.printStackTrace();
}
}
public EnderecoForm() {
initContainers();
IniciaComboBox();
setCaption(“Teste SQLContainer”);
setFormFieldFactory(new DefaultFieldFactory() {
public Field createField(Item item, Object propertyId, Component uiContext) {
Field field = super.createField(item, propertyId, uiContext);
if(propertyId.equals(“IdEstado”)){
Combostate.setCaption(“Estado”);
Combostate.setNullSelectionAllowed(false);
Combostate.setInputPrompt(“Selecione o Estado”);
Combostate.setWidth(“200px”);
Combostate.setRequired(true);
Combostate.setImmediate(true);
/* In this method I will create a listener for when selecting a state to bring the city in the state*/
//Combostate.addListener(list);
return Combostate;
}
field.setWidth("200px");
return field;
}
});
}
public ComboBox InitComboBox(){
Combostate = new ComboBox();
for(int j = 0; j<estadosContainer.size(); j++){
Estados uf = (Estados) estadosContainer.getIdByIndex( j );
Combostate.addItem(uf.getIdEstado());
Combostate.setItemCaption(uf.getIdEstado(), uf.getNomeEstado());
}
return Comboestado;
}
public void setEnderecoContainer(SQLContainer enderecoContainer) {
this.estadosContainer = enderecoContainer;
}
public SQLContainer getEnderecoContainer() {
return estadosContainer;
}
}
dharmendra1
(dharmendra prasad)
June 28, 2013, 5:56pm
4
Hi,
I had the same issue and finally I fixed it. Please check the post http://techieme.in/techieme/handling-two-comboboxes-in-vaadin