APEX行选择器第2部分 [英] APEX row selector part 2
问题描述
这是5天前发布的"APEX行选择器"的后续内容.
This is a follow on to "APEX row selector" posted 5 days ago.
问题是从交互式网格中收集多个值.从出色的链接到提供的帖子,我都能够实现这一目标.但是,项目的下一部分是打开编辑对话框页面并更新多个值.
The problem was collecting multiple values from an interactive grid. From the excellent links to post supplied I was able to achieve this. However, the next part of the project is to open an edit dialog page and update multiple values.
我将此代码添加到了交互式网格的属性中:
I added this code to the attribute of the interactive grid:
function (config)
{
var $ = apex.jQuery,
toolbarData = $.apex.interactiveGrid.copyDefaultToolbar(),
toolbarGroup = toolbarData.toolbarFind("actions3");
toolbarGroup.controls.push(
{
type: "BUTTON",
action: "updateCar",
label: "Edit Selected Cars",
hot: true,
});
config.toolbarData = toolbarData;
config.initActions = function (actions)
{
// Defining the action for activate button
actions.add(
{
name: "updateCar",
label: "Edit Selected Cars",
action: updateCar
});
}
function updateCar(event, focusElement)
{
var i, records, model, record,
view = apex.region("ig_car").widget().interactiveGrid("getCurrentView");
var vid = "";
model = view.model;
records = view.getSelectedRecords();
if (records.length > 0)
{
for (i = 0; i < records.length; i++)
{
record = records[i];
alert("Under Development " + record[1]);
vid = vid + record[1] + "||";
apex.item("P18_CAR").setValue(vid);
// need to open next page here and pass parameters
}
}
}
return config;
}
我需要知道如何打开表单并使参数值可用于传递给oracle更新脚本.
I need to know how to open a form and have the parameter values available to pass to an oracle update script.
感谢您提供的任何帮助.我确实找到了一些帖子,但我确实需要一个很好的例子.我已经尝试了一切都无济于事.
Thank you for any help you can provide. I did find some posts but I really need a good example. I have tried everything to no avail.
推荐答案
您可以通过多种方式执行此操作.这是一种方法,也许其他人会提供更有效的选择.
There are various ways you could do this. Here's one way, perhaps someone else will offer a more efficient option.
此处记录了APEX中用于导航的JavaScript选项: https://docs.oracle. com/en/database/oracle/application-express/19.1/aexjs/apex.navigation.html
The JavaScript options for navigation in APEX are documented here: https://docs.oracle.com/en/database/oracle/application-express/19.1/aexjs/apex.navigation.html
由于您要打开单独的页面,因此可能要使用apex.navigation.dialog
,这是APEX从报表,按钮等打开模式页面时自动使用的内容.
Since you're trying to open a separate page, you probably want to use apex.navigation.dialog
, which is what APEX automatically uses when opening modal pages from reports, buttons, etc.
但是,如文档中所述,出于安全目的,导航URL必须在服务器端生成.您需要一个动态URL(页面呈现时未知),因此需要一种变通方法来生成它.有了URL后,导航到它很容易.那么您如何获得URL?阿贾克斯.
However, as noted in the doc, the URL for the navigation must be generated server-side for security purposes. You need a dynamic URL (one not known when the page renders), so you'll need a workaround to generate it. Once you have the URL, navigating to it is easy. So how do you get the URL? Ajax.
创建一个Ajax进程以生成URL
- 在报告/网格页面的处理"选项卡下,右键单击"Ajax回调",然后选择"创建流程".
- 将名称"设置为 GET_FORM_URL .
- 将PL/SQL代码设置为以下
- Under the processing tab of the report/grid page, right-click Ajax Callback and select Create Process.
- Set Name to GET_FORM_URL.
- Set PL/SQL code to the following
代码:
declare
l_url varchar2(512);
begin
l_url := apex_page.get_url(
p_application => :APP_ID,
p_page => 3,
p_items => 'P3_ITEM_NAME',
p_values => apex_application.g_x01
);
apex_json.open_object();
apex_json.write('url', l_url);
apex_json.close_object();
end;
请注意,我正在使用apex_item.get_url
来获取URL,这是apex_util.prepare_url
的替代方法.我还使用apex_json
发出JSON来响应客户端.
Note that I'm using apex_item.get_url
to get the URL, this is an alternative to apex_util.prepare_url
. I'm also using apex_json
to emit JSON for the response to the client.
此外,对apex_application.g_x01
的引用也很重要,因为它将包含从调用页面中选择的值.您将看到下一步的设置.
Also, the reference to apex_application.g_x01
is important, as this will contain the selected values from the calling page. You'll see how this was set in the next step.
使用JavaScript打开URL
在调用页面的函数和全局变量声明"属性中输入以下代码:
Enter the following code in the Function and Global Variable Declaration attribute of the calling page:
function openFormPage(ids) {
apex.server.process(
'GET_FORM_URL',
{
x01: ids.join(':')
},
{
success: function (data) {
var funcBody = data.url.replace(/^"javascript:/, '').replace(/\"$/,'');
new Function(funcBody).call(window);
},
error: function (jqXHR, textStatus, errorThrown) {
console.error(errorThrown);
// handle error
}
}
);
}
在这种情况下,我使用的是 apex.server.process 来调用服务器端的PL/SQL进程.请注意,我正在将ids.join(':')
的值传递给x01
.该值将在PL/SQL代码中以apex_application.g_x01
的形式访问.您可以使用其他项目,也可以将冒号分隔的值字符串仅传递给一个项目(就像我在做的那样).
In this case, I'm using apex.server.process to call the server-side PL/SQL process. Note that I'm passing the value of ids.join(':')
to x01
. That value will become accessible in the PL/SQL code as apex_application.g_x01
. You can use additional items, or you can pass a colon-delimited string of values to just one item (as I'm doing).
返回给客户端的URL将不是标准URL,而是包含该URL的JavaScript代码段.您需要删除开头和结尾部分,并使用剩下的内容在JavaScript中生成动态函数.
The URL that's returned to the client will not be a standard URL, it will be a JavaScript snippet that includes the URL. You'll need to remove the leading and trailing parts and use what's left to generate a dynamic function in JavaScript.
通常对此不屑一顾,但是我相信在这种情况下它是足够安全的,因为我知道我可以相信流程调用的响应不是恶意的JavaScript代码.
This is generally frowned upon, but I believe it's safe enough in this context since I know I can trust that the response from the process call is not malicious JavaScript code.
添加安全检查!
由于您正在创建一种动态方式来生成用于打开第3页(或您要定位的任何页面)的URL,因此需要确保对模式页面进行保护.在该页面上,创建一个Header之前的过程,以验证P3_ITEM_NAME的值.如果用户不应该访问这些值,则抛出异常.
Because you're creating a dynamic way to generate URLs to open page 3 (or whatever page you're targeting), you need to ensure that the modal page is protected. On that page, create a Before Header process that validates the value of P3_ITEM_NAME. If the user isn't supposed to be able to access those values, then throw an exception.
这篇关于APEX行选择器第2部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!