【问题标题】:primefaces editable dataTable updates after validation failure in previous rows在前几行中验证失败后,primefaces 可编辑数据表更新
【发布时间】:2013-02-05 19:00:51
【问题描述】:

我在谷歌上搜索了很多我的问题,但似乎没有人遇到相同的问题,或者它没有按照我想要的方式解决

我有一个可编辑的<p:dataTable editable="true" editMode="cell">,不管是单元格还是行(在 Primefaces 3.5 中)
我在一列上有一个验证,当我输入一个字符串 > 4 验证错误发生在 <p:inputText> 仍然可编辑的地方
我有一个<p:commandButton>,当我单击此按钮时,我正在向此<p:dataTable> 添加一行,并且我正在更新表格以显示行
问题是当我添加一行并且在前一行中出现验证错误(单元格处于可编辑模式<p:inputText>)时,<p:dataTable> 将按照我所说的进行更新,并且具有验证错误的单元格将更改为<p:outputText> 具有空值
如果我按下前一个单元格(它有一个错误验证并且为空),则会显示错误的输入,如果我按下 Tab,它将被提交(<p:inputText> 更改为 <p:outputText> 输入错误)
我怎样才能实现可编辑的验证

代码示例:

<h:form id="form">  

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

    <p:contextMenu for="cars" widgetVar="cMenu">     
        <p:menuitem value="Edit Cell" icon="ui-icon-search" onclick="carsTable.showCellEditor();return false;"/>    
        <p:menuitem value="Hide Menu" icon="ui-icon-close" onclick="cMenu.hide()"/>    
    </p:contextMenu>   

    <p:dataTable id="cars" var="car" value="#{tableBean.carsSmall}" editable="true" editMode="cell" widgetVar="carsTable">  

        <f:facet name="header">  
            In-Cell Editing  
        </f:facet>  

        <p:ajax event="cellEdit" listener="#{tableBean.onCellEdit}" update=":form:messages" />  

        <p:column headerText="Model" style="width:25%">  
               <p:cellEditor>  
                   <f:facet name="output">
                           <h:outputText value="#{car.model}" />
                   </f:facet>  
                   <f:facet name="input">
                           <p:inputText id="modelInput" value="#{car.model}" style="width:96%">
                                <f:validateLength minimum="0" maximum="4">
                           </p:inputText>
                   </f:facet>  
               </p:cellEditor>  
           </p:column>  

           <p:column headerText="Year" style="width:25%">  
            <p:cellEditor>  
                <f:facet name="output">
                     <h:outputText value="#{car.year}" />
                </f:facet>  
                <f:facet name="input">
                     <p:inputText value="#{car.year}" style="width:96%" label="Year"/>
                </f:facet>  
            </p:cellEditor>  
        </p:column> 

    </p:dataTable>   
    <p:commandButton action="#{tableBean.addCar}" update=":cars :messages" process="@this"/>
</h:form>


public class TableBean implements Serializable {  

    private List<Car> carsSmall;

    public TableBean() {  
        carsSmall = new ArrayList<Car>();  
    }  

    public List<Car> getCarsSmall() {  
        return carsSmall;  
    }  

    public void onCellEdit(CellEditEvent event) {  
        Object oldValue = event.getOldValue();  
        Object newValue = event.getNewValue();  

        if(newValue != null && !newValue.equals(oldValue)) {  
            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue);  
            FacesContext.getCurrentInstance().addMessage(null, msg);  
        }  
    }  

    public String addCar(){
         carsSmall.add(new Car());
         return null;
    }
}

【问题讨论】:

    标签: hibernate validation jsf-2 primefaces


    【解决方案1】:

    我对您的要求几乎没有澄清。(1)您是否一次向数据表添加一行 (2) 表格中的单元格是否始终可编辑,或者只有您要添加的行才可编辑。 (3) 当您点击按钮时,您是验证所有行还是仅验证要添加到数据表的行??

    【讨论】:

    • 感谢您的关注 (1) 是的,我一次添加一行 (2) 所有单元格都是可编辑的,并提醒我使用 primefaces 3.5 和 其中所有单元格都是可编辑的,如果是 在每一行都有一个 ,当点击时整行都会在其中编辑模式
    • (3) 当我点击添加按钮 我正在做的是此按钮验证所有行或仅添加的行,如果不是,我如何验证所有行
    猜你喜欢
    • 1970-01-01
    • 2012-01-30
    • 1970-01-01
    • 2017-10-23
    • 2020-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多