Primefaces可编辑的数据表在先前行中的验证失败后进行更新 [英] primefaces editable dataTable updates after validation failure in previous rows

查看:144
本文介绍了Primefaces可编辑的数据表在先前行中的验证失败后进行更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对我的问题进行了大量搜索,但似乎没有人遇到同样的问题,或者解决了问题,而不是我想要的。

我有一个可编辑的< p:dataTable editable =trueeditMode =cell> 如果单元格或行(在Primefaces 3.5中)
没有问题当我输入字符串时出现验证错误> 4验证错误发生在< p:inputText> 仍然可编辑

的地方我有一个< p:commandButton> 当我点击这个按钮时,我正在为这个< p:dataTable> 添加一行,而我正在更新用于显示行的表
问题是,当我添加一行并在上一行中存在验证错误(单元格处于可编辑模式< p: inputText> < p:dataTable> 将按照我所说的更新,并且具有验证错误的单元格将更改为< p:outputText> ,其中包含null值

,如果我按下前一个单元格是一个错误验证,并为空),将显示错误的输入,如果我按下标签它将被提交(< p:inputText> 更改为< p:outputText> 带有错误的输入)

如何实现可编辑
的验证?b $ b代码示例:

 < h:form id =form> 

< p:growl id =messagesshowDetail =true/>

< p:contextMenu for =carswidgetVar =cMenu>
< p:menuitem value =Edit Cellicon =ui-icon-searchonclick =carsTable.showCellEditor(); return false;/>
< / p:contextMenu>

< p:dataTable id =carsvar =carvalue =#{tableBean.carsSmall}editable =trueeditMode =cellwidgetVar =carsTable>

< f:facet name =header>
内嵌编辑
< / f:facet>

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

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

< p:列headerText =年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:栏>

< / p:dataTable>
< / h:表格>


公共类TableBean实现可序列化{

private List< Car> carsSmall;

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

公共列表< 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 +,新:+ newValue);
FacesContext.getCurrentInstance()。addMessage(null,msg);



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


解决方案

I (1)您是否每次向数据表
添加一行(2)表中的单元格是否始终可编辑,或者只有您要添加的行只能编辑。
(3)当你点击按钮时,你是验证所有的行还是只有你要添加到数据表的行?


i googled my problem a lot but it seems that no one has the same exact problem or it is solved not in what i want

I have an editable <p:dataTable editable="true" editMode="cell"> it doesnot matter if cell or row (in Primefaces 3.5)
I have a validation on one column which is when i enter a string > 4 validation error occur where <p:inputText> remains editable
I have a <p:commandButton> when i click this button i am adding a row to this <p:dataTable> and i am updating the table for displaying the row
The problem is when i add a row and in the previous row there is a validation error (cell is being in editable mode <p:inputText>) the <p:dataTable> will be updated as i said and the cell having the validation error will change to a <p:outputText> with null value
and if i press the previous cell (which has an error validation and is null) the wrong input will be displayed and if i press tab it wil be submitted (<p:inputText> changes to <p:outputText> with the wrong input)
How can i acheive the validation on editable

code sample :

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

解决方案

I have few clarification regarding your requirement.(1) Are you adding one row at a time to datatable (2) Are the cells in the table always editable or only the row which you are about to add is only editable. (3) When you click on button are you validating all the rows or only the row you are going to add to data table??

这篇关于Primefaces可编辑的数据表在先前行中的验证失败后进行更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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