重置表单中的所有字段 [英] Reset all fields in form

查看:86
本文介绍了重置表单中的所有字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在对话框表单中选择确认按钮后,我试图重置表单字段

I am trying to reset the form fields after choosing confirm button in a dialog form

<h:form id="form">  
<p:panel id="panelform">
 <h:panelGrid id="formulaire" columns="2"> 
...
</h:panelGrid>
</p:panel>
 <p:dataTable ..... </p:dataTabe>
</h:form>
<p:confirmDialog style="position: absolute; width: 50px; border-color: blue" id="deleteData"  message="Your Database Will be completely removed. Are you sure? "  
                                     appendToBody="true"                                                               
                                     header="Delete List" severity="alert" widgetVar="deleteDialog">                          
                        <h:form>     
                            <p:commandButton id="confirm" value="Confirm" actionListener="#{MB.deleteData()}" update=":form" ajax="true" oncomplete="deleteDialog.hide(); purchase.hide();" >                            
                            </p:commandButton>  
                            <p:commandButton id="cancel" value="Later" onclick="deleteDialog.hide();" type="button" />                           
                        </h:form>
                    </p:confirmDialog> 

我的sessionScoped bean中的deleteData方法是

My deleteData method in my sessionScoped bean is

 public String deleteData() {
    logger.log(Level.SEVERE, "*****delete Datas***** ");
    dataBusinessLocal.deletedatas(datas);
    logger.log(Level.SEVERE, "*****delete Data***** ");
    dataBusinessLocal.deleteData(data);
    datas.clear();
    RequestContext.getCurrentInstance().reset("form:panelform");  
    return "datasList";
}

推荐答案

RequestContext.getCurrentInstance().reset("form:panelform");清除缓存的值-如果ValidationPhase期间的验证无法正确进行,则可以在以下内容中向用户显示错误的值页面.

RequestContext.getCurrentInstance().reset("form:panelform"); clears cached values - in case a validation during ValidationPhase did not work out correctly, the wrong values can be shown to the user on the following page.

我想,这不是清除模型中的值.因此,在RenderResponse期间,将Model值写回到xhtml-output.为防止这种情况,只需在操作方法中将输入字段手动设置为null.

I guess, what it not does is to clear values from the Model. Caused by this, during RenderResponse the Model values will be written back to the xhtml-output. To prevent that, just set the input fields to null manually in your action method.

以下链接如何清除p:dataTable中的所有输入字段?" 建议设置输入type="reset" .如果有效,请给我一个提示. :-)

The following link "How to clear all input fields in p:dataTable?"suggests setting the input type="reset". If it works, give me a hint. :-)

这篇关于重置表单中的所有字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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