如何通过执行 JavaScript 代码添加将重定向到另一个页面的动态操作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28074001/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add a dynamic action that will redirect to another page by executing JavaScript Code?
提问by Kevin
I have buttons on my apex application that executes custom PL/SQL codes upon being clicked. They have names APPLY (Acknowledge) and CHANGE (Count Correct). I need to have it so that when APPLY is clicked, it redirects to the same page (with the PL/SQL code implemented) and when CHANGE is clicked, it redirects to another page (with PL/SQL code implemented).
我的 apex 应用程序上有按钮,可以在单击时执行自定义 PL/SQL 代码。它们有名称 APPLY(确认)和 CHANGE(计数正确)。我需要它,以便在单击 APPLY 时,它重定向到同一页面(实现了 PL/SQL 代码),当单击 CHANGE 时,它重定向到另一个页面(实现了 PL/SQL 代码)。
I tried setting a conditional branch for After Processing by way of "When Button is Pressed" and/or "Condition Type: Request = Expression 1" with the value of Expression 1 equaling "APPLY" or "CHANGE". I can't produce the results I am looking for (frustratingly) this way. APEX says that the submitted page Request takes on the name button that is clicked (i.e APPLY when APPLY is clicked) but I can not get that to happen.
我尝试通过“按下按钮时”和/或“条件类型:请求 = 表达式 1”为后处理设置条件分支,表达式 1 的值等于“应用”或“更改”。我无法以这种方式(令人沮丧地)产生我正在寻找的结果。APEX 表示提交的页面请求采用单击的名称按钮(即单击 APPLY 时应用),但我无法做到这一点。
I am now seeking to add a True Action to my Dynamic Actions for APPLY and CHANGE (which are currently "Execute PL/SQL Code" and "Submit Page" for each) which executes a Javascript Code redirecting to the desired page in the application.
我现在正在寻求为我的 APPLY 和 CHANGE 动态操作添加一个真正的操作(当前是“执行 PL/SQL 代码”和“提交页面”),它执行重定向到应用程序中所需页面的 Javascript 代码。
The code, i think, would utilize something like this
我认为代码会使用这样的东西
"apex.navigation.redirect('f?p=928:35:4081364075246::NO:::');"
page 35 is the page I'd like the CHANGE button to redirect to, in this case.
在这种情况下,第 35 页是我希望“更改”按钮重定向到的页面。
I'm not as versed in JavaScript as I'd like to be, so any help with my methodology on any of this would be appreciated.
我不像我希望的那样精通 JavaScript,因此对我的方法论的任何帮助将不胜感激。
回答by Kevin
I finally found out how to do this. The Request of the button (specifically the dynamic action of the button) was not set to the button name because the 'Request/Button Name' of the 'Submit Page' true action was not set to the name of the button.
我终于找到了如何做到这一点。按钮的请求(特别是按钮的动态动作)未设置为按钮名称,因为“提交页面”真实操作的“请求/按钮名称”未设置为按钮名称。
Make sure in the dynamic action to add this information under 'Settings'. The branch should be placed to 'Submit: before Processing' with the condition 'Request = Expression 1' with Expression 1 equaling the button name!
确保在动态操作中在“设置”下添加此信息。分支应置于“提交:处理之前”,条件为“请求 = 表达式 1”,表达式 1 等于按钮名称!
回答by WW Davos
In a recent project, I needed to do a page redirect once the user clicked the Save button on a model page. The button had a Dynamic action that included 3 separate actions:
在最近的一个项目中,我需要在用户单击模型页面上的“保存”按钮后进行页面重定向。该按钮有一个动态动作,包括 3 个单独的动作:
- Execute PL/SQL
- Submit Page
- Close Dialog
- 执行 PL/SQL
- 提交页面
- 关闭对话框
In between the Submit Pageand the Close Dialog, I added an Execute Javascriptaction that clicks a hidden button that I added to the page.
在Submit Page和之间Close Dialog,我添加了一个Execute Javascript点击我添加到页面的隐藏按钮的操作。
document.getElementById("BTN_ID").click();
The hidden button was set to redirect the user in Behavior-> Action-> Redirect to Page in Application, and the page #.
隐藏按钮设置为在Behavior-> Action-> Redirect to Page in Application和页面中重定向用户#。
I hid the button with #BTN_ID{visibility:hidden;}placed in the CSS Inline section of the page.
我将按钮隐藏#BTN_ID{visibility:hidden;}在页面的 CSS Inline 部分中。
This worked.
这奏效了。
回答by LG-C
Here's how I solved a similar situation: I wanted the DELETE button on page 2 to perform deletes on other tables, in addition to deleting the row displayed, and then return to page 1:
下面是我解决类似情况的方法:我希望第 2 页上的 DELETE 按钮对其他表执行删除,除了删除显示的行,然后返回到第 1 页:
- Deleted the existing DELETE button.
- Created new button with: Button Name=DELETE, Label=Delete, Action=Submit Page.
- Created an After Submit ProcessBranch with: Name=Delete and Return to Page 1, Execute Point=After Submit, Behavior Type=Page or URL, Target=Page 1, Advanced Request=DELETE, Server Side Condition=When Button Pressed=DELETE, Type=PL/SQL Function Body,
- 删除了现有的 DELETE 按钮。
- 创建新按钮:按钮名称=删除,标签=删除,操作=提交页面。
- 创建了一个After Submit 流程分支,其中: Name= Delete and Return to Page 1,Execute Point= After Submit,Behavior Type= Page or URL,Target= Page 1,Advanced Request= DELETE,Server Side Condition= When Button Pressed=DELETE,类型= PL/SQL 函数体,
then PL/SQL FUNCTION BODY:
然后 PL/SQL 函数体:
declare
宣布
lv_msg varchar2(2000) := null;
begin
pz_delete_related_records(:P2_KEY1, :P2_KEY2, lv_msg);
DELETE FROM BASE_TABLE
WHERE KEY1 = :P2_KEY1
AND KEY2 = :P2_KEY2;
RETURN TRUE;
end;

