繁体   English   中英

Primefaces 4.0 dataTable对话框详细信息不起作用

[英]Primefaces 4.0 dataTable dialog details doesn't working

我正在使用PrimeFaces 4.0和Netbeans 6.9.1。 我在这里关注了primefaces演示:

数据表单选

一切正常,期望按钮视图。 这是我的代码:

Customer_list.xhtml

<p:growl id="msgs" showDetail="true" />
<h:form id="formTable">
    <p:dataTable styleClass="table" id="customers" var="customer" value="#{customerBean.customer}">

        <p:column>
            <f:facet name="header">First Name</f:facet>
            #{customer.firstName}
        </p:column>

        <p:column>
            <f:facet name="header">Last Name</f:facet>
            #{customer.lastName}
        </p:column>

        <p:column>
            <f:facet name="header">Email</f:facet>
            #{customer.email}
        </p:column>

        <p:column>
            <f:facet name="header">DOB</f:facet>
            #{customer.dob}
        </p:column>
        <p:column style="width:4%">
            <p:commandButton id="selectButton" update=":formCreate" oncomplete="dialogCustomerCreate.show()" icon="ui-icon-search" title="Update">
                <f:setPropertyActionListener value="#{customer}" target="#{customerBean.selectedCustomer}" />
            </p:commandButton>
        </p:column>
    </p:dataTable>
</h:form>
<h:form id="formCreate">
    <p:dialog header="Create New Customer" widgetVar="dialogCustomerCreate" resizable="false" id="dlgCustomerCreate"
              showEffect="fade" hideEffect="explode" modal="true">

        <h:panelGrid id="display" columns="2" cellpadding="4" style="margin:0 auto;">

            <h:outputText value="First Name:" />
            <h:outputText value="#{customerBean.selectedCustomer.firstName}" style="font-weight:bold"/>

            <h:outputText value="Last Name:" />
            <h:outputText value="#{customerBean.selectedCustomer.lastName}" style="font-weight:bold"/>


            <h:outputText value="Email:" />
            <h:outputText value="#{customerBean.selectedCustomer.email}" style="font-weight:bold"/>

            <h:outputText value="DOB:" />
            <h:outputText value="#{customerBean.selectedCustomer.dob}" style="font-weight:bold"/>

        </h:panelGrid>

    </p:dialog>

</h:form>

customerBean.java

public class customerBean {

    private List<Customer> customer;
    private Customer selectedCustomer;

    /** Creates a new instance of customerBean */
    public customerBean() {
        customer = new ArrayList<Customer>();        
    }

    public List<Customer> getCustomer() {
        CustomersDao cust_dao = new CustomersDao();
        customer = cust_dao.findAll();
        return customer;
    }

    public Customer getSelectedCustomer() {
        return selectedCustomer;
    }

    public void setSelectedCustomer(Customer selectedCustomer) {
        this.selectedCustomer = selectedCustomer;
    }
}

客户Dao.java

public class CustomersDao {
    public List<Customer> findAll(){
        List<Customer> list_cust = null;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        String sql = "FROM Customer";
        try{
            session.beginTransaction();
            list_cust = session.createQuery(sql).list();
            session.beginTransaction().commit();
        }catch(Exception e){
            session.beginTransaction().rollback();
        }
        return list_cust;
    }
}

希望有人建议我代码中有什么问题。 我花了2天时间才能解决。 谢谢阅读!

您需要为客户类配备一个转换器:

@FacesConverter(forClass = Customer.class)
public class CustomerConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if (value != null && !value.equals("") && !value.equals("0")) {
            //find and return object from DAO
        } else {
            return null;
        }
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        //return object id as string
   }
}

您没有提到在commandButton属性update显示弹出对话框的正确ID。

<p:commandButton id="selectButton" update=":formCreate:display" oncomplete="dialogCustomerCreate.show()" icon="ui-icon-search" title="Update">
     <f:setPropertyActionListener value="#{customer}" target="#{customerBean.selectedCustomer}" />
</p:commandButton>

1)尝试删除您的<h:form/> ,因为您没有在该对话框中提交任何信息;

2)尝试将您的<p:commandButton update=""/>更改为update=":display" ;

3)将process="@form"添加到您的<p:commandButton/>

4)如果可行,我认为您不需要<h:form/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM