2016-09-19 47 views
0

我試圖使用選擇模式從數據表中選擇一些項目,並指定使用CellEditor選擇的項目的數量,但CellEditor未獲取所有值點擊「顯示」按鈕後進入,它只會得到我在CellEditor列中輸入的最後一個值。請我需要有人幫助我!數據表中的單元格編輯器在JSF中只獲取一個值

我的XHTML代碼

<p:dataTable editable="true" editMode="cell" id="change" selection="#{openJobOrderBean.selectedMaterials}" rowKey="#{openJob.materialId}" 
       rows="5" var="openJob" value="#{openJobOrderBean.smtOrder}" paginator="true" paginatorPosition="bottom" 
       paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" 
       rowsPerPageTemplate="5,10,15"> 

    <p:ajax immediate="true" process="@this" event="cellEdit" listener="#{openJobOrderBean.onCellEdit}" update="change" /> 
    <p:column selectionMode="multiple" style="text-align: center; width: 80px" headerText="Select Requested Materials" /> 
    <p:column headerText="Quantity Requested(click to edit)" style="width: 150px; text-align: center" class="columnedit" > 
     <p:cellEditor> 
      <f:facet name="output"><h:outputText value="#{openJobOrderBean.quantity}" /></f:facet> 
      <f:facet name="input"><p:inputText label="Quantity Requested(editable)" value="#{openJobOrderBean.quantity}" style="width: 150px" /> 

      </f:facet> 
     </p:cellEditor> 
    </p:column> 

    <p:column style="text-align: center" headerText="Material Name" filterBy="#{openJob.materialName}"> 
     <h:outputText value="#{openJob.materialName}" /> 
    </p:column> 
    <p:column style="text-align: center" headerText="Available Quantity" > 
     <h:outputText value="#{openJob.materialQuantity}" /> 
    </p:column> 
    <f:facet name="footer"> 
     <p:commandButton id="shows" oncomplete="PF('multimaterials').show()" value="Show" process="change" update=":mainform:materialdetails"/> 
    </f:facet> 
</p:dataTable> 

<p:dialog header="Selected Materials" widgetVar="multimaterials" minimizable="true" maximizable="true" 
      showEffect="shake" hideEffect="explode" width="500"> 
    <p:panel style="width: 500px" id="materialdetails" > 

     <ui:repeat value="#{openJobOrderBean.selectedMaterials}" var="openJob"> 

      <p:panelGrid columns="1" layout="grid"> 
         #{openJob.materialName} - #{openJobOrderBean.quantity} 
      </p:panelGrid> 

     </ui:repeat> 
    </p:panel> 
</p:dialog> 

我的豆

private List<OpenJobOrderBean> powerHouseOrder; 
    private List<OpenJobOrderBean> selectedMaterials; 
private String materialName; 
private int materialQuantity; 
private int materialId; 
private int quantity; 

public String getMaterialName() { 
    return materialName; 
} 

public void setMaterialName(String materialName) { 
    this.materialName = materialName; 
} 

public int getMaterialQuantity() { 
    return materialQuantity; 
} 

public void setMaterialQuantity(int materialQuantity) { 
    this.materialQuantity = materialQuantity; 
} 

public int getMaterialId() { 
    return materialId; 
} 

public void setMaterialId(int materialId) { 
    this.materialId = materialId; 
} 

public int getQuantity() { 
    return quantity; 
} 

public void setQuantity(int quantity) { 
    this.quantity = quantity; 
} 

public List<OpenJobOrderBean> getSelectedMaterials() { 
    return selectedMaterials; 
} 

public void setSelectedMaterials(List<OpenJobOrderBean> selectedMaterials) { 
    this.selectedMaterials = selectedMaterials; 
} 

public List<OpenJobOrderBean> getPowerHouseOrder() { 
    try { 
     this.powerHouseOrder = new OpenJobOrder().retrievePowerHouseMaterials(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
     FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "", e.getMessage()); 
     FacesContext.getCurrentInstance().addMessage(null, msg); 
    } 
    return powerHouseOrder; 
} 

public void onCellEdit(CellEditEvent event) { 
    Object oldValue = event.getOldValue(); 
    Object newValue = event.getNewValue(); 
    FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue); 
    FacesContext.getCurrentInstance().addMessage(null, msg); 

} 

This is the result before clicking the SHOW button

This is the result after selecting and clicking the SHOW button

回答

0

你爲什麼這樣做?

#{openJob.materialName} - #{openJobOrderBean.quantity} 

爲了得到這份工作的數量,你得改:

#{openJob.materialName} - #{openJob.quantity} 

此外,這看起來非常糟糕。不要存儲你的bean的列表。創建openJob一個實體類和存儲這些實體的名單..

+0

我已經更改爲: '#{} openJob.materialName - #{openJob.quantity}' 但它變得0作爲量均通過。 @Attila –

+0

請我不明白你爲openJob創建實體類的含義... –

+0

你應該在cellEditor中更改#{openJob.quantity}以及.. 通過創建一個實體類,我的意思是你應該創建一個具有所有屬性(名稱,數量,ID等)和getter/setter方法的類,並且將這些列表存儲在bean中。你應該有一個bean用於你的xhtml頁面,而不是在同一個bean中存儲一個bean列表。 –

相關問題