-
FEATURED COMPONENTS
First time here? Check out the FAQ!
<window id="xxxForm" title="Tesoureiro EDM" width="100%" height="100%" border="normal" apply="${xxxForm}"> <grid> <rows> <row>Entidade: <combobox id="entidade" cols="26"/></row> </rows> </grid> </window>
public class XxxForm extends GenericForwardComposer { @Autowired @Qualifier("cntService") private GenericService cntService; private Combobox entidade; public XxxForm() { } public void onCreate$tesoureiroEdmForm(Event event) { populateEntidade(); } public void onClick$finalizar(Event event) { Comboitem item = entidade.getSelectedItem(); log.info("item:" + item + ":"); CNT cnt = item != null ? (CNT)item.getValue() : null; log.info("cnt:" + cnt + ":"); } private void populateEntidade() { Cnt example = new Cnt(); example.setNome("ZK%"); List<CNT> cnts = (List<CNT>)sdpscntService.findByExample(example); entidade.getChildren().clear(); for (CNT cnt : cnts) { Comboitem comboitem = new Comboitem(cnt .getEnt()); comboitem.setValue(cnt); entidade.appendChild(comboitem); } } }
@Entity @Table(name = "CNT", schema = "XXX") public class CNT implements Serializable { @Id private String ent; private String abv; private String nome; public CNT() { } public String getEnt() { return psent; } public void setEnt(String ent) { this.ent = ent; } public String getAbv() { return abv; } public void setAbv(String abv) { this.abv = abv; } public String getNome() { return nome; } public void setNome(String nome) { this.nome = nome; } public boolean equals(Object o) { if (!(o instanceof CNT)) return false; CNT cnt = (CNT) o; return cnt.ent.equals(ent); } }
I write an simple test case, but it works.
Maybe the problem is with GenericForwardComposer.
Now, I have no more time to work over it.
I will work over it later.
<?page id="indexPage" title="BCI - O MEU BANCO" contentType="text/html;charset=UTF-8"?> <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" ?> <?evaluator name="mvel"?> <window width="100%" border="normal" title = "Combobox BUG"> Combobox: <combobox id="cbo" onCreate="fill()" /> <button label="test" onClick="print()" /> <zscript> <![CDATA[ public void fill() { Person person1 = new Person("F1", "L1"); Person person2 = new Person("F2", "L2"); Person person3 = new Person("F3", "L3"); List persons = new ArrayList(); persons.add(person1); persons.add(person2); persons.add(person3); cbo.getChildren().clear(); for (Person person : persons) { Comboitem comboitem = new Comboitem(person.getFirstName() + " - " + person.getLastName()); comboitem.setValue(person); cbo.appendChild(comboitem); } } public void print() { Comboitem item = cbo.getSelectedItem(); Person person = item != null ? (Person)item.getValue() : item; alert("Selected Person: " + person); } ]]></zscript> </window>
After work over this issue, just to understand what is happening, I found that the following code (javascript validation code), is interfering with ZK.
The code, was an old code.
function minValue(comp, min, errorMsg) {
var comp = $e(comp);
if (comp.value < min) {
return errorMsg;
}
}
function betweenValue(comp, min, max, errorMsg) {
var comp = $e(comp.id + "!real");
if (!(comp.value >= min && comp.value <= max)) {
return errorMsg;
}
}
function setActiveStyleSheet(estilo) {
var i, elemento;
for (i = 0; (elemento = document.getElementsByTagName("link")); i++) {
if (elemento.getAttribute("href").indexOf("/BciCamp/css/bci_") != -1) {
if (estilo == "azul") {
elemento.href = "/BciCamp/css/bci_" + estilo + ".css";
createCookie("bci_style", estilo, 365);
} else {
if (estilo == "verde") {
elemento.href = "/BciCamp/css/bci_" + estilo + ".css";
createCookie("bci_style", estilo, 365);
}
}
}
}
}
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca;
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
window.onload = function(e) {
var estilo = readCookie("bci_style");
setActiveStyleSheet(estilo);
}
Buen día.
Gracias sousa1981 por compartir tu experiencia y tu código, me fue de mucha utilidad.
Ejemplo:
Código Para agregar información al combobox:
GestionEstado gestionEstado = new GestionEstado();
arrayListEstados = new ArrayList();
arrayListEstados = gestionEstado.consultarEstados();
this.cbx_Estado.getChildren().clear();
for(int x = 0; x < arrayListEstados.size(); x++)
{
Estado estado = new Estado();
estado = (Estado) arrayListEstados.get(x);
Comboitem comboitem = new Comboitem(estado.getNombre_estado());
comboitem.setValue(estado);
this.cbx_Estado.appendChild(comboitem);
}
Código para retornar la selección del combobox:
Comboitem comboitem = this.cbx_Estado.getSelectedItem();
Estado estado = new Estado();
if(comboitem != null)
{
estado = (Estado) comboitem.getValue();
}
else
{
estado = null;
}
System.out.println(estado.getId_estado());
System.out.println(estado.getNombre_estado());
Gracias.
Juank
Bogota - Colombia
Asked: 2009-06-01 14:36:18 +0800
Seen: 633 times
Last updated: Feb 09 '11