我无法使用zk在按钮中获取事件

时间:2014-10-16 11:49:23

标签: button zk

我是新用的ZK,最近我开始了一个proyect,在我的index.zul和一个列表框中收集来自db的数据,所有这一切都好,但问题是当我尝试过滤时,使用按钮进行搜索,我无法通过此按钮获取活动。有我简单的代码.zul和控制器。

.zul

<window id="win" apply="test.listbox.composer.ListboxModelRendererComposer">

    <!-- Tested with ZK 6.0.2 -->
    Filtro
    <textbox id="pepito" value="Gar" instant="true"/>
    <button id="saveButton" label="Buscar"></button>

    <div style="margin: 10px;">
        <vbox>
            <label value="Listado de legajos San Fernando" />
            <div height="10px" />
            <listbox id="lbThree" emptyMessage="La busqueda no retorno resultados" />
        </vbox>
    </div>
</window>

public class ListboxModelRendererComposer extends GenericForwardComposer {
Listbox lbThree;
Textbox pepito;
Button saveButton;

@Override
public void doAfterCompose (Component comp) throws Exception {
    super.doAfterCompose(comp);

    // set models and render to listbox after comopsed
    lbThree.setModel(getLegajosModel());

    lbThree.setItemRenderer(new PersonListitemRenderer());
}

public ListModel getSimpleStringModel () {
    List l = new ArrayList();

    // simply add some Strings to a list
    // than wrap the list by a ListModelList
    l.add("data one");
    l.add("data two");
    l.add("data three");

    return new ListModelList(l);
}
public ListModel getLegajosModel () {
    List legajos;

    EntityManagerFactory emf;
    emf = Persistence.createEntityManagerFactory("TestRenderPU");
    EntityManager em = emf.createEntityManager();
    javax.persistence.Query q = em.createQuery("select c from LegLEGAJO as c WHERE c.apellido LIKE :filtro OR c.nombre LIKE :filtro OR c.tipoLegajo LIKE :filtro OR c.legajo LIKE :filtro");
    q.setParameter("filtro", "%" + pepito.getValue() + "%");
    legajos = q.getResultList();
    em.close();

    return new ListModelList(legajos);
}

@Listen(Events.ON_CLICK + " = #saveButton")
public void saveButtonClicked(Event event) {
    alert("Hello!!!");
} 

}

1 个答案:

答案 0 :(得分:1)

您有两种方式:

第一个:

扩展SelectorComposer

连接组件:

Listbox lbThree;
Textbox pepito;
Button saveButton;

更改为:

@Wire
private Listbox lbThree;
@Wire
private Textbox pepito;
@Wire
private Button saveButton;

第二个做出正确的@Listen

@Listen("onClick = #saveButton")

第二个:

保留GenericForwardComposer:

public void onClick$saveButton(Event event) {
    //...
}

编辑:更正为@NabilA。评价。