JSF - Richfaces,处理提交的表单数据,然后确认继续或取消 [英] JSF - Richfaces, process submitted form data and then confirm to continue or cancel
问题描述
我想在提交表单时显示一个确认对话框来连续或取消保存操作。我有一个带有保存按钮的表单,它正在调用一个动作方法来保留表单中的数据。
单击保存按钮时,在表单数据持久化之前,将在服务器端读取一个文件。来自文件的数据将被加入到表单数据中,然后表单数据将被保留。我需要一些表单中的值来定义哪个文件将被读取。到目前为止没有问题。当FileNotFoundException被抛出或文件中的必需数据未被找到时,我想显示一个确认对话框来连续或取消保存操作带有消息。
I want to show a confirmation dialog to continiue or cancel a save operation when a form is submitted. I have a form with a save button which is calling an action methode to persist data in the form. When save button is clicked, a file will be readed on serverside before the form data is persisted. Data from the file will be joined into form data and then te form data will be persisted. I need some values from the form to define which file will be readed. There is no problem so far. When a FileNotFoundException throwed or the neccessary data from the file is not found, then i want to show a confirmation dialog to continiue or cancel save operation with caused message.
是否有人有一些例子或任何想法如何处理这个?我需要使用a4j吗?谢谢。
我正在使用Rifchfaces 3.3.3和Seamframework 2.2。
Does anybody have some examples or any ideas how to handle this? Do i need to use a4j? Thanks. I am using Rifchfaces 3.3.3 and Seamframework 2.2.
推荐答案
起初我必须更正我的问题标题。 不是正在处理提交的表单数据,而是一些表单数据,将在验证后提交。
At first i have to correct my question title. It is not going on "processing submitted form data" but a form data that will be submitted after some validation.
现在的解决方案。
例如我的表单中有以下内容:
For example I have following in my form:
-
某些文件夹
some filelds
a4j:commandButton重新渲染字段并执行doSomeStuff()操作
an a4j:commandButton to reRender the fields and perform doSomeStuff() action
一个隐藏的h:或a4j:commandButton提交表单。
an hidden h: or a4j:commandButton to submit the form.
1-用户点击'fake'提交按钮,这是一个a4j:commandButtton,
1- User clicks on 'fake' submit button which is an a4j:commandButtton,
2- reRender属性中的Ajax调用更新字段
2- Ajax call updates fields in reRender attribute
3-之后,方法doSomeStuff()执行与rerendered字段值
3- After that,method doSomeStuff() is performed with rerendered field values
4-最终Javascript将运行提交形式与否。
4- In the end Javascript will run to submit form or not.
表单:
<h:form id="myForm">
<h:inputText id="name" value="#{personHome.person.name}"/>
<h:inputText id="surname" value="#{personHome.person.surname}"/>
<a:commandButton value="Save" reRender="name, surname"
action="#{personHome.doSomeStuff()}"
oncomplete="return checkMessage('#{personHome.success}')"
id="a4jSave" />
<h:commandButton id="save" value="Save"
action="#{personHome.persist}"
style="visibility:hidden" />
</h:form>
JavaScript:
JavaScript:
<script language="javascript">
function checkMessage(success) {
if(success =='false')
{
return confirm('Do you want to submit this form?') ? submitForm() : false;
} else {
submitForm ();
}
}
function submitForm() {
document.getElementById('myForm:save').click();
return false;
}
</script>
这篇关于JSF - Richfaces,处理提交的表单数据,然后确认继续或取消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!