Created
August 10, 2015 19:51
-
-
Save lucianobezerra/b9ccb0cacd4f6963818c to your computer and use it in GitHub Desktop.
Código para Setar o ID selecionado de um combo em Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void setaTransportadora(Composicao composicao) { | |
int index = 0; | |
int selectedIndex = 0; | |
Transportadora selected = null; | |
if(composicao != null){ | |
selected = composicao.parent(Transportadora.class); | |
} | |
comboTransportadora.removeAllItems(); | |
List<Transportadora> transportadoras = Transportadora.findAll().orderBy("descricao"); | |
for (Transportadora transportadora : transportadoras) { | |
comboTransportadora.addItem(new ComboItem(transportadora.getString("id"), transportadora.getString("descricao"))); | |
if(selected != null && transportadora.getInteger("id").equals(selected.getInteger("id"))){ | |
selectedIndex = index; | |
} | |
index++; | |
} | |
if(selected != null){ | |
comboTransportadora.setSelectedIndex(selectedIndex); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment