且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何创建oracle apex服务器端实时验证而无需提交页面

更新时间:2022-02-02 21:42:02

是的,您可以使用Dynamic Action和JavaScript函数apex.server.process创建服务器端验证.

Yes, you can create server side validation by using Dynamic Action and JavaScript function apex.server.process.

一个基本的例子来演示-

A basic example to demonstrate-

  • 创建页面项目,例如您页面中的P4_NAME
  • 创建页面处理并将执行点选择为"AJAX 打回来".
  • Create a page item e.g. P4_NAME in your page
  • Create a page process and select the execution point as "AJAX CALLBACK".

在下面的代码中,我正在检查P4_ITEM值,您可以编写自己的逻辑进行验证.

In below code I am checking the P4_ITEM value, you can write your own logic to validate.

BEGIN
   IF :P4_NAME = 'HIMANSHU'
   THEN
      HTP.prn ('SUCCESS');
   ELSE
      HTP.prn ('ERROR');
   END IF;
END;

  • 现在创建一个新的动态操作,然后将事件选择为"LOSE FOCUS",将选择类型选择为项目",并在项目中).选择商品名称.
    • Now create a new dynamic action and select the Event as "LOSE FOCUS", Selection Type as "Item(s)" and in Item(s) select the item name.
      • 创建一个真实的动作,然后选择执行JavaScript代码".

      在代码部分中,像下面一样实现apex.server.process-

      In code section, implement apex.server.process like below-

apex.server.process('validate_name',
{
   pageItems : '#P4_NAME'
}
,
{
   dataType : 'text', success : function(data)
   {
      if(data != 'SUCCESS')alert(data);
   }
}
)

第一个参数是我们之前创建的页面流程名称(validate_name),第二个是您要提交给流程的数据,第三个是选项. 有关 apex.server.process

The first argument is the page process name(validate_name) which we have create earlier, second the data you want to submit to the process and third is options. For more details on apex.server.process

完成了.刷新页面并检查.验证失败时,您会收到警报.

It is done. Refresh your page and check. On validation failure you will get an alert.

您可以进一步自定义JS代码,以更精致的方式显示错误消息,而不是显示警报.

You can customize your JS code further to display error messages in more fancy way instead of showing alert.