p:commandButton在渲染后没有调用动作

时间:2015-04-03 04:03:07

标签: jsf primefaces

PrimeFaces <p:commandButton>在呈现后无法正常工作。 结构:

我正在使用Form并在表单内部创建一个命令按钮(addproducts)来在datatable中添加值并将表格呈现给它(工作)

在表格中使用另外两个不起作用的命令按钮

请参考<p:commandButton id="addrowTable1" />无法正常工作..

请帮我这个

该动作未被调用/

这是我的XHTML:

<h:form id ="addProductForm">
  <p:growl id="msgs" showDetail="true"/>
  <p:panel id="basic" header="Basic Information"
    style="margin-bottom:20px">
    <h:panelGrid columns="4" cellpadding="10">

      <h:outputText value="Invoice No" />
      <p:inputText value="#{purchaseBean.invoiceNo}"/>

      <h:outputText value="Supplier Code" />
      <p:inputText value="#{purchaseBean.suppliercode}" />
      <h:outputText value="Invoice Value" />
      <p:inputText value="#{purchaseBean.invoiceValue}" />

      <h:outputText value="Remarks" />
      <p:inputText value="#{purchaseBean.remark}" />


      <h:outputText value="Total Amount" />
      <p:inputText value="#{purchaseBean.total}" />
    </h:panelGrid>

    <p:commandButton value="AddProducts" id="addNewProduct"
      styleClass="ui-priority-primary"
      actionListener="#{purchaseAction.addTableValues}"
      update=":addProductForm:purchaseDetails" />


    <p:contextMenu for="purchaseDetails" widgetVar="cMenu">
      <p:menuitem value="Edit Cell" icon="ui-icon-search"
        onclick="PF('purchas').showCellEditor();return false;" />
      <p:menuitem value="Hide Menu" icon="ui-icon-close"
        onclick="PF('cMenu').hide()" />
    </p:contextMenu>



    <p:dataTable id="purchaseDetails" var="product"
      value="#{purchaseBean.pl}" editable="true" editMode="cell"
      widgetVar="purchas" rendered="true">
      <f:facet name="header"> Add Products </f:facet>

      <p:ajax event="cellEdit"
        listener="#{purchaseAction.onCellEdit}"
        update=":addProductForm:msgs,:addProductForm:purchaseDetails" />

      <p:column headerText="S No" rendered="true">
        <p:cellEditor>
          <f:facet name="output">
            <h:outputText value="#{product.sno}" />
          </f:facet>
          <f:facet name="input">
            <p:inputText id="modelInput" value="#{product.sno}"
              style="width:96%" label="sno" />
          </f:facet>
        </p:cellEditor>
      </p:column>

      <p:column headerText="Product Code" rendered="true">
        <p:cellEditor>
          <f:facet name="output">
            <h:outputText value="#{product.productCode}" />
          </f:facet>
          <f:facet name="input">
            <p:inputText id="productCode"
              value="#{product.productCode}" style="width:100%"
              label="sno" />
          </f:facet>
        </p:cellEditor>
      </p:column>

      <p:column headerText="Description">
        <p:cellEditor>
          <f:facet name="output">
            <h:outputText value="#{product.description}" />
          </f:facet>
          <f:facet name="input">
            <p:inputText id="descript" value="#{product.description}"
              style="width:100%" label="desc" />
          </f:facet>
        </p:cellEditor>
      </p:column>

      <p:column headerText="MRP">
        <p:cellEditor>
          <f:facet name="output">
            <h:outputText value="#{product.mrp}" />
          </f:facet>
          <f:facet name="input">
            <p:inputText id="mrp" value="#{product.mrp}"
              style="width:100%" label="mrp" />
          </f:facet>
        </p:cellEditor>
      </p:column>
      <p:column headerText="Rate">
        <p:cellEditor>
          <f:facet name="output">
            <h:outputText value="#{product.rate}" />
          </f:facet>
          <f:facet name="input">
            <p:inputText id="rate" value="#{product.rate}"
              style="width:100%" label="rate" />
          </f:facet>
        </p:cellEditor>
      </p:column>

      <p:column style="width:82px" rendered="true" id="adddelete">

        <p:commandButton
          actionListener="#{purchaseAction.addTableValues}"
          update=":addProductForm:purchaseDetails"
          icon="ui-icon-plusthick" rendered="true"
          action="#{purchaseAction.addTableValues}" title="Icon Only"
          id="addrowTable1" />
        <p:commandButton
          actionListener="#{purchaseAction.deleteRow}"
          icon="ui-icon-minusthick" title="Icon Only" />
      </p:column>

    </p:dataTable>


    <p:commandButton value="Submit" id="submitnewRow"  styleClass="ui-priority-primary" actionListener="#{purchaseAction.addRow}" rendered="true" update=":addProductForm:purchaseDetails" >

    </p:commandButton>
    <p:commandButton value="Cancel" id="cancel" styleClass="ui-priority-primary" />

  </p:panel>
</h:form>

我的Action类(PurchaseAction.java)

package co.in.ar.sm.action;

import java.util.ArrayList;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

import org.primefaces.event.CellEditEvent;

import co.in.ar.sm.bean.Purchase;
import co.in.ar.sm.bean.PurchaseDetails;

@ManagedBean(name="purchaseAction")
@RequestScoped
public class PurchaseAction {

  public void onCellEdit(CellEditEvent event) {
        Object oldValue = event.getOldValue();
        Object newValue = event.getNewValue();

        if(newValue != null && !newValue.equals(oldValue)) {
            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue);
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
    }

  /**
   * @return the purchase
   */
  public Purchase getPurchase() {
    return purchase;
  }

  /**
   * @param purchase the purchase to set
   */
  public void setPurchase(Purchase purchase) {
    this.purchase = purchase;
  }

  @ManagedProperty("#{purchaseBean}")
  private Purchase purchase ;

  public void addRow(){

      List<PurchaseDetails> a = purchase.getPl();

        PurchaseDetails p =new PurchaseDetails();
        p.setProductCode(987);
        p.setDescription("NewProduct1");
        p.setMrp(34);
        p.setPrice(433);
        p.setQuantity(79);
        p.setVat(57);
        p.setRate(78);
        purchase.pl.add(p);

  }

  public void addTableValues(){



    purchase.getInvoiceNo();
    PurchaseDetails p =new PurchaseDetails();
    p.setProductCode(123);
    p.setDescription("NewProduct");
    p.setMrp(1);
    p.setPrice(433);
    p.setQuantity(79);
    p.setVat(57);
    p.setRate(78);
    purchase.pl.add(p);

  }

  public void deleteRow(){

  }
}

MY Bean CLass(purchase.java:

package co.in.ar.sm.bean;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;

@ManagedBean(name="purchaseBean")
public class Purchase {
String receiptNo;
String invoiceNo;
String Suppliercode;
Double invoiceValue;
String remark;
float total;
public List<PurchaseDetails> pl = new ArrayList<PurchaseDetails>();

/**
 * @return the receiptNo
 */
public String getReceiptNo() {
  return receiptNo;
}
/**
 * @param receiptNo the receiptNo to set
 */
public void setReceiptNo(String receiptNo) {
  this.receiptNo = receiptNo;
}
/**
 * @return the invoiceNo
 */
public String getInvoiceNo() {
  return invoiceNo;
}
/**
 * @param invoiceNo the invoiceNo to set
 */
public void setInvoiceNo(String invoiceNo) {
  this.invoiceNo = invoiceNo;
}
/**
 * @return the suppliercode
 */
public String getSuppliercode() {
  return Suppliercode;
}
/**
 * @param suppliercode the suppliercode to set
 */
public void setSuppliercode(String suppliercode) {
  Suppliercode = suppliercode;
}
/**
 * @return the invoiceValue
 */
public Double getInvoiceValue() {
  return invoiceValue;
}
/**
 * @p aram invoiceValue the invoiceValue to set
 */
public void setInvoiceValue(Double invoiceValue) {
  this.invoiceValue = invoiceValue;
}
/**
 * @return the remark
 */
public String getRemark() {
  return remark;
}
/**
 * @param remark the remark to set
 */
public void setRemark(String remark) {
  this.remark = remark;
}
/**
 * @return the total
 */
public float getTotal() {
  return total;
}
/**
 * @param total the total to set
 */
public void setTotal(float total) {
  this.total = total;
}
/**
 * @return the pl
 */
public List<PurchaseDetails> getPl() {
  return pl;
}
/**
 * @param pl the pl to set
 */
public void setPl(List<PurchaseDetails> pl) {
  this.pl = pl;
}

}

数据表中使用的My List bean

PurchaseDetails.java

public class PurchaseDetails {
int sno;
int productCode;
String description;
int quantity;
float price;
float mrp;
float vat;
float rate;

//with getters and setterrs

0 个答案:

没有答案