首页 文章

Primefaces cellEditor需要inputText

提问于
浏览
1

我有一个PrimeFaces p:dataTable ,其中一列 p:cellEditorp: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 字段的任何想法?

1 回答

  • 0

    根据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;
    }
    

相关问题