0

Critical BUG with Combobox (With Code to Reproduce)

asked 2009-06-01 14:36:18 +0800

sousa1981 gravatar image sousa1981
573 4

updated 2009-06-01 14:57:41 +0800

Firefox works fine. Other browser: Eclipse Internal Browser, IE... not. Change the line at java "Comboitem comboitem = new Comboitem(cnt.getEnt());" to be "Comboitem comboitem = new Comboitem(cnt.getEnt() + " - " + cnt.getNome());" ZUL File:
<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>
Java File:
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);
	}

}
delete flag offensive retag edit

5 Replies

Sort by » oldest newest

answered 2009-06-01 14:59:31 +0800

sousa1981 gravatar image sousa1981
573 4

I will try to create more simple code to reproduce.

But keep in mind that:
> In firefox it works,
> I have already see our developer talk about this bug (when an comboitem contains space)

link publish delete flag offensive edit

answered 2009-06-01 15:56:04 +0800

sousa1981 gravatar image sousa1981
573 4

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>

link publish delete flag offensive edit

answered 2009-06-02 10:03:40 +0800

sousa1981 gravatar image sousa1981
573 4

Until now, without time to create simple code to reproduce

link publish delete flag offensive edit

answered 2009-06-02 20:02:30 +0800

sousa1981 gravatar image sousa1981
573 4

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);

}

link publish delete flag offensive edit

answered 2011-02-09 13:36:08 +0800

trunks gravatar image trunks
12

updated 2011-02-09 13:37:37 +0800

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

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-06-01 14:36:18 +0800

Seen: 633 times

Last updated: Feb 09 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More