oracle apex中提交和验证页面后的警报消息 [英] Alert message after submit and validation page in oracle apex

查看:89
本文介绍了oracle apex中提交和验证页面后的警报消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态的动作在做下面的事情,
提交页面,
成功的警报消息,
注销并重定向到另一个网站(www.google.com),
我在页面中有两个必填项.

I have a dynamic action doing the below ,
Submit page ,
Successful Alert message,
Log out and redirect to another website (www.google.com),
And I have two required item in page.

当按下按钮且项目为null时,将显示成功的Alert消息,然后系统显示错误(该项目为必填项).仅当过程和验证完成且没有错误,并且在警报消息中按ok时,才显示成功的警报消息重定向到网站并从会话中注销

When pressed the button and the item is null ,the successful Alert message appears and after that the system shows the error (the item is required). How can I show the successful alert message only when the process and validation are done without errors ,and when ok is pressed in the alert message redirect to website and log out from the sessions

推荐答案

有多种方法可以解决此问题.您目前正在混合使用动态操作和页面级验证以及流程,这些流程无法很好地发挥作用.我建议您将所有逻辑转移到动态操作"上.以下是逐步说明,以帮助您完成我认为您想做的事情.您可以从中学到东西,然后将想要的东西集成到解决方案中.

There are different ways you could approach this. You're currently using a mix of Dynamic Actions and page-level validations and processes that aren't going to play well together. I suggest you move all the logic to Dynamic Actions. Here are step by step instructions to do what I think you're trying to do. You can learn from this and then integrate what you want back to your solution.

  1. 创建一个新的空白页.我的页面是第17页.如果页码不同,则需要用页码更新对"P17"的引用.禁用页面级属性未保存的更改警告,以防止在重定向到Google之前出现提示.
  2. 在页面上添加新的HTML区域.
  3. 将新项目添加到该区域.将名称设置为 P17_FIRST_NAME ,并保留默认的类型文本字段.
  4. 将新项目添加到该区域.将名称设置为 P17_LAST_NAME ,并保留文本字段的默认类型.
  5. 将新项目添加到该区域.将名称设置为 P17_RESULT ,将类型设置为隐藏,将受保护的值设置为.此项将用于通过Ajax将消息从服​​务器传输到客户端.
  6. 将按钮添加到该区域.将名称设置为 RUN_PROCESS ,将操作设置为由动态操作定义.
  7. 创建一个新的动态操作,该操作在单击按钮时触发.最简单的方法是右键单击按钮,然后选择创建动态操作.将名称设置为单击RUN_PROCESS .
  8. 选择默认情况下为动态操作创建的显示操作.将操作设置为执行PL/SQL代码,然后将以下代码复制粘贴到 PL/SQL Code 属性中.

  1. Create a new blank page. Mine was page 17. You'll need to update references to "P17" with your page number if it's different. Disable the page level attribute Warn on Unsaved Changes to prevent prompts before the redirect to Google.
  2. Add a new HTML region to the page.
  3. Add a new item to the region. Set Name to P17_FIRST_NAME and leave the default Type of Text Field.
  4. Add a new item to the region. Set Name to P17_LAST_NAME and leave the default Type of Text Field.
  5. Add a new item to the region. Set Name to P17_RESULT, Type to Hidden, and Value Protected to No. This item will be used to transfer messages from the server to the client via Ajax.
  6. Add a button to the region. Set Name to RUN_PROCESS and Action to Defined by Dynamic Action.
  7. Create a new Dynamic Action that fires when the button is clicked. The easiest way to do this is to right-click the button and select Create Dynamic Action. Set the Name to RUN_PROCESS clicked.
  8. Select the Show action that was created by default for the Dynamic Action. Set Action to Execute PL/SQL Code and copy-paste the following code into the PL/SQL Code attribute.

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.

As you can see, the validations are now being done inside the process. The PL/SQL code is making use of the JSON types introduced with Oracle 12.2. If you're on an older version of the database, you can adapt the code to use APEX_JSON instead.

选择默认情况下为动态操作创建的显示操作.将 Action 设置为 Execute JavaScript Code (执行JavaScript代码),然后将以下代码复制并粘贴到 Code 属性中.

Select the Show action that was created by default for the Dynamic Action. Set Action to Execute JavaScript Code and copy-paste the following code into the Code attribute.

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.

The JavaScript code takes the result from the process and either displays error messages or an alert. I'm using apex.message.alert instead of apex.message.showPageSuccess because the former supports a callback when the message is dismissed. When the message is dismissed, apex.navigation.redirect takes the user to Google.

这是最后的样子:

我希望这里有足够的信息供您了解正在发生的事情.如果您有任何疑问,请告诉我.您可以在以下位置找到apex.navigationapex.message的文档: https://apex.oracle.com/jsapi

I hope there's enough information here for you to understand what's going on. Let me know if you have any questions. You'll find the documentation for apex.navigation and apex.message here: https://apex.oracle.com/jsapi

P.S.这是一个使用APEX_JSON的PL/SQL代码的示例.

P.S. Here's an example of what the PL/SQL code would look like using APEX_JSON.

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;

这篇关于oracle apex中提交和验证页面后的警报消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆