oracle apex中提交和验证页面后的警报消息

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

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

还有麦甘

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

  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属性中。

    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. 选择默认为动态动作创建显示动作。操作设置执行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.navigationapex.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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章