使用<p:ajax event =“onRowSelect”>更新按钮</p:ajax>

时间:2014-01-11 07:10:35

标签: jsf java-ee jsf-2 primefaces

我正在使用<p:ajax event="onRowSelect" update="editButton deleteButton">切换disabled中的<p:commandButton>属性,但它无法正常工作。

这是我的代码:

<p:ajax event="rowSelect" update="editButton deleteButton"/>
...
<p:commandButton id="editButton" icon="ui-icon-pencil" value="#{appBundle.Edit}" action="detail.xhtml?faces-redirect=true" disabled="#{empty academicManagedBean.academicSelected}">

我做错了吗?

修改

这是我的托管bean类:

package com.rdb.beans;

import com.rdb.entities.TblAcademic;
import com.rdb.entities.TblClass;
import com.rdb.entities.TblStudent;
import com.rdb.util.JsfUtil;
import java.io.Serializable;
import java.util.List;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;

/**
 *
 * @author NNToan
 */
@ManagedBean
@ViewScoped
public class AcademicManagedBean extends TblAcademic implements Serializable {

    private List<TblAcademic> all;
    private static TblAcademic academicSelected;

    /**
     * Creates a new instance of AcademicManagedBean
     *
     */
    public AcademicManagedBean() {
        super();
    }

    /**
     * Get all records in TblAcademic from the database.
     *
     * @return List<TblAcademic>
     */
    public List<TblAcademic> getAll() {
        try {
            all = new com.rdb.bll.AcademicBLL().getAll();
            return all;
        } catch (Exception ex) {
            Logger.getLogger(BranchManagedBean.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    /**
     * Add new record to the database Show action status at growl
     *
     * @param actionEvent
     * @throws Exception
     */
    public void add(ActionEvent actionEvent) throws Exception {
        boolean check = new com.rdb.bll.AcademicBLL().add(this);
        if (check) {
            JsfUtil.addSuccessMessage("Congratulation, new student has been added successfully!");
        } else {
            JsfUtil.addErrorMessage(ResourceBundle.getBundle("com.rdb.service.AppBundle").getString("PersistenceErrorOccured"));
        }
    }

    /**
     * Update student information Show action status at growl
     *
     * @param actionEvent
     * @throws Exception
     */
    public void update(ActionEvent actionEvent) throws Exception {
        boolean check = new com.rdb.bll.AcademicBLL().update(AcademicManagedBean.academicSelected);
        if (check) {
            JsfUtil.addSuccessMessage("Congratulation, student has been updated successfully!");
        } else {
            JsfUtil.addErrorMessage(ResourceBundle.getBundle("com.rdb.service.AppBundle").getString("PersistenceErrorOccured"));
        }
    }

    /**
     * Delete student from the database Show action status at growl
     *
     * @param actionEvent
     * @throws Exception
     */
    public void delete(ActionEvent actionEvent) throws Exception {
        boolean check = new com.rdb.bll.AcademicBLL().delete(AcademicManagedBean.academicSelected);
        if (check) {
            JsfUtil.addSuccessMessage("Congratulation, student has been deleted successfully!");
        } else {
            JsfUtil.addErrorMessage(ResourceBundle.getBundle("com.rdb.service.AppBundle").getString("PersistenceErrorOccured"));
        }
    }

    /**
     * Enter student edit-mode
     *
     * @return detail.xhtml?faces-redirect=true
     */
    public String studentDetail() {
        TblStudent std = new com.rdb.bll.StudentBLL().getById(AcademicManagedBean.academicSelected.getStudentRollNo());
        new StudentManagedBean().setStudentSelected(std);

        return "detail.xhtml?faces-redirect=true";
    }

    /**
     * Get class name through class identifier
     *
     * @param classId
     * @return className
     */
    public String getClassNameById(int classId) {
        TblClass objClass = new com.rdb.bll.ClassBLL().getById(classId);
        return objClass.getClassName();
    }

    /**
     * Get current working object (selected row)
     *
     * @return TblAcademic
     */
    public TblAcademic getAcademicSelected() {
        return academicSelected;
    }

    /**
     * Set current working object (selected row)
     *
     * @param academicSelected
     */
    public void setAcademicSelected(TblAcademic academicSelected) {
        AcademicManagedBean.academicSelected = academicSelected;
    }
}

0 个答案:

没有答案