JSF - Richfaces,处理提交的表单数据然后确认继续或取消

发布于 2024-12-04 16:22:28 字数 317 浏览 4 评论 0原文

我想显示一个确认对话框,以连续或取消提交表格时的保存操作。我有一个带有保存按钮的表单,该表格正在调用动作方法以持久形式的数据。 单击“保存”按钮时,在持续表单数据之前,将在Serveride上读取文件。文件中的数据将连接到表单数据中,然后将te表单数据持续存在。我需要从表单中的一些值来定义将读取哪些文件。到目前为止没有问题。当抛出FilenotFoundException或找不到文件中的必要数据时,我想显示一个确认对话框,以连续或取消带有消息的保存操作。

有人有一些例子或任何想法如何处理吗?我需要使用A4J吗?谢谢。 我正在使用Rifchfaces 3.3.3和SeamFramework 2.2。

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晚雾 2024-12-11 16:22:28

首先我必须纠正我的问题标题。它不是正在“处理提交的表单数据”,而是经过验证后将提交的表单数据

现在解决方案。

例如,我的表单中有以下内容:

  • 一些 filelds

  • 一个 a4j:commandButton 来重新渲染字段并执行 doSomeStuff() 操作

  • 隐藏的 h: 或 a4j:commandButton 来提交表单。

1- 用户点击“假”提交按钮(a4j:commandButtton),

2- Ajax 调用更新 reRender 属性中的字段

3- 之后,使用重新渲染的字段值执行方法 doSomeStuff()

4- 最后 Javascript 将运行到是否提交表格。

形式:

<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:

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

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.

Now the solution.

For example I have following in my form:

  • some filelds

  • an a4j:commandButton to reRender the fields and perform doSomeStuff() action

  • an hidden h: or a4j:commandButton to submit the form.

1- User clicks on 'fake' submit button which is an a4j:commandButtton,

2- Ajax call updates fields in reRender attribute

3- After that,method doSomeStuff() is performed with rerendered field values

4- In the end Javascript will run to submit form or not.

Form:

<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:

<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>  
后eg是否自 2024-12-11 16:22:28

是的,你需要使用 a4j。

尝试类似的方法(未经测试,但遵循算法):

<a4j:commandButton  onclick="if(messageHasToBeDisplayed){Richfaces.showModalPanel('modalId');}else{doSomeStuff();}"  />
...
<a4j:jsFunction name="doSomeStuff" action="#{controller.doSomeStuff}" reRender="..."/>

这向您展示了如何在必要时显示模式面板。
如果没有更多代码,我无法为您提供更多帮助,但我认为这应该对您有所帮助......

Yes you need to use a4j.

Try something like that (non tested, but follow the algorithm) :

<a4j:commandButton  onclick="if(messageHasToBeDisplayed){Richfaces.showModalPanel('modalId');}else{doSomeStuff();}"  />
...
<a4j:jsFunction name="doSomeStuff" action="#{controller.doSomeStuff}" reRender="..."/>

This shows you how to display a modal panel if necessary.
Without more code I can't help you more, but I think this should help you...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文