【问题标题】:Command button action not working in primefaces+ hibernate application命令按钮操作在 primefaces + 休眠应用程序中不起作用
【发布时间】:2013-10-08 09:22:48
【问题描述】:

我在项目中使用 JSF primefaces 和 Hibernate。我使用了 primefaces 布局单元。 当我单击菜单项时,它会更新面板。但是当我尝试从托管 bean 执行方法时,它什么也不做。也没有错误信息。

托管 bean 的代码是:

@ManagedBean(name = "customerDetails")
@SessionScoped
@Entity
@Table(name = "CUSTOMER")
public class CustomerDetailsBean implements Serializable {   


    @Id
    @GeneratedValue
    @Column(name = "ID")
    private long customerId;

    @Column(name = "NAME")
    private String customerName;

    @Column(name = "DOB")
    private Date DOB;

    @Column(name = "ORG_NAME")
    private String organizationName;

    @Column(name = "MOBILE")
    private String mobile;

    @Column(name = "BEST_TIME_CALL")
    private String bestTimeToCall;

    @Column(name = "PROD_CAT")
    private String productCategory;

    @Column(name = "PROD")
    private String product;

    @Column(name = "REF_SRC")
    private String referralSource;

    @Column(name = "TELE_NAME")
    private String telesalesName;

    @Column(name = "TELE_CODE")
    private String telesalesCode;

    @Embedded
    @ManagedProperty(value = "#{customerAddressDetails}")
    private CustomerAddressDetailsBean addressDetailsBean;

    @Embedded
    @ManagedProperty(value = "#{customerLoanDetails}")
    private CustomerLoanDetailsBean loanDetailsBean;

    public String getCustomerName() {
        return customerName;
    }

    public void setCustomerName(String customerName) {
        this.customerName = customerName;
        System.out.println(customerName);
    }

    public Date getDOB() {
        return DOB;
    }

    public void setDOB(Date dOB) {
        DOB = dOB;
    }

    public String getOrganizationName() {
        return organizationName;
    }

    public void setOrganizationName(String organizationName) {
        this.organizationName = organizationName;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getProductCategory() {
        return productCategory;
    }

    public void setProductCategory(String productCategory) {
        this.productCategory = productCategory;
    }

    public String getProduct() {
        return product;
    }

    public void setProduct(String product) {
        this.product = product;
    }

    public String getReferralSource() {
        return referralSource;
    }

    public void setReferralSource(String referralSource) {
        this.referralSource = referralSource;
    }

    public String getTelesalesName() {
        return telesalesName;
    }

    public void setTelesalesName(String telesalesName) {
        this.telesalesName = telesalesName;
    }

    public String getTelesalesCode() {
        return telesalesCode;
    }

    public void setTelesalesCode(String telesalesCode) {
        this.telesalesCode = telesalesCode;
    }

    public String getBestTimeToCall() {
        return bestTimeToCall;
    }

    public void setBestTimeToCall(String bestTimeToCall) {
        this.bestTimeToCall = bestTimeToCall;
    }

    public long getCustomerId() {
        return customerId;
    }

    public void setCustomerId(long customerId) {
        this.customerId = customerId;
    }

    public CustomerAddressDetailsBean getAddressDetailsBean() {
        return addressDetailsBean;
    }

    public void setAddressDetailsBean(CustomerAddressDetailsBean addressDetailsBean) {
        this.addressDetailsBean = addressDetailsBean;
    }

    public CustomerLoanDetailsBean getLoanDetailsBean() {
        return loanDetailsBean;
    }

    public void setLoanDetailsBean(CustomerLoanDetailsBean loanDetailsBean) {
        this.loanDetailsBean = loanDetailsBean;
    }

    public String insertCustomer() {
        System.out.println("inserting Customer");

        return "Login";

    }
}

xhtml 的代码是:

<p:commandButton id="btnSearch1" value="Search" type="Submit" action="#{customerDetails.insertCustomer}" update=":Centerform:Masters"/>

【问题讨论】:

  • 您是否在页面某处添加了&lt;h:messages&gt;
  • 是的,我已经为每个输入字段添加了。但是在提交时没有看到错误消息。
  • 您的 p:commandButton 是否在表单内?
  • 我在一个 id="Centerform" 的表单中有 p:commandButton

标签: hibernate jsf-2 primefaces


【解决方案1】:

我假设你的组件没有放在表单组件中。

执行以下操作:

<h:form>
   <!-- place the components and the button here -->
</h:form>

【讨论】:

  • 我使用 Eclipse Juno。我创建了一个新的工作空间并在那里复制了项目。现在它工作正常。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-11
  • 1970-01-01
  • 1970-01-01
  • 2012-05-13
  • 2023-03-22
  • 1970-01-01
相关资源
最近更新 更多