2015-07-21 77 views
-1

我有:PrimeFaces:P:cellEditor的不點火

一個基本數據表,該表中,爲了簡單起見,僅示出了一定的客戶訂單的產品的量。

問題:

當我點擊單元格中,<p:inputText>出現,我可以輸入一個數字(例如:3)。當我按enter時,舊號碼(例如:42)出現在<h:outputText>內。如果再次單擊單元格,編輯後的數字(3)再次出現。最重要的是,這個方法不會被解僱。

有什麼我想:

我創造了另一種基本的Web應用程序中,只有一個可編輯<p:dataTable>(我想它),在這個項目聽者火災,我根本就沒有得到不同的東西。爲了簡單起見,我不會添加其他項目的代碼。

此外,我試圖應用(不)接受的答案this問題,但它也沒有工作。

問題:

爲什麼聽者不火?可能是什麼原因(或原因)?是的,我是初學者,所以任何暗示都會非常受歡迎。

謝謝!

XHTML與表

<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:ui="http://java.sun.com/jsf/facelets" 
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:p="http://primefaces.org/ui" 
      xmlns:f="http://java.sun.com/jsf/core" 
      template="/templates/template.xhtml"> 

<ui:define name="metadata"/> 
<ui:define name="content"> 

    <h:form id="lastOrders"> 

     <p:dataTable id="orders" 
        var="item" 
        value="#{editController.items}" 
        emptyMessage="Der Kunde hat noch keine Aufträge!" 
        style="size: 30px" 
        editable="true" 
        editMode="cell"> 

      <p:ajax event="cellEdit" listener="#{editController.onCellEdit}" update=":mainForm:lastOrders:orders"/> 

      <f:facet name="header"> 
       <p:outputPanel> 
        <h:outputText value="#{userController.customer.name}" /> 
       </p:outputPanel> 
       <p:outputPanel> 
        <h:outputText value="#{oldOrdersController.order.date}"> 
         <f:convertDateTime pattern="dd.MM.yy" /> 
        </h:outputText> 
       </p:outputPanel> 
      </f:facet> 

      <p:column headerText="Amount"> 
       <p:cellEditor> 
        <f:facet name="output"> 
         <h:outputText value="#{item.amount}"/> 
        </f:facet> 
        <f:facet name="input"> 
         <p:inputText id="modelInput" value="#{item.amount}"/> 
        </f:facet> 
       </p:cellEditor> 
      </p:column> 
     </p:dataTable> 
    </h:form> 
</ui:define> 

這是EditController

package com.forall.laundry.controller.edit; 

import com.forall.laundry.controller.OldOrdersController; 
import com.forall.laundry.model.Item; 
import com.forall.laundry.service.ItemService; 
import com.forall.laundry.service.ProductService; 
import java.io.Serializable; 
import java.util.List; 
import javax.annotation.PostConstruct; 
import javax.ejb.EJB; 
import javax.faces.view.ViewScoped; 
import javax.inject.Inject; 
import javax.inject.Named; 
import org.primefaces.event.CellEditEvent; 

    @Named 
    @ViewScoped 
    public class EditController implements Serializable{ 

    @EJB 
    private ItemService itemService; 

    @EJB 
    private ProductService productService; 

    @Inject 
    private OldOrdersController oc; 

    private List<Item> items; 

    @PostConstruct 
    public void init(){ 
     items = itemService.getItemsFrom(oc.getOrder()); 
    } 

    public void onCellEdit(CellEditEvent event) { 
     System.out.println("TEST"); // NOT FIRED (i know sysout is not good but no matter what I do here, nothing happens. 
    } 

    public ItemService getItemService() { 
     return itemService; 
    } 

    public void setItemService(ItemService itemService) { 
     this.itemService = itemService; 
    } 

    public OldOrdersController getOc() { 
     return oc; 
    } 

    public void setOc(OldOrdersController oc) { 
     this.oc = oc; 
    } 

    public List<Item> getItems() { 
     return items; 
    } 

    public void setItems(List<Item> items) { 
     this.items = items; 
    } 

    public ProductService getProductService() { 
     return productService; 
    } 

    public void setProductService(ProductService productService) { 
     this.productService = productService; 
    } 
} 

回答

0

註釋到該溶液中或替代方法:

在PrimeFaces showcase建議使用<p:ajax event="cellEdit" listener="#{dtEditView.onCellEdit}" update=":form:msgs" />但由於我不知道的原因事件不會被解僱,onCellEdit方法不會被調用。因此,我研究了其他觸發事件的方法,並最終得出了下面的解決方案,在該解決方案中,我傳遞了被更改的對象本身,而不是事件。 我仍然不知道爲什麼原始代碼不起作用。

段:

<p:column headerText="Produkt"> 
       <p:cellEditor> 
        <f:facet name="output"> 
         <h:outputText value="#{item.name}"/> 
        </f:facet> 
        <f:facet name="input"> 
         <h:inputText id="modelInput" value="#{item.name}"> 
          <f:ajax execute="modelInput" event="change" listener="#{editController.onCellEdit(item)}" render=":mainForm:lastOrders:orders"/> 
         </h:inputText> 
        </f:facet> 
       </p:cellEditor> 
      </p:column> 

豆方法:

public void onCellEdit(Item item) { 

    //stuff 
} 
+1

請添加一些文字你改變,爲什麼會解決它。所以其他人可以更容易地識別自己的東西 – Kukeltje