我试图使用选择模式从数据表中选择一些项目,并指定我使用CellEditor选择的项目数量,但CellEditor没有获得我单击"显示"按钮后输入的所有值,它只获得我在CellEditor的列中输入的最后一个值。拜托,我需要有人来帮我!!
My XHTML code
<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);
}
这是点击SHOW按钮
之前的结果这是选择并单击SHOW按钮后的结果
你为什么要这样做?
#{openJob.materialName} - #{openJobOrderBean.quantity}
要获得任务的数量,您必须更改为:
#{openJob.materialName} - #{openJob.quantity}
而且,这看起来真的很糟糕。不要存储bean的列表。为openJob创建一个实体类,并存储这些实体的列表。