1

我有我的数据表。当我通过按下编辑链接进入行编辑模式时,我想禁用命令链接:

在此处输入图像描述

JSF:

<p:growl id="messages" showDetail="true" />

<p:dataTable value="#{employeeBean.employees}"
                 var="employee" id="employeeDTable"
                 editable="true">

        <p:ajax event="rowEdit" listener="#{employeeBean.edit}" update=":employeeForm:messages" />
        <p:ajax event="rowEditCancel" listener="#{employeeBean.undoEdit}" update=":employeeForm:messages" />

        <p:column id="id" headerText="Id">
            <h:outputText value="#{employee.id}"/>
        </p:column>

        <p:column id="firstname" headerText="Voornaam">
            <p:cellEditor>
                <f:facet name="output">
                    <h:outputText value="#{employee.firstName}"/>
                </f:facet>
                <f:facet name="input">
                    <p:inputText value="#{employee.firstName}" label="firstname"/>
                </f:facet>
            </p:cellEditor>
        </p:column>

        <p:column id="editButtonsId" headerText="">
            <p:rowEditor />
        </p:column>

        <p:column id="cashbook" headerText=""> 
            <div align="center">
                <h:panelGroup id="cashbookPanel">
                    <p:commandLink title="Cashbook" update="employeeDTable" styleClass="ui-icon ui-icon-cart" /> <!-- DISABLE THIS IN EDITMODE -->
                </h:panelGroup>
            </div>
        </p:column>

</p:dataTable>

代码:

@Component("employeeBean")
@Scope("session")
public class EmployeeBean {

    List<EmployeeModel> employees;

    private EmployeeModel employeeModel;

    @Autowired
    private EmployeeService employeeService;

    public EmployeeBean() {
        if(employeeService == null){
            employeeService = ServiceRepository.getInstance().getEmployeeService();
        }
        employeeModel = new EmployeeModel();
        if(employees == null){
            this.employees = this.employeeService.getEmployees();
        }
    }

    public void edit(RowEditEvent event) {
        EmployeeModel employee = ((EmployeeModel) event.getObject());
        EmployeeModel updatedEmployee = this.employeeService.updateEmployee(employee);

        if(updatedEmployee != null){
            FacesMessage msg = new FacesMessage("Employee Edited", employee.getFirstName());
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
    }

    public void undoEdit(RowEditEvent event) {    
    }

    public EmployeeModel getEmployeeModel() {
        return employeeModel;
    }

    public void setEmployeeModel(EmployeeModel employeeModel) {
        this.employeeModel = employeeModel;
    }

    public List<EmployeeModel> getEmployees() {
        return employees;
    }

    public void setEmployees(List<EmployeeModel> employees) {
        this.employees = employees;
    }
}
4

1 回答 1

0

将您的链接和禁用的链接放在一个<p:cellEditor/>

<p:column id="cashbook" headerText=""> 
    <p:cellEditor>
        <f:facet name="output">
            <div align="center">
                <h:panelGroup id="cashbookPanel">
                    <p:commandLink title="Cashbook" update="employeeDTable" styleClass="ui-icon ui-icon-cart" />
                </h:panelGroup>
            </div>
        </f:facet>
        <f:facet name="input">
            <div align="center">
                <h:panelGroup id="cashbookPanel">
                    <p:commandLink disabled="true" title="Cashbook" update="employeeDTable" styleClass="ui-icon ui-icon-cart" />
                </h:panelGroup>
            </div>
        </f:facet>
    </p:cellEditor>
</p:column>
于 2013-11-13T06:51:16.027 回答