【问题标题】:Alert message after submit and validation page in oracle apexoracle apex 中提交和验证页面后的警报消息
【发布时间】:2020-02-02 01:21:19
【问题描述】:

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

当按下按钮且 item 为 null 时,会出现成功的 Alert 消息,然后系统显示错误(该 item 是必需的)。只有在流程和验证没有错误的情况下完成,并且在警报消息中按下确定时,如何才能显示成功的警报消息重定向到网站并从会话中注销

【问题讨论】:

  • 看来这些项目毕竟不是必需的(如果您想忽略警告)。所以将它们设置为非必需。
  • 没有它需要的项目,但是当提交页面时,警报消息出现在验证错误之前,因为当项目为空时,我如何更改警报不会出现。
  • 这意味着我如何停止警报消息并仅在成功处理和验证时出现
  • 听起来您不需要动态操作。只需将您的按钮操作提交页面并创建一个分支来重定向到另一个站点。这是一种更简单、更简洁的方法。
  • 我知道,但是没有出现成功消息,因为重定向到另一个网站(点击它时我在网站上有一个链接,重定向到公共页面以填写您的数据,按完成后返回网站),因为我需要动态警报消息。

标签: oracle-apex


【解决方案1】:

有不同的方法可以解决这个问题。您当前正在混合使用动态操作和页面级验证以及无法很好地协同工作的流程。我建议您将所有逻辑移至动态操作。以下是我认为您正在尝试做的分步说明。您可以从中学习,然后将您想要的内容集成到您的解决方案中。

  1. 创建一个新的空白页。我的是第 17 页。如果不同,您需要使用您的页码更新对“P17”的引用。禁用页面级属性 Warn on Unsaved Changes 以防止在重定向到 Google 之前出现提示。
  2. 向页面添加新的 HTML 区域。
  3. 向区域添加新项目。将 Name 设置为 P17_FIRST_NAME 并保留 Text Field 的默认 Type
  4. 向区域添加新项目。将 Name 设置为 P17_LAST_NAME 并保留 Text Field 的默认 Type
  5. 向区域添加新项目。将 Name 设置为 P17_RESULT,将 Type 设置为 Hidden,并将 Value Protected 设置为 没有。此项将用于通过 Ajax 将消息从服​​务器传输到客户端。
  6. 向区域添加一个按钮。将 Name 设置为 RUN_PROCESS 并将 Action 设置为 Defined by Dynamic Action
  7. 创建一个在单击按钮时触发的新动态操作。最简单的方法是右键单击该按钮并选择创建动态操作。将 Name 设置为 RUN_PROCESS clicked
  8. 选择默认为动态操作创建的显示操作。将 Action 设置为 Execute PL/SQL Code 并将以下代码复制粘贴到 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。

  9. 仍在 执行 PL/SQL 代码 操作时,将 要提交的项目 设置为 P17_FIRST_NAME,P17_LAST_NAME要返回的项目P17_RESULT。这样您就可以在流程执行之前将值从页面传输到会话状态,然后在流程完成执行后返回到页面。
  10. 创建一个在 P17_RESULT 的 Change 事件上触发的新动态操作。最简单的方法是右键单击该项目并选择创建动态操作。将 名称 设置为 P17_RESULT 已更改
  11. 选择默认为动态操作创建的显示操作。将 Action 设置为 Execute JavaScript Code 并将以下代码复制粘贴到 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.navigationapex.message 的文档:https://apex.oracle.com/jsapi

附:这是使用 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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-05
    • 1970-01-01
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-25
    相关资源
    最近更新 更多