我在执行以下动态操作,
提交页面,
成功警报消息,
注销并重定向到另一个网站(www.google.com),
并且页面中有两个必填项。
当按下按钮并且项目为null时,将显示成功的Alert消息,然后系统显示错误(该项目为必填项)。仅当过程和验证已完成且没有错误,并且在警报消息中按“确定”时,才可以显示成功的警报消息,重定向到网站并从会话中注销
您可以通过不同的方法来解决这个问题。您目前正在混合使用动态操作和页面级验证以及流程,这些流程无法很好地发挥作用。我建议您将所有逻辑移至动态动作。以下是逐步说明,以做我认为您要尝试做的事情。您可以从中学习,然后将想要的内容集成到解决方案中。
选择默认为动态动作创建的显示动作。将操作设置为执行PL / SQL代码,然后将以下代码复制粘贴到PL / SQL Code属性中。
declare
l_result_obj json_object_t := json_object_t();
l_errors_arr json_array_t := json_array_t();
l_error_obj json_object_t;
begin
if :P17_FIRST_NAME is null
then
l_error_obj := json_object_t();
l_error_obj.put('pageItem', 'P17_FIRST_NAME');
l_error_obj.put('message', 'First Name is required.');
l_errors_arr.append(l_error_obj);
end if;
if :P17_LAST_NAME is null
then
l_error_obj := json_object_t();
l_error_obj.put('pageItem', 'P17_LAST_NAME');
l_error_obj.put('message', 'Last Name is required.');
l_errors_arr.append(l_error_obj);
end if;
if l_errors_arr.get_size() > 0
then
l_result_obj.put('status', 'error');
l_result_obj.put('errors', l_errors_arr);
:P17_RESULT := l_result_obj.to_string();
return;
end if;
null; -- do "success" processing here
l_result_obj.put('status', 'success');
l_result_obj.put('message', 'Hi ' || :P17_LAST_NAME || ' ' || :P17_LAST_NAME ||
'! You will now be redirected to Google.');
:P17_RESULT := l_result_obj.to_string();
end;
如您所见,现在正在流程内部进行验证。PL / SQL代码利用Oracle 12.2引入的JSON类型。如果您使用的是旧版本的数据库,则可以修改代码以改为使用APEX_JSON。
选择默认为动态动作创建的显示动作。将操作设置为执行JavaScript代码,然后将以下代码复制粘贴到Code属性中。
var result = JSON.parse($v('P17_RESULT'));
apex.message.clearErrors();
if (result.status === 'error') {
for (var idx = 0; idx < result.errors.length; idx++) {
result.errors[idx].type = 'error';
result.errors[idx].location = ['page', 'inline'];
result.errors[idx].unsafe = false;
}
apex.message.showErrors(result.errors);
} else if (result.status === 'success') {
apex.message.alert(result.message, function(){
apex.navigation.redirect('https://google.com');
});
}
JavaScript代码从过程中获取结果,并显示错误消息或警报。我使用apex.message.alert
而不是apex.message.showPageSuccess
因为前者在关闭消息时支持回调。取消邮件后,apex.navigation.redirect
将用户带到Google。
最终的样子如下:
我希望这里有足够的信息供您了解发生了什么。如果您有任何问题,请告诉我。你会发现文件apex.navigation
和apex.message
这里:https://apex.oracle.com/jsapi
PS这是使用APEX_JSON的PL / SQL代码的示例。
declare
l_error_count pls_integer := 0;
l_result_obj clob;
begin
apex_json.initialize_clob_output;
apex_json.open_object();
apex_json.open_array('errors');
if :P17_FIRST_NAME is null
then
l_error_count := l_error_count + 1;
apex_json.open_object();
apex_json.write('pageItem', 'P17_FIRST_NAME');
apex_json.write('message', 'First Name is required.');
apex_json.close_object();
end if;
if :P17_LAST_NAME is null
then
l_error_count := l_error_count + 1;
apex_json.open_object();
apex_json.write('pageItem', 'P17_LAST_NAME');
apex_json.write('message', 'Last Name is required.');
apex_json.close_object();
end if;
apex_json.close_array();
if l_error_count > 0
then
apex_json.write('status', 'error');
apex_json.close_object();
:P17_RESULT := apex_json.get_clob_output();
apex_json.free_output;
return;
end if;
null; -- do "success" processing here
apex_json.write('status', 'success');
apex_json.write('message', 'Hi ' || :P17_LAST_NAME || ' ' || :P17_LAST_NAME ||
'! You will now be redirected to Google.');
apex_json.close_object();
:P17_RESULT := apex_json.get_clob_output();
apex_json.free_output;
end;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句