保存后如何重置表单? [英] How can I reset form after save?
本文介绍了保存后如何重置表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在PrimeFaces对话框中进行产品插入表单。我的bean的作用域是会话。我可以插入一个产品,但是当我尝试插入另一个产品时,表单中有以前的产品信息。我想重置表单。我试过 UIInput
但它不起作用。如何清除表单?
I am doing a product insert form in PrimeFaces dialog. My bean's scope is session. I can insert a product, but when I try to insert another product, the form has previous product's information. I want to reset form. I tried UIInput
but it doesnt work. How can I clear the form?
推荐答案
只需在保存后创建新产品并确保您是ajax更新保存后的表格。
Just create a new product after saving it and make sure that you're ajax-updating the form after save.
Eg
<h:form>
<h:inputText value="#{productController.product.name}" />
<h:inputTextarea value="#{productController.product.description}" />
<h:selectOneMenu value="#{productController.product.category}">
<f:selectItems value="#{applicationData.categories}" />
</h:selectOneMenu>
<p:commandButton value="Save" action="#{productController.save}" update="@form" />
</h:form>
with
with
public void save() {
productService.save(product);
product = new Product();
}
顺便说一句,那种bean实际上不属于会话范围。把它放在视图范围内。
By the way, that kind of bean really doesn't belong in the session scope. Put it in the view scope.
这篇关于保存后如何重置表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文