我将当前迭代的dataTable作为托管bean的属性使用.Here我想获取一个localproduct并将其发送到对话框以更改值。但我没有添加代码,因为我的setListener不起作用,它没有设置或设置为null。但是,始终将其设置为null。选择模式可以杀死setPropertyActionListener吗?
视图,local-product.xhtml:
<ui:define name="content">
<h:form prependId="false" style="margin-top: 25px" id="form">
<p:dataTable id="tableData" value="#{localProductUI.localProductLazyModel}" var="localProduct" style="max-width: 1200px; margin-top: 20px;" paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="20,100,200,500" rows="20" lazy="true" rowIndexVar="row" editable="true" editMode="cell"
widgetVar="productTable" reflow="true" selection="#{localProductUI.selectedNewLocalProduct}" rowKey="#{localProduct.id}" rowSelectMode="checkbox">
<f:facet name="header">
<h:outputText value="Number of products: #{localProductUI.countProduct}" id="card-count"/>
</f:facet>
<p:column selectionMode="multiple" filterValue="" style="width: 20px"/>
<p:column headerText="Id" sortBy="#{localProduct.id}">
#{localProduct.id}
</p:column>
<p:column headerText="Name" filterBy="#{localProduct.name}" style="white-space: normal;">
#{localProduct.name}
</p:column>
<p:column headerText="Code" sortBy="#{localProduct.code}" filterBy="#{localProduct.code}">
#{localProduct.code}
</p:column>
<p:column headerText="Category" filterBy="#{localProduct.categoryId}" style="white-space: normal;">
#{localProduct.categoryId}
</p:column>
<p:column headerText="APrice" sortBy="#{localProduct.arrivalCost}">
#{util.fDouble(localProduct.arrivalCost)}
</p:column>
<p:column headerText="SPrice" sortBy="#{localProduct.sellingPrice}">
#{util.fDouble(localProduct.sellingPrice)}
</p:column>
<p:column headerText="Change">
<p:commandButton value="Change" update=":productDetail" onclick="PF('productDialog').show();"
action="#{localProductUI.editNewLocalProduct}" >
<f:setPropertyActionListener target="#{localProductUI.newLocalProduct}" value="#{localProduct}" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:dialog header = "Change product" widgetVar="productDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
<p:outputPanel id="productDetail" style="text-align: center">
<p:panelGrid columns="2" rendered="#{not empty localProductUI.newLocalProduct}" columnClasses="label,value">
<h:outputText value="Name:"/>
<h:outputText value="#{localProductUI.newLocalProduct.name}"/>
<h:outputText value="Code:"/>
<h:outputText value="#{localProductUI.newLocalProduct.code}"/>
<h:outputText value="Category:"/>
<h:outputText value="#{localProductUI.newLocalProduct.categoryId}"/>
<h:outputText value="APrice:"/>
<h:outputText value="#{localProductUI.newLocalProduct.arrivalCost}"/>
<h:outputText value="SPrice:"/>
<h:outputText value="#{localProductUI.newLocalProduct.sellingPrice}"/>
</p:panelGrid>
</p:outputPanel>
</p:dialog>
</h:form>
</ui:define>
</ui:composition>
托管bean,LocalProductUI:
public class LocalProductUI implements Serializable {
/*
* Consts
*/
private static final Logger log = Logger.getLogger(LocalProductUI.class.getName());
/*
* EJB
*/
@EJB private NewLocalProductEJB newLocalProductEJB;
/*
* Fields
*/
private LazyDataModel<NewLocalProduct> localProductLazyModel;
private Integer countProduct;
private List<NewLocalProduct> selectedNewLocalProduct;
private NewLocalProduct newLocalProduct;
/*
* Init
*/
public void init() {
this.localProductLazyModel = new LazyDataModel<NewLocalProduct>() {
@Override
public List<NewLocalProduct> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
localProductLazyModel.setRowCount(newLocalProductEJB.countNewLocalProducts(filters));
countProduct = newLocalProductEJB.countNewLocalProducts(filters);
Boolean sortAsc = sortOrder == null ? null : sortOrder == SortOrder.ASCENDING;
return newLocalProductEJB.getNewLocalProductList(first, pageSize, sortField, sortAsc, filters);
}
@Override
public NewLocalProduct getRowData(String rowKey) {
int id;
try {
id = new Integer(rowKey);
} catch (NumberFormatException e) {
throw new Error(e);
}
return newLocalProductEJB.findById(id);
}
@Override
public Object getRowKey(NewLocalProduct product) {
return product.getId();
}
@Override
public void setRowIndex(int rowIndex) {
if (rowIndex == -1 || getPageSize() == 0) {
super.setRowIndex(-1);
} else {
super.setRowIndex(rowIndex % getPageSize());
}
}
};
localProductLazyModel.setRowCount(newLocalProductEJB.countNewLocalProducts(new HashMap<String, Object>()));
}
/*
* Actions
*/
public void saveToGlobalProduct() throws InputValidationException {
newLocalProductEJB.doSave(selectedNewLocalProduct);
FacesMessage msg = new FacesMessage("Number of local products added: "+ selectedNewLocalProduct.size());
FacesContext.getCurrentInstance().addMessage(null,msg);
}
public void editNewLocalProduct(){
System.err.println("Change here!");
}
public void removeProduct() throws InputValidationException {
newLocalProductEJB.doRemove(selectedNewLocalProduct);
FacesMessage msg = new FacesMessage("Number of local products deleted: "+ selectedNewLocalProduct.size());
FacesContext.getCurrentInstance().addMessage(null,msg);
}
/*
* Getters/setters
*/
public Integer getCountProduct() { return countProduct; }
public void setCountProduct(Integer countProduct){
this.countProduct = countProduct;
}
public LazyDataModel<NewLocalProduct> getLocalProductLazyModel() { return localProductLazyModel; }
public void setLocalProductLazyModel(LazyDataModel<NewLocalProduct> localProductLazyModel){ this.localProductLazyModel = localProductLazyModel; }
public List<NewLocalProduct> getSelectedNewLocalProduct(){ return selectedNewLocalProduct; }
public void setSelectedNewLocalProduct(List<NewLocalProduct> selectedNewLocalProduct){ this.selectedNewLocalProduct = selectedNewLocalProduct; }
public NewLocalProduct getNewLocalProduct() { return newLocalProduct; }
public void setNewLocalProduct(NewLocalProduct newLocalProduct){ this.newLocalProduct = newLocalProduct;}
}