Primefaces dataTable rowEdit事件似乎不起作用

时间:2015-01-20 20:44:04

标签: jsf jsf-2 primefaces datatable

我最近正在调查PrimeFaces。我尝试创建可编辑的DataTable。我从演示中获取了一些代码,并创建了自己的Facelets文件和托管bean。

products.xhtml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://xmlns.jcp.org/jsf/html"
        xmlns:f="http://xmlns.jcp.org/jsf/core"
        xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
        xmlns:c="http://java.sun.com/jsp/jstl/core"
        xmlns:p="http://primefaces.org/ui">

    <h:head>
      <!-- some headers -->
    </h:head>

    <h:body>
        <h:form>
            <p:dataTable id="products" var="product" value="#{productsBean.products}" editable="true" style="margin-bottom: 20px; width: 1000px;">
                <f:facet name="header">Products</f:facet>

                <p:ajax event="rowEdit" listener="#{productsBean.onRowEdit}" />
                <p:ajax event="rowEditCancel" listener="#{productsBean.onRowCancel}" />

                <p:column headerText="Nazwa">
                    <p:cellEditor>
                        <f:facet name="output"><h:outputText value="#{product.name}" /></f:facet>
                        <f:facet name="input"><p:inputText value="#{product.name}" style="width:100%" label="Nazwa"/></f:facet>
                    </p:cellEditor>
                </p:column>

                <!-- more columns... -->            

                <p:column style="width:32px">
                    <p:rowEditor  />
                </p:column>

            </p:dataTable>
        </h:form>
    </h:body>
</html>

ProductsBean.java:

    import java.io.Serializable;
    import java.util.List;

    import javax.ejb.EJB;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.SessionScoped;

    import org.primefaces.event.RowEditEvent;

    // more imports...

    @SessionScoped @ManagedBean
    public class ProductsBean implements Serializable {

    private static final long serialVersionUID = -501520863695260180L;

    @EJB
    private ProductDao productDao;

    @EJB
    private UnitDao unitDao;

    private List<Product> products;
    private List<Unit> units;

    @PostConstruct
    private void init() {
        products = productDao.findAll();
        units = unitDao.findAll();
    }

    public void onRowEdit(RowEditEvent event) {
        System.out.println("onRowEdit");
    }
    public void onRowCancel(RowEditEvent event) {
        System.out.println("onRowCancel");
    }

    public List<Product> getProducts() {
        return products;
    }

    public List<Unit> getUnits() {
        return units;
    }
}

不幸的是,onRowEdit(RowEditEvent)永远不会被调用,只有我的桌子会变红。我没有得到任何其他反馈。正确调用onRowCancel(RowEditEvent)。我做错了什么或我错过了什么?谢谢你的帮助。

0 个答案:

没有答案