繁体   English   中英

Primefaces cellEditor必需的inputText

[英]Primefaces cellEditor required inputText

我有一个PrimeFaces p:dataTable ,其中一列类型为p:cellEditor ,带有p:inputText字段。

此inputText应该是必需的,但是如果我将required =“ true”设置为空,则什么也不会发生,也不会显示任何消息。 包括上述在内的表格仍然被提交。

这是我的代码,尤其是<p:column headerText="Data Value">部分:

<h:form id="my-form">
            <p:dataTable var="dataItem" rowIndexVar="rowIndex" value="#{backingBean.dataList}" draggableRows="true" editable="true" editMode="cell">
                    <p:ajax event="rowReorder" update="@form"/>

                        <p:column headerText="Order Position">
                            <h:outputText value="#{rowIndex+1}" />
                        </p:column>
                        <p:column headerText="Data Name">
                            <h:outputText value="#{dataItem.name}" />
                        </p:column>

                        <p:column headerText="Data Value">
                            <p:cellEditor>
                                <f:facet name="output"><h:outputText value="#{dataItem.value}" /></f:facet>
                                <f:facet name="input"><p:inputText required="true" requiredMessage="Please insert a value" id="valueInput" value="#{dataItem.value}" style="width:100%"/></f:facet>
                            </p:cellEditor>
                        </p:column>
                </p:dataTable>
            <div>
                <h:commandLink action="#{backingBean.submit()}">Submit</h:commandLink>
            </div>
            <h:messages id="validateMsg" />
        </h:form>

提交的h:commandLink不是ajax调用。 但是我认为,只要必需的p:inputText字段为空,就不应该提交表单。

我也尝试使用h:inputText而不是p:inputText获得相同的结果。

我试图在p:dataTable之外添加所需的h:inputText ,该效果可以按预期工作,并且只要表单为空即可阻止提交表单。

关于如何在p:cellEdit获得必需的p:inputText字段的任何想法?

根据rion18的建议。 我正在检查我的支持bean是否设置了所有值。 只有设置了所有值,才会显示“提交”按钮。 这就是我最终这样做的方式:

<h:form id="my-form">
    <p:dataTable var="dataItem" rowIndexVar="rowIndex" value="#{backingBean.dataList}" draggableRows="true" editable="true" editMode="cell">
    <p:ajax event="cellEdit" update=":#{p:component('submit-button-group')}" />
        <p:column>
...
        </p:column>
    </p:dataTable>
    <div>
        <h:panelGroup id="submit-button-group">
            <h:commandLink action="#{backingBean.submit()}" rendered="#{backingBean.isAllValuesSet()}">Submit</h:commandLink>
        </h:panelGroup>
    </div>
</h:form>

在我的后备bean中,我有一个简单的函数可以遍历dataList:

public boolean isAllValuesSet(){
    for(DataItem item:dataItems){
        if(item.getValue()==null || item.getValue().isEmpty()){
            return false;
        }
    }
    return true;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM