0

I'm putting the currently iterated dataTable as a property of a managed bean using .Here I want to take one localproduct and send it to the dialog to change the values. But I did not add the code for that due to my setListener does not work and it does not set or it sets to null. However, it is always set it as null. Can selection mode kill the setPropertyActionListener?

The view, 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>

The managed 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;}
}
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
nuuk.me
  • 19
  • 2
  • On topic: what is the bean scope? Off-Topic: In modern JSF/EL you can do `` and don't use `prependId="false"` http://stackoverflow.com/questions/7415230/uiform-with-prependid-false-breaks-fajax-render – Kukeltje Sep 14 '17 at 09:30
  • Did you debug if an ajax event is fired? And 'when' is it null? – Kukeltje Sep 14 '17 at 09:44
  • I deleted prependId but also it doesnot work. Ajax event can not be reached. – nuuk.me Sep 14 '17 at 09:53
  • it is null when dialog opens – nuuk.me Sep 14 '17 at 09:55
  • PrependId was an offtopic remark. Ajax 'event' can be seen in the browser developer tool (network traffic)... But did you debug if the setter is called at all? Please put some more basic debugging/investigation in the problem... Cheers – Kukeltje Sep 14 '17 at 09:59
  • I fount that neither my actionListener nor commandButton action work. What is the problem? – nuuk.me Sep 14 '17 at 12:23
  • https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value – Kukeltje Sep 14 '17 at 13:08

0 Answers0