Af:clientListener and javascript confirm() dialog

Hi,
a common requirement in most of our web apps is to include a warning dialog when a user tries to delete a record, ie. if someone presses on a link to delete a record they get a javascript dialog asking them "Are you sure you want to delete this record?'. Clicking ok will delete the record, while clicking cancel will cancel the action. Our jsp code from jdev 10.1.3 is shown below:
<af:commandLink actionListener="#{bindings.removeRowWithKey.execute}"
          action="#{viewCalStatus.deleteCalStatus}" text="Delete"
                onclick="return confirm('Are you sure you want to delete this record?');">
    <af:setActionListener from="#{row.rowKeyStr}" to="#{requestScope.calStatusRow}"/>
</af:commandLink>We have noticed that in 11G <af:commandLink> no longer supports any javascript events such as onClick. The suggested replacement is to use <af:clientListener>, however, it doesn't look like the same functionality can be achieved. We tried the code below, however, when the delete link is pressed, the record is submitted for deletion before the javascript dialog shows up (which we kind of expected anyway). Is there any way of achieving the same javascript functionality using <af:clientListener>? If not, what is the suggested 'best practice' for achieving similar functionality?
<script language="JavaScript" type="text/javascript">
    function confirmDelete() {
        if (confirm('Are you sure you want to delete this record?'))
            return true;
     else
            return false;
</script>
<af:commandLink actionListener="#{bindings.removeRowWithKey.execute}"
          action="#{viewCalStatus.deleteCalStatus}" text="Delete">
    <af:clientListener method="confirmDelete" type="click"/>
    <af:setActionListener from="#{row.rowKeyStr}" to="#{requestScope.calStatusRow}"/>
</af:commandLink>Thanks,
Michael.

Hi Michael
Hello from sunny Perth.
I suspect (but don't quote me) what you're looking for is described in the entire section "3.9 Sending Custom Events From the Client to the Server" in the new Web User Interface Developer's Guide for ADF, available online with JDev 11g TP2.
I've had some limited success testing this approach, to get a commandLink to call a client side JavaScript, display a message, and when the user clicks Ok, a server side backing bean method is called to do the rest of your work. It seems to work sometimes and not others, so I'm playing around with the config.
As for "best practice," it's a little early to start asking this of a preview release isn't it? ;)
Happy JDevelopering in Geelong.
Regards,
CM.

Similar Messages

  • How to add a title to a JavaScript Confirm dialog box.

    function confirmDelete() {
    var msg = "Do you want to continue removing the items ?";
    return confirm(msg);
    Presently it says http://locahost:8080/says etc on the title bar for the dialog box. Instead I want to set the title as "Confirm Delete". How can I do this?

    You're talking about the document title as you set it in the HTML head? Just alter the title of the document accordingly in the same Javascript function.
    If you find Javascript hard, there's a nice tutorial at w3schools.com. And for Javascript related questions better use a forum devoted to Javascript. There are ones at webdeveloper.com and dynamicdrive.com.

  • JavaScript Confirmation Dialog on Button

    Hi all,
    I have a Back Button which triggers the following JavaScript Function:
    <script language="javascript">
    function backConfirm() {
         msg = "<%=res.getString("BACK.CONFIRM")%>";
         return confirm(msg);
    </script>
    The function gets called in my Back button using:
    <hbj:button
         id="button_back"
         onClick="onBackButtonClicked"
         onClientClick="backConfirm()"
         width="100"
         design="EMPHASIZED">
         <%
         button_back.setText(res.getString("BUTTON.BACK"));
         button_back.setTooltip(res.getString("BUTTON.BACK.TOOLTIP"));
         %>
    </hbj:button>
    Now, the problem is that
    onBackButtonClicked
    is always called, regardless of the button clicked in the confirmation message.
    How can I solve this?
    Kind regards,
    Francisco

    You need to use the cancelSubmit method to prevent the onClick method from being invoked.
    From the button documentation.
    onClientClick    
    Defines the JavaScript fragment that is executed when the user clicks on the button. If both events ('onClick' and 'onClientClick') are specified, the 'onClientClick' event handling method is activated first. By default the 'onClick' event handling method is activated afterwards. In the JavaScript fragment you can cancel the activation of the 'onClick' event handling method with the command
    htmlbevent.cancelSubmit=true;
    The 'onClientClick' event is useful to pre process the form and only send the form to client if the preprocessing was successful (for example, date validation, valid number format etc.) to save client/server interaction.

  • Confirm Dialog (JavaScript)

    Hi,
    I'm using the JavaScript confirm dialog attached to a button (return confirm('xxxxxxxxxxxxxxx').
    It works fine but I need two things:
    1. How can I change the window title?
    2. How can I change the titles of the two buttons? (I need them in Spanish).
    Thanks a lot for your help

    Hi!
    As far as I know, there is no possibility to change title of standard dialogs like alert, confirm etc. You can use window JavaScript object and set title in it's parameter name.
    And since JavaScript is realized in browser, it seems that change of your locale should change button's title to language of locale.
    Thanks,
    Roman.

  • Javascript  Confirm Based on server time!!

    Hello Everybody,
    I want to raise a javascript confirm dialog box based on the server time. On button click, I want to raise the following code if the time is between 11 am to 24pm.
    E.g.
    IF l_time BETWEEN '11:00' AND '24:00' THEN
    htp.p('<script>');
    htp.p('var r=confir("Do you want to proceed?");
    htp.p('........so on');
    htp.p('</script>');
    ELSE
    -- just submit the page
    END IF;
    Any help will be appreciated!!
    Thanks,
    Parveen

    Hi,
    a.Always mention the Apex version, in every post.
    b. Always enclose your code in a pair of tags to make is more readable.
    Javascript can read the local machine time. If you want to access the server time you will need to use PL/SQL or SQL for that and pass that to the javascript function.
    Any specific reason why you are generating the JS through PL/SQL? Its so much easier to decalre the function in the Page HTML Header rather than doing htp.p.
    Regards,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Mail 2.0.5: Can the confirmation dialog on "Erase Junk Mail" be turned off?

    Subject says it all, really. Does anyone know of a way to turn off the confirmation dialog when you Erase Junk Mail in Mail 2.0.5? Maybe some config file I can manually edit or something...?

    I'm not sure about a config file that can be manually edited but you can select automatically erase messages in an account's Junk mailbox which is available under the Mailbox Behaviors tab for the preferences for each account and no confirmation dialog will be provided.
    The confirmation dialog is only provided when doing a manual Erase Junk Mail.

  • Javascript Confirm popup Yes, No button instead of OK and Cancel?

    Hi,
    I wrote javascript for confirm popup like below:
    var answer = confirm ("Are you sure you want to delete this item ?");
    It is showing OK Cancel button popup , but I want to display Yes No buttons on popup insted of OK Cancel buttons...
    Appreciate if anyone give proper solution.
    Thank you.
    Still I could not get proper solution.... Please any one help me solve this... need js solution not jquery..

    Hi Praveen
    There is not direct option in JavaScript to get Yes/No buttons in a Confirm dialog.
    But, we can create a customized dialog box with our own HTML tags, controls and scripts and show it as a confirmation dialog using
    window.showModalDialog() function
    Here is the sample HTML to demonstrate how to create a customized confirmation dialog.
    Dialog.HTML (This contains the UI for the confirmation dialog. Message, Yes No buttons etc)
    <!DOCTYPE>
    <html>
    <head>
    <title>Confirmation Message</title>
    <script language="javascript" type="text/javascript">
    window.onload = function()
    var messageDiv = document.getElementById('dlgMessage');
    if ( messageDiv != null && typeof(messageDiv) != "undefined" )
    messageDiv.innerHTML = window.dialogArguments;
    function confirmClick(args)
    window.returnValue = args;
    window.close();
    </script>
    </head>
    <body>
    <div id="dlgMessage">
    </div>
    <input type="button" value="Yes" id="btnYes" onclick="javascript:confirmClick('yes')"/>
    <input type="button" value="No" id="btnNo" onclick="javascript:confirmClick('no');"/>
    </body>
    </html>
    MainPage.HTML (From where the confirmation dialog will be shown. In your case, u can use the script in this html and customize it according to ur needs)
    <!DOCTYPE>
    <html>
    <head>
    <title>Main Page</title>
    <script language="javascript" type="text/javascript">
    function showConfirmDlg(message)
    var returnValue = window.showModalDialog("dialog.html",message,"dialogHeight:150px;dialogWidth:200px");
    if ( returnValue == 'yes' )
    alert('Yes button is clicked in the dialog');
    else
    alert('No button is clicked in the dialog');
    </script>
    </head>
    <body>
    <input id="btnConfirm" type="button" value="Confirm" onclick="javascript:showConfirmDlg('Do you want to continue?');" />
    </body>
    </html>
    Hope this helps.
    See this MSDN Link for more information on how to use and customize the showModalDialog() function
    http://msdn.microsoft.com/en-us/library/ie/ms536759(v=vs.85).aspx

  • Confirmation Dialog when clicking on Tree Node.

    I am working on Oracle Apex 4.2.0.00.27 and I have the following problem:
    The code below shows the definition of a tree. The tree displays records from the table ACTIVITIES in hierarchical structure.
    When user clicks on a leaf/node of the tree he will be redirected to another page where the details of each Activity/leaf/node are displayed.
    The tree is part of a page where I have established a functionality to check for changes on the input fields of the page and inform the user when he tries to redirect without first saving the changes he made.
    What I want to do is:
    WHEN user clicks on a node of the tree AND he hasn't saved any changes he made
    THEN
    trigger a confirmation dialog.
    IF
    he clicks OK he is redirected to the node details page as defined on the tree definition:
    f?p=&APP_ID.:10:'||:APP_SESSION||'::::P10_ID:'||"ID"
    ELSE if he clicks CANCEL
    he stays on the same page.
    The condition to trigger the confirmation box is:
    if (document.getElementById('P0_CHANGES_DETECTED').value == 1)
    where P0_CHANGES_DETECTED is a universal hidden text field that is set to +'1'+ every time a change is made.
    and here is the tree definition:
    select case when connect_by_isleaf = 1 then 0
    when level = 1             then 1
    else                           -1
    end as status,
    level,
    +"NAME" as title,+
    null as icon,
    +"ID" as value,+
    null as tooltip,
    decode(PARENT_ID,null,null, 'f?p=&APP_ID.:10:'||:APP_SESSION||'::::P10_ID:'||"ID") as link
    from "#OWNER#"."ACTIVITIES"
    where GROUP_ID = :P20_GROUP_ID
    start with "ID" in (select ID from "#OWNER#"."ACTIVITIES" where GROUP_ID = :P20_GROUP_ID and PARENT_ID is null)
    connect by prior "ID" = "PARENT_ID"
    order siblings by "ID"
    I hope it is clear what I want to achieve. Thanks in advance.

    So you'll want to bind an event to all tree nodes that checks for the value and then fires the confirmation if there value is 1.
    Try something like this:
    - first, give your static ID attribute in your tree the value of tree_static_id (or whatever you want. just replace the id selector below with what you choose).
    - In your Page Function and Variable Declaration Javascript:
    function confirmSave() {
    var changeDetected = jQuery('#P0_CHANGES_DETECTED').val();
    if(changeDetected == 1) {
    //only do this if change is detected
    if(confirm('You have unsaved changes. Do you want to leave this page?')) {
    window.location('[your url here]');
    jQuery(document).ready(function() {
    //bind function to the click event
    $('#tree_static_id').find('li a').bind('click', function() { confirmSave(); } });
    });Hope this helps

  • JavaScript Confirm Pop Up

    I am calling a JavaScript function from a dropdownlistbox onClientSelect attribute. The javascript function dispalys a confirmation pop up with OK and CANCEL buttons. When the user hits OK, the JS function issues htmlbevent.cancelSubmit = false and I continue with serverside processing. However, when the user hits CANCEL, I still need to continue with serverside processing and change the dropdownlist box value back to previous value. Is there a way that I can capture users response from the confirmation pop up in javascript and return it for serverside processing. Thanks.

    on both user action OK or CANCLE you want server action but you want to differentiate whether the user clicked ok or cancle (to carry out different server action)
    to achive this have a hidden form field. and set the value to OK or cancel based on waht user selected in confirm dialog .
    the js code would look somethig like below.
    var Check = false; Check = confirm('k1?');if(Check == false){ document.myform.hiddenformfield.value="false";htmlbevent.cancelSubmit = true; }
    now you can read the hidden form field in oninputprocessing and based on the value you can do further processing.
    Regards
    Raja

  • Display confirmation dialog when opening PDF

    I've been asked to add a confirmation dialog box to a PDF file that includes a legal disclaimer. The dialogue box would display when opening the pdf document and include yes and no buttons to confirm that the user understands and accepts the disclaimer before reading the document. Selecting "Yes" would allow them to proceed, while selecting "No" would close the file. Is it possible to create something like this in Acrobat? I'm running Acrobat Standard 8.
    Thanks,
    Eric

    Hi Eric,
    Yes, you can do that but it's not an easy task.  You need to code the dialog in JavaScript and then use OCGs (layers) for a cover sheet that will remain "on" until the user selects the Yes button in the dialog.  Coding the dialog is a major task to do by hand and I'm not sure if Acrobat 8 Standard has the OCG capability.
    Check out our tool AcroDialogs(http://www.windjack.com/products/acrodialogs.html) for making dialog creation about 100 times faster and easier, and there is an example of a license dialog agreement just like what you are asking for on that page- scroll down to the Document License Dialog Example. But again, that solution was developed with Acrobat Professional and I'm not sure if Standard handles OCGs or not- you'll have to check on that.
    Also keep in mind this is by no means a foolproof security methodology.  However, it does provide a way to ensure the user agreed to the dialog before viewing the rest of the content.
    Hope this helps,
    Dimitri
    WindJack Solutions
    www.windjack.com
    www.pdfscripting.com

  • Poping Up a Confirmation Dialog

    I would like to popup a confirmation dialog when a user clicks a 'cancel' button in my page. If the user clicks 'NO' in the dialog, data is not cleared and navigation is canceled.
    I tried this ...
    public String cancelBtn_action() {
            int i = JOptionPane.showConfirmDialog
                        (null, "Do you really want to clear all data and start over?",
                            "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
            if(i == JOptionPane.YES_OPTION) {
                getSessionBean1().clearBeans();
                return "clear";
            else return "null";
        }... but the dialog is hidden behind all the open windows on my machine (b/c the 'null' argument in showConfrimDialog, I guess).
    Can I attach this dialog to the page somehow (so it does not get hidden)? Should I even use Swing? Is there a prefered way to use popup dialogs in JSF/Creator?
    Any information would be much appreciated.

    Thank you for your reply.
    Pardon any redundancy, but to be sure that I am making myself clear and that I am understanding your response...
    At first 'cancel_action()' ( event handler in the page bean) looked like this:
    public String cancelBtn_action() {
           getSessionBean1().clearBeans();
           return "cancel";
    }To make this code conditional I next tried this:
    public String cancelBtn_action() {
            int i = JOptionPane.showConfirmDialog
                        (null, "Do you really want to clear all data and start over?",
                            "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
            if(i == JOptionPane.YES_OPTION) {
                getSessionBean1().clearBeans();
                return "cancel";
            else return "null";
    }This code works 'fine', except that the dialog gets displayed behind all open windows where the user can not see it. (If there is a way to tie the dialog to the browser frame so it does not get buried (maybe there is?), this would allow all the JOptionPane stuff to be leveraged nicely with JSF).
    Since you are not modifying any data based on the
    response received from confirmation dailogclearBeans() clears data previously entered in several session-scoped beans (so data is (conditionaly) modifed). "cancel" and "null" are different navigation cases
    I would suggest to use javascript based dialogs. I like the simplicity of using javascript, but I need to set a flag (or something similar) in my page bean to conditionaly control navigation and whether to clear data stored in the session beans. This seems to require that the javascript calls a method in the page bean. Can this be done with JSF?
    >
    You can also use another jsp page in a popup as
    confirmation dialog by specifying the size of the new
    page.
    So I guess you mean a non-JSF JSP page? Since I need to finish executing the code in the event handler that was interupted by the confirmation dialog, I think that JSF navigation/lifecycle issues would be a problem. Am I correct?
    Again pardon any redundancy.
    More details on either (or any other) approach would be helpful.

  • Submiting JSF form on clicking ok of Confirm dialog box

    Hi,
    We are using JSF 1.2 and Seam 2 in our project.
    We have set of requirements
    1)To throw a confirmation dialog box when user tries to navigate away from page with out saving the data changes. It includes browser closure, back button and refresh as well along with other application navigation links.
    2) upon clicking ok we need to save the current JSF form and redirect to where user is intended to navigate.
    Please let me know the best ways of implementing the above requirements.

    For the first point, I totally agree with Raymond and you can use the javascript function like this:
    <script>
    window.onbeforeunload =
    function(){
    if((window.event.clientX<0) || (window.event.clientY<0)){
    //create new confirm window here
    //I guess you can check on opening a new JSF page itself as a pop up.
    //in that page with normal form and submit buttons, I guess you can call JSF action methods.
    </script>

  • Confirm Dialog?

    As a flex newbie with a pretty good understanding of
    Javascript, I was thrilled to find the Alert.show() function
    available to replace the alert() function I often used in
    Javascript. That got me wondering... is there a corresponding
    function for the confirm() function as well? I tried
    Confirm.show(), but with no luck, as that shows up as an undefined
    property.
    I was hoping there's a simple way to activate modal
    confirmation dialogs, as I'd hate to have to build an entire
    component just for that.
    Thanks,
    Josh

    Well, there is an relative simply solution for this:
    Make a button with calls a function when clicking:
    <mx:Button label="Click Me"
    click="clickHandler(event);"/>
    Use the following implementation of the eventhandler:
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert;
    import mx.events.CloseEvent;
    // Event handler function uses a static method to show
    // a pop-up window with the title, message, and requested
    buttons.
    private function clickHandler(event:Event):void {
    Alert.show("Do you want to save your changes?", "Save
    Changes", 3, this, alertClickHandler);
    // Event handler function for displaying the selected Alert
    button.
    private function alertClickHandler(event:CloseEvent):void {
    if (event.detail==Alert.YES)
    status.text="You answered Yes";
    else
    status.text="You answered No";
    ]]>
    </mx:Script>

  • Conditional confirm dialog with button

    Hi all,
    I want to create a confirm dialog with submit button that can fire only if one item is not submitted in that page.
    i have one check box item in my page called P2_LWF
    i created confirm dialog with button using the below code
    javascript:if (confirm('Are you sure you want to proceed?')) {
    this.disabled=true; this.value='Submitted...';
    doSubmit('SUBMIT');
    The moment i click submit button i want to fire that confirm dialog only if P2_LWF is unchecked.
    How can i do that in my application?
    Regards,
    Anees

    Hi marko,
    find application link below
    http://apex.oracle.com/pls/apex/f?p=14972:1:25026364614886:::::
    user name: [email protected]
    pswd: symphony
    you can access my work space using below credentials
    http://apex.oracle.com/pls/apex/f?p=4550:1:0:::::
    workspace : aneesmohd
    username : [email protected]
    paswd: symphony
    application name: Confirmation Dialog
    application id= 14972
    when i press submit button i can get the confirmation dialog,but i want to make that as conditional (only when dl and lwf checkboxes are not ticked).if those are ticked i want to submit without getting the confirmation dialog.
    and want to clear the employee region cashe(report region) ones submit button pressed or refresh the page.
    Regards,
    Anees
    Edited by: anees_mohd on Jan 16, 2013 3:25 AM

  • Confirmation dialog box in JSf

    Hi,
    I have a Save (type 'Submit') button which onClick should give me a confirmation dialog box with Ok and Cancel.
    Ok would go ahead with the process and cancel would take me back to where the page was before the save button was clicked.
    Any help is really appreciated.
    Thanks.

    Hello,
    I hope you can invoke a javascript function when the user clicks on "Save" button (onClick event for save button). Specify window.confirm(....) inside your javascript function which will give you confirmation window. I am not well enough how you want to handle navigation in your page.

Maybe you are looking for

  • Was unable to load data class info from sync services.  try again later.

    Since installing the latest version of itunes (11.1.5.5) whenever I have either mine or my wife's iphones (4 and 5c, both with the latest 7.1.1) turned on and I start iTunes, I receive the error message saying that itunes was unable to load data clas

  • Extended mode with MacbookPro using Dual Screen Wallpaper

    Hello, guy's, I already have a Macbook Pro 13" connected on ACD24". I use the both of monitors in extended mode. That i want to ask you is the seguent.. Can i use one dual wallpaper? I mean that i want

  • Movies are dark

    Recently purchased Apple TV - downloaded 3 movies from itunes, found all to be unusually dark compared to the original DVD. Using component input to 1080i widescreen, just swapped out the Sony DVD player for the Apple TV - DVD player looks fine throu

  • Installing windows XP on Portege R600

    I have a pre-installed XP downgrade disk, but I'd really like to install a fresh windows XP instead. So I insert a winXP disk, and install. (a) Installing straight at boot doesn't work: it claims that I have no hard disks! See here: http://www.proble

  • How do I open/print/save. a pdf dxweb file?

    When I download documents fom the web they come through as a pdf dxweb file that will not open using Adobe Acrobat XI, print, or transfer to a disc.  What am I doing wrong?