Onclick javascript confirm for commandlinks

Pre JSF 1.2, there was no onclick for commandLinks. Below is some javascript I wrote to dynamically pre-pend a confirm javascript call before the onclick submit event is called. I use this so that my delete links in my application pop up confirm dialogs before actually doing the submit. (I am unable to upgrade to JSF 1.2) I hope this helps someone else experiencing the same problem.
Comments and suggestions are always welcome!
You need to wrap your commandLink components with some kind of tag:
Example: <span name="deleteButton" confirm="#{itemTitle}"><commandLink... /></span>
Also, you need to add pageConfirmLoader as a function to be executed on window load.
var ConfirmLoader = {
     init : function(tag, tagName) {
          this.tag = tag;
          this.tagName = tagName;
     load : function() {
         if(this.tag != null && this.tagName != null) {
               var spans = document.getElementsByTagName(this.tag);
               var spansLength = spans.length;
               var confirmHelper = {
                    functs: [ ],
                    descs: [ ],
                    confirmDelete: function(event) {
                         var loc = event.target.parentNode.parentNode.id;
                         var confirmText = "Are you sure you want to delete this item?";
                         if(this.descs[loc] != null) {
                              confirmText = "Are you sure you want to delete '" + this.descs[loc] + "' ?"
                         if(confirm(confirmText) ) {
                              eval(this.functs[loc](event));
               for (i = 0; i < spansLength; i++) {
                    if (spans.getAttribute('name') == this.tagName) {
                         confirmHelper.functs[spans[i].id] = spans[i].childNodes[0].onclick;
                         confirmHelper.descs[spans[i].id] = spans[i].getAttribute('confirm');
                         spans[i].childNodes[0].onclick = function(event){ confirmHelper.confirmDelete(event); };
function pageConfirmLoader() {
     ConfirmLoader.load();
ConfirmLoader.init('span', 'deleteButton');

I have one missed attribute: the wrapping span tag also needs some kind of id assigned to it, so the javascript ConfirmLoader can insert the values into the correct locations.
<span name="deleteButton" confirm="#{itemTitle}" id="#{iter.nextId}" ><commandLink... /></span>

Similar Messages

  • CommandLink onclick JavaScript

    How to add onclick JavaScript to commandLink ?
    Why commandButton has onclick method, but commandLink hasn't ?

    When you use <h:commandLink>, the JSF implementation must write the "onclick" event handler so that the form it belongs to is submitted with enough info to tell which link was clicked. If you could add your own code for "onclick", it could potentially disable the main functionality of the <h:commandLink>. Use <h:outputLink> instead if you want to override the "onclick" behavior.

  • How to Add A Javascript Confirm() on an Apex button for a form?

    Hi, how can I add a Javascript confirm() to a button in Apex for a form? Thanks.

    Hello:
    You could do the following
    1)In the 'Option URL Redirect' section of the Edit Button page set 'Target is a ' to 'URL'
    2)For URL Target enter javascript:{if (confirm('Your Question here')) doSubmit('<button name>');}Varad
    Edited by: varad acharya on Jul 15, 2009 3:47 PM

  • 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.

  • Problem with javascript confirm() in a JSP

    I'm trying to use a confirm() box in a jsp. I've looked at tons of examples and I still have the same problem. If I just add this to my page the prompt will pop up as expected: (of course it doesn't really do anything.)<SCRIPT LANGUAGE="JavaScript">
    confirm( "Are you sure you want to delete?" )
    </SCRIPT>As soon as I add an if clause around it it doesn't even pop up anymore, such as:if (confirm("Are you sure you want to delete?")){
    <%
         Do some jsp stuff
    %>
    else {
    <%
         Do some jsp stuff
    %>
    }I can include more of the code if needed. This code is for deleting some files, so I want to add an "are you sure prompt?". If they hit ok it will delete, otherwise cancel the operation.
    I assume that the "if confirm( "Are you sure you want to delete?" ) " should wait for a reponse before continuing. Any help is appreciated.
    Thanks,
    James

    You can use Javascript to confirm a delete, and delete an object in the following manner.
    //link to delete an object..
    <a href="thisPage.jsp?delete=<%= itemID %>"
       onClick="return confirm('Are you sure you wish to delete this item?');">delete</a>Then, at the top of the JSP pageif(request.getParameter("delete") != null)
       //do whatever to delete, then load the page as normal
    }Now, your item will be deleted, and the page will be refreshed to show the changes.

  • 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

  • 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,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to use JavaScript in Dynamic commandLink

    Hi All,
    In my JSF application, I am able to get the dynamic CommandLink with the below mentioned code.
    commandLink.setActionExpression(createActionExpression("#{myBean.myMethod}", String.class));
    The above code is navigating to the page mypage.jsp properly (the page which is returned by method myMethod).
    My Question is: Instead of navigation (as mentioned above) I want to generate a popup window using JavaScript on click of commandLink.
    Please suggest me on how to proceed on this?

    Hers is my JavaScript:
    function showPopupWindow(action) {
    formId=action.form.id;
    //features="height=300,width=250,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";
    features="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=900,height=500,top=80,left=80";
    winId=window.open('Mypage.faces','list',features); // open search window
    winId.focus();
    This works perfectly with the onclick attribute of the commandbutton as shown below:
    <h:commandButton value="Open Popup" onclick="showPopupWindow(this); return false;"></h:commandButton>
    {color:#ff0000}
    But I tried same thing with the onclick attribute of the commandLink, that did not work.
    <h:commandLink value="Open Popup" onclick="showPopupWindow(this); return false;"></h:commandLink>
    {color:#0000ff}As per my requirement, I tried using setOnclick attribute in the following manner, that failed to open the popup:
    commandLink.setOnclick("{color}{color}*{color:#0000ff}showPopupWindow(this); return false;{color}*{color:#ff0000}*{color:#0000ff}");{color}*
    {color}

  • Javascript Confirm box dependent on results of query

    Hi
    I'm using Apex version 3.2.1 and I'm looking for a way to do the following, any help much appreciated:
    A javascript confirm box will appear when the user submits a page if the result of a query returns anything, the query would look something like this....
    SELECT * FROM LINKEDPROJECTS
    WHERE ENV_ID = :P18_ENV_ID
    AND COMP_ID = :P18_COMP_ID
    AND DATE_FROM <= to_date(:P18_DATE_TO, 'DD-MON-YY')
    AND DATE_TO >= to_date(:P18_DATE_FROM, 'DD-MON-YY')
    If it doesnt return any data the page will submit as normal, if it does return any data the confirm box will appear, and the message will also be driven by the result of a query.
    So the message would be something like....
    Project(s) +"Select NAME FROM PROJECTS WHERE ID IN (SELECT PROJ_ID FROM LINKEDPROJECTS WHERE ENV_ID = :P18_ENV_ID+
    +AND COMP_ID = :P18_COMP_ID+
    +AND DATE_FROM <= to_date(:P18_DATE_TO, 'DD-MON-YY')+
    +AND DATE_TO >= to_date(:P18_DATE_FROM, 'DD-MON-YY')"+ have this environment booked on the dates you selected.  Do you want to continue with the booking?
    Selecting yes submits the page, selecting no returns them to the page.

    In a nutshell (and some pseudo code):
    The button URL would look something like "javascript:beforeSubmit()" without quotes and where beforeSubmit is the name of your function.
    The function would look something like:
    function beforeSubmit() {
      var runQuery = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=RunTheQuery',1);
      var result = runQuery.get();
      if (result = 0) {
        if (!apex.confirm('Submit page?")
          return;
      doSubmit('SUBMIT');
    {code}
    The application process, called "RunTheQuery" in this example, is a PL/SQL block that runs the query and return the value using the htp.prn function.
    There are probably errors in the above as I just did this off the top of my head, and you will probably need to tweak it somewhat.  But hopefully you get the idea.
    Mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Javascript Confirm Redirect

    I am looking to figure out how to do a javascript confirm
    Redirect popup. Can anyone help me out with that? Is there a
    Dreamweaver behavior for that?

    I'm not sure exactly what you mean, but it's easy enough to
    make a popup (to
    open a second sized browser window) by using DW's Open
    Browser Window
    behavior.
    Patty Ayers | www.WebDevBiz.com
    Free Articles on the Business of Web Development
    Web Design Contract, Estimate Request Form, Estimate
    Worksheet
    "joey_a" <[email protected]> wrote in
    message
    news:edbo7j$iea$[email protected]..
    >I am looking to figure out how to do a javascript confirm
    Redirect popup.
    >Can anyone help me out with that? Is there a Dreamweaver
    behavior for that?

  • Javascript confirm alert Can we change the text ok

    can we change the ok and cancel text in the javascript confirm alert. pls respond, its very ungent
    Edited by: Bini John on Jun 10, 2009 9:19 AM

    Hi,
    Yes if client want new description for the PS Group, you have to create new only and assign the wage types to them and so on..... you have to do all the configurations regarding the PS Group. Here the main point is be careful with the start date of the PS Group for newly created records and assignments.
    Best Regards.

  • Onclick javascript throws addtional characters

    HI,
    I tried below
    In column properties>>data format>>custom text format
    [html] {span class=\"Nav\" onClick=\"javascript:PortalPageNav(event,'/shared/report/DASHBOARD','page 1','Param PL','"Pl Line"','@')\">@ {SPAN>
    </span>
    when i try to export report in excel i can find addtional special characters-@ ';">
    my result comes like this
    @ ';">name1
    @ ';">name2
    can i know what is wrong in above code                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    but when I click the add button on a particular item all 3 of the
    items are added to my shopping list. Can anyone tell me why? and if so how > > can I resolve this problem?I don't think that clicking the button is what is causing your problem. The following line of code is the problem:
    <td><a href="#"><img src="images/add.gif" width="47" height="19"
    border="0" name="addButton<%=product.getItemId()%>" id="<%=product.getItemId()%>"
    onMouseOver="MM_swapImage('addButton<%=product.getItemId()%>','','images/add_hover.gif',1)"
    onMouseOut="MM_swapImgRestore()"
    onclick="<%/*addNewItem(product.getItemId());*/ list.addItem(new Integer (product.getItemId()));%>
    window.parent.location.reload(false);"></a></td> When you are trying to create the onClick, you are invoking list.addItem. You are doing this for each item. By the way, I don't think the resulting onClick will actually do anything. It will evaluate to the item id and nothing will happen. You need to trigger a request to the server here (e.g. by submitting a form and including the correct item id).

  • Navigation Bar OnClick JavaScript Problem

    I tried to create a Navigation Bar to pop up a online help documentation. The sample application can be seen at
    http://apex.oracle.com/pls/otn/f?p=27294:1
    When I debugged the application, I found that the link of Help Navigation Bar points to "http://apex.oracle.com/pls/otn/f?p=27294:#:432121301146634::NO:::"
    not as what I defined on OnClick JavaScript for the navigation bar. The Help Window won't pop up.
    Please help. Thanks.

    Have a look at the following post:
    how to create a popup help page in html db

  • OnClick javascript.

    L.S.
    I implemented a master-detail relationship in my app using the following lines of code in the onClick Javascript property of a hyperlink in a table:
    window.open(�/Fitwise/faces/OnderneminDetails.jsp?idBedrijf=#{currentRow.value[�bedrijf.idBedrijf�]}�, �_blank�, �height=432, resizable=yes, scrollbars=yes, toolbar=yes, width=576�); return false;
    This works fine. In the details page I get the idBedrijf from the parameter and set it as the value of a private property idBedrijf with its own getter and setter methods.
    Now I would like to open another window when the user clicks an ImageHyperlink in the detailspage. For this to work properly I have to transfer the idBedrijf to that page. I used the following lines of code in the onClick Javascript property of the ImageHyperlink:
    window.open(�/Fitwise/faces/ODLesrooster.jsp?idBedrijf=#{getIdBedrijf()]}�, �_blank�, �height=600, resizable=yes, scrollbars=yes, toolbar=yes, width=800�); return false;
    This does not work. I suppose it is the getIdBedrijf() bit of code that is wrong, what do I have to replace it with to get the onClick thing working.
    Thanks,
    Annet.

    Thanks for your reply yossarian,
    I replaced the Image Hyperlink with a Hyperlink and got the code working. However I cannot figure out why it does not work when I use an Image Hyperlink. I replaced the code with the simple window.close(); return false; bit of code,of which I am sure it works fine with a Hyperlink, but when I run the project, clicking on the Image Hyperlink does not have any effect at all. I did use an Image Hyperlink with an action event on another occassion, but, since I would like to open a new window, I would rather use the onClick javascript option to implement this behaviour.
    Any ideas what the problem is?
    Thanks,
    Annet.

  • Automatic TO creation and confirmation for a Material document

    Hi Dear All,
    i am new to MM andWM.
    I have to customization for auto transfer orders and confirmations for material documents what ever created with 101 movement type in Inventory Management. I have down configuration like below.
    SPRO->Logistics Execution->Warehouse Management->Activities->Transfers-> Set Up Autom. TO Creation for TRs / Posting Change Notices
    Double click on ‘control data ‘tab
    Hear for my warehouse I given input like   Auto TO = ‘1’,
                                                                             AddId = ‘select check box’.
    And in ‘Assign control’ tab for 101 movement type I have given input like below.
    Automatic TO = ‘1’.
    TO item can be confirmed immed. = ‘tick checkbox’
    Propose Confirmation = ‘tick checkbox’.
    Foreground/Backgrnd = ‘D’.
    After creating of Material document I am executing report RLAUTA10 in SE38.When I execute this report system showing message like ‘TO processing finished: TR total:   17, TO created:    0, Errors:   17’.
    If I check header details of transfer requirements in LB03, i am not seeing ‘Tick Mark’ in Auto TO Creation field.
    Can any one tell me what the mistake i have down or if i need to do any further configuration. Please help me regarding this concern?
    Thanks in Advance..

    Dear Steve,
    Thanks a lot for giving reply with what I need to do, but I am unable to see result.
    I have down configuration like below even though system not processing Auto TO creation. Can you explain me if I have down any mistake below.
    Click on ‘Assign’ button,
    Press on ‘New entries’
    WhN = ‘900’
    Reference Movement Type = ‘101’
    Movement indicator = ‘B’
    Movement type for Whse Mgmt = ‘101’
    TR create Transfer Requirement = ‘X’
    Immed.TO Creation
    Mail confirmation for background processing = ‘01’.
    GR date = ‘2’

Maybe you are looking for

  • Replacing the MacBook Pro Power Adapter Port

    There's a short in the adapter port. I have to keep the cord sitting just perfectly to make sure it's running off the adapter or off the battery. The battery has needed to be replaced for a while so when the adapter shorts and it switches to battery

  • HT4009 How do I cancel in apps purchasing for yearly suscription which I did intend to?

    I recently downloaded TripIt. When I tried to figure out the things accidently click on a link and take me to purchase the service with no price displayed. I thought it was free. It actually did purchase one year of TripIt Pro Services for $48.95. Ho

  • Button tregers twice

    hi... i have a button inside a movie clip.I want to open a site in a browser window when i clicks the button so i write the script inside the button .But when i click the button two windows are opening with the same url...[the movie clip has animatio

  • CS4 Bridge can't see CS3 Photoshop's ACR

    Hi all, I have been using CS3 PS + ACR happily for the last year.  Yesterday I downloaded the CS4 trial packs for Dreamweaver, Flash, etc, and installed them, along with CS4 Bridge. CS4 Bridge will send an image to CS3 PS but when I select "Open in C

  • MM06E005 enhancement

    hi, if anyone has displayed table control in item level tab for ME21n/2n/3n using enhancement MMO6E005 please send me some code sample as it is very urgent for me.  I tried but i can display the values only for simple fields but not in table control.