检查数据表中的任何celleditor是否处于编辑模式

时间:2016-07-12 19:32:14

标签: jsf-2 primefaces

我有一个数据表,显示一些有3列的应用程序参数: name(outputext), value(p:cellEditor)和 编辑(p:使用rowEditor)

单击任何行中的编辑按钮值字段将转换为输入字段并附加验证程序。更改并接受(单击检查图标)值后,页面底部会提供“更新按钮”以保存所有更改。

我的问题是如果出现验证错误,我们按下“更新按钮”,然后调用以旧值保存托管bean中的保存功能。因此,要停止此操作,我想在任何行打开编辑模式时禁用“更新按钮”。我可以在第2列中检查所有单元格编辑器的模式,因此我将在更新按钮的禁用属性中使用它。 请建议任何其他更好的方法吗?

使用jsf 2.1和primefaces 3.5

XHTML片段

        

        <!-- Body panel for display of individual configuration mode -->
        <p:panel id="mainConfigPanel" >
        <!-- status message section -->
        <p:messages id="msg" autoUpdate="true" closable="true"/>
        <!-- Parameter configuration mode -->
            <p:panel
                rendered="#{configMBean.configUtility.configParamModeOn}"
                styleClass="panelNoBorder">
                <p:dataTable id="configParamTable" var="configParamVar"
                    value="#{configMBean.configParamList}" editable="true">

                    <p:ajax event="rowEdit" listener="#{configMBean.onRowEdit}" update=":mainForm:msg" />
                    <p:ajax event="rowEditCancel" listener="#{configMBean.onRowCancel}"  update=":mainForm:msg" />

                    <p:column headerText="Parameter Name" sortBy="#{configParamVar.paramConfigName}">
                        <h:outputText id="paramNameId" value="#{configParamVar.paramConfigName}" />
                    </p:column>


                    <p:column headerText="Param Value" sortBy="#{configParamVar.paramConfigValue}">
                        <p:cellEditor>
                            <f:facet name="output" > <h:outputText value="#{configParamVar.paramConfigValue}" /> </f:facet>
                            <f:facet name="input">
                                <p:inputText id="paramValueId" value="#{configParamVar.paramConfigValue}" required="true"
                                    validator="#{configMBean.validateParam}"   >
                                    <f:validateLength maximum="2000" />
                                    <f:attribute name="input" value="#{configParamVar}" />
                                </p:inputText>
                            </f:facet>
                        </p:cellEditor>
                    </p:column>

                    <p:column headerText="Edit" style="text-align:center;vertical-align:top;width:20px">
                        <p:rowEditor />
                    </p:column>

                </p:dataTable>


                <h:panelGrid columns="2" >
                    <p:commandButton value="Update Parameters" actionListener="#{configMBean.saveParamUpdate}" update=":mainForm" />
                    <p:commandButton value="Cancel" actionListener="#{configMBean.cancelParamUpdate}" immediate="true" update=":mainForm">
                    </p:commandButton>
                </h:panelGrid>
            </p:panel>
            <!-- End of Parameter configuration mode panel -->


</p:panel>
<!-- End of body panel for individual configuration mode -->

    </p:panelGrid>
    <!-- end of main panel -->

Managed Bean中的函数

public void onRowEdit(RowEditEvent event) {
    System.out.println(" In Row Edit");
}

public void onRowCancel(RowEditEvent event) {
    System.out.println("In Row Canel of Parameter Config");
}

public void validateParam(FacesContext facesContext, UIComponent component,
        Object value) throws ValidatorException, Exception {
    if (value != null) {
        //Getting  parameter Name and Value for validation
        String paramName = ((RowEntity) component.getAttributes().get("input")).getParamConfigName();
        String paramValue = (String) value;
        FacesMessage msg = null;

        //Validation Cases
        if (paramName.equalsIgnoreCase(ResourceBundle.getMsg("Param_Enable_FTP"))) {
            if (!paramValue.equalsIgnoreCase("true") || !paramValue.equalsIgnoreCase("false")) {
                msg = new FacesMessage(FacesMessage.SEVERITY_WARN, ResourceBundle.getMsg("Param_True_False_Validation")+ paramName, "");
                throw new ValidatorException(msg);
            }
        } else if (paramName.equalsIgnoreCase(ResourceBundle.getMsg("Param_Contingency_Reserve"))) {
            if (!Pattern.matches("-?\\d*\\.?\\d*", paramValue)) {
                    msg = new FacesMessage(FacesMessage.SEVERITY_WARN, ResourceBundle.getMsg("Param_Number_Validation") + paramName, "");
                    throw new ValidatorException(msg);
                }
        }// end if else if

    }

}

1 个答案:

答案 0 :(得分:0)

来自文档:rowEdit

有一个Ajax行为事件
rowEdit | org.primefaces.event.RowEditEvent | When a row is edited.

您可以在RowEditEvent被解雇时禁用更新按钮,并在取消或保存行编辑后释放按钮。

我希望我的问题是正确的,这会有所帮助。