Primefaces cellEditor必需的inputText [英] Primefaces cellEditor required inputText

查看:139
本文介绍了Primefaces cellEditor必需的inputText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a PrimeFaces p:dataTable with one column of type p:cellEditor with an p:inputText field.

该inputText应该是必需的,但是如果我设置required ="true"并将输入保留为空,则什么也不会发生/没有消息显示.无论如何,包含以上内容的表格都将提交.

This inputText is supposed to be required but if I set required="true" and leave the input empty nothing happens / no message is shown. The form including the above is submitted anyway.

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

Here's my code, especially the <p:column headerText="Data Value"> part:

<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字段为空,就不应该提交表单.

The submitting h:commandLink is not an ajax call. But in my opinion it shouldn't submit the form anyway as long as the required p:inputText fields are empty.

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

I also tried using h:inputText instead of p:inputText with the same result.

我试图在p:dataTable之外添加所需的h:inputText,该效果可以按预期工作,并且可以防止表单为空.

I tried to add a required h:inputText outside the p:dataTable which works as expected and prevents the form from being submitted as long as it is empty.

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

Any ideas about how I get a required p:inputText field in p:cellEdit ?

推荐答案

根据rion18的建议.我正在检查我的支持bean是否设置了所有值.仅当所有值均已设置时,才会显示提交"按钮.这是我最终完成此操作的方式:

According to rion18's suggestion. I'm checking in my backing bean if all values are set. Only if all values are set the submit button is shown. Here's how I ended up doing this:

<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:

In my backing bean I have a simple function that iterates over the dataList:

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

这篇关于Primefaces cellEditor必需的inputText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆