I would like to call a form as pop-up window (a form with some input fields and a submit button) and then read the user selected results from the session. The problem is that the mixing of JS code (pop-up window) with CF (server-side) code, as is expected, causes the process to output the session variable before the process updates it. For better understanding, hereunder is the scenario together with some relevant code snippets:
我想将窗体称为弹出窗口(带有一些输入字段和提交按钮的表单),然后从会话中读取用户选择的结果。问题是JS代码(弹出窗口)与CF(服务器端)代码的混合(如预期的那样)会导致进程在进程更新之前输出会话变量。为了更好地理解,下面是场景以及一些相关的代码片段:
Scenario:
场景:
1. User calls ShowForm(..)
2. ShowForm(..) displays a pop-up window and waits for the user
to submit his selection
3. The result gets stored in the session
4. The function returns the user-submitted result
form.cfc
form.cfc
<cffunction name="ShowForm" access="public" output="true" returntype="string">
<script>
window.showModalDialog('formpage.cfm',null,"dialogHeight=400px,dialogLeft=150px");
</script>
<cfreturn session.form_result> <!--- @toFix: The return of form_result is happening before the actual form_result is set. --->
</cffunction>
formpage.cfm
formpage.cfm
<cfajaxproxy cfc="components.sess_mgr" jsclassname="JSMaskProxy">
<script>
function submitSelection(formObj)
{
for (i=0; i<intSelValue.length; i++)
result.push(intSelValue[i]);
var instCfProxy = new JSMaskProxy();
instCfProxy.setToSession(result); // updates session.form_result
//window.returnValue=result;
window.close();
}
</script>
<form name="frmDtls">
<td align="center"><input type="button" id="selectButton" name="selectButton" onClick="submitSelection(details);">
</form>
What's your take on this? How to solve this problem?
你对此有何看法?如何解决这个问题呢?
ColdFusion.navigate(..) function can have a callback function and an error handler but the thing is that the callback function can only be a client-side function. If the function could be a CF function or maybe a server-side page I think that would solve this dependency problem.
ColdFusion.navigate(..)函数可以有一个回调函数和一个错误处理程序,但问题是回调函数只能是一个客户端函数。如果该函数可能是CF函数或可能是服务器端页面,我认为这将解决此依赖性问题。
Something on the side, ideally I would love to read the value from window.showModalDialog rather than reading it from the session, but this is just a sketch and the main point here is how to overcome this JS-CF intermingling problem.
侧面的东西,理想情况下我想从window.showModalDialog读取值而不是从会话中读取它,但这只是一个草图,这里的要点是如何克服这个JS-CF混合问题。
2 个解决方案
#1
1
Rather than using window.showModalDialog use something like cfwindow, jQuery dialog or an extjs window. All of these have some form of callback or event listener. cfwindow has a onHide function, jQuery dialog has a close option to which a function can be assigned, ext.window has onHide, as well as event listeners.
而不是使用window.showModalDialog使用cfwindow,jQuery对话框或extjs窗口。所有这些都有某种形式的回调或事件监听器。 cfwindow有一个onHide函数,jQuery对话框有一个close选项,可以为其分配一个函数,ext.window有onHide,以及事件监听器。
All of these will allow you to open a new "window" and run some function when the window is hidden or closed. Those functions should all have access to anything from the window as well as being able to access the main window.
所有这些都允许您打开一个新的“窗口”并在窗口隐藏或关闭时运行一些功能。这些函数应该都可以从窗口访问任何东西,并且能够访问主窗口。
Ray Camden has a cfwindow example : http://www.coldfusionjedi.com/index.cfm/2008/9/26/Ask-a-Jedi-Another-CFWINDOW-Example
Ray Camden有一个cfwindow示例:http://www.coldfusionjedi.com/index.cfm/2008/9/26/Ask-a-Jedi-Another-CFWINDOW-Example
jQuery dialog has an example of what you're after : http://jqueryui.com/demos/dialog/#modal-form
jQuery对话框有一个你想要的例子:http://jqueryui.com/demos/dialog/#modal-form
Sencha's Ext.Window examples show passing values to the main window when a dialog is closed : http://dev.sencha.com/deploy/dev/examples/message-box/msg-box.html
Sencha的Ext.Window示例显示关闭对话框时将值传递到主窗口:http://dev.sencha.com/deploy/dev/examples/message-box/msg-box.html
Plenty of options there. I hope they help.
那里有很多选择。我希望他们帮忙。
#2
0
Problem solved!
问题解决了!
The solution adopted is based on Stephen Moretti idea which is that of replacing window.showModalDialog with cfwindow call. This alone does not solve the problem. However, I worked when replacing the script tag with cfscript, and then inside the cfscript I simply do a server-side redirection to the page with cfwindow tag.
采用的解决方案基于Stephen Moretti的想法,即用cfwindow调用替换window.showModalDialog。仅这一点并不能解决问题。但是,我在用cfscript替换脚本标签时工作,然后在cfscript中我只是使用cfwindow标签对服务器端重定向到页面。
#1
1
Rather than using window.showModalDialog use something like cfwindow, jQuery dialog or an extjs window. All of these have some form of callback or event listener. cfwindow has a onHide function, jQuery dialog has a close option to which a function can be assigned, ext.window has onHide, as well as event listeners.
而不是使用window.showModalDialog使用cfwindow,jQuery对话框或extjs窗口。所有这些都有某种形式的回调或事件监听器。 cfwindow有一个onHide函数,jQuery对话框有一个close选项,可以为其分配一个函数,ext.window有onHide,以及事件监听器。
All of these will allow you to open a new "window" and run some function when the window is hidden or closed. Those functions should all have access to anything from the window as well as being able to access the main window.
所有这些都允许您打开一个新的“窗口”并在窗口隐藏或关闭时运行一些功能。这些函数应该都可以从窗口访问任何东西,并且能够访问主窗口。
Ray Camden has a cfwindow example : http://www.coldfusionjedi.com/index.cfm/2008/9/26/Ask-a-Jedi-Another-CFWINDOW-Example
Ray Camden有一个cfwindow示例:http://www.coldfusionjedi.com/index.cfm/2008/9/26/Ask-a-Jedi-Another-CFWINDOW-Example
jQuery dialog has an example of what you're after : http://jqueryui.com/demos/dialog/#modal-form
jQuery对话框有一个你想要的例子:http://jqueryui.com/demos/dialog/#modal-form
Sencha's Ext.Window examples show passing values to the main window when a dialog is closed : http://dev.sencha.com/deploy/dev/examples/message-box/msg-box.html
Sencha的Ext.Window示例显示关闭对话框时将值传递到主窗口:http://dev.sencha.com/deploy/dev/examples/message-box/msg-box.html
Plenty of options there. I hope they help.
那里有很多选择。我希望他们帮忙。
#2
0
Problem solved!
问题解决了!
The solution adopted is based on Stephen Moretti idea which is that of replacing window.showModalDialog with cfwindow call. This alone does not solve the problem. However, I worked when replacing the script tag with cfscript, and then inside the cfscript I simply do a server-side redirection to the page with cfwindow tag.
采用的解决方案基于Stephen Moretti的想法,即用cfwindow调用替换window.showModalDialog。仅这一点并不能解决问题。但是,我在用cfscript替换脚本标签时工作,然后在cfscript中我只是使用cfwindow标签对服务器端重定向到页面。