Generate 'Delete with Confirmation' in JHeadstart applications

3

JHeadstart is one of the tools we use quite successfully here at AMIS. We have written on this blog about JHeadstart and ways to extend, enhance and optimally benefit from JHeadstart many many times. And today is another moment for just such an article. The issue at hand: JHeadstart does not – unlike Oracle Forms for example – have the split between the data manipulation – for example delete record – and commit – save your changes or revert them. JHeadstart generates pages with big, luring DELETE buttons that allow users to delete records. However, once the button is pressed, there is no way back. There is no ‘Are you sure’ moment, there is no explicit, additional commit required. It’s press the big button and off you go.
 
In many cases, that is just fine. It can be incredibly irritating if your application keeps asking you ‘Are you sure? Are you really truly absolutely positively sure?’ Of course I am! I asked for it, didn’t I? However, some delete operations, especially those with far reaching cascade deletes in the background, may require a little additional caution. For those cases, you may want the user to actively confirm that they know what they are about to do and are sure that they really want to do it. This article describes a very simple method for generating that additional confirmation into JHeadstart applications.

 ....

 

The following are the steps for getting this Delete with Confirm implemented:

1. Create a JavaScript library MyUtils.js

2. Import this library in the pageConfig.jspx file

3. Create a new template DeleteWithConfirmButton.vm

4. Associate Groups in the Application Definition file with this template to achieve Delete With Confirm
 

Step 1 – Create a JavaScript library MyUtils.js

A simple JavaScript function is required to ask the "Are you sure" question and return the OK or Cancel result. We want to i18n-ize this question – i.e. make it locale specific. We create a new JavaScript library – MyUtils.js – that leverages the client side messages infrastructure available in JHeadstart:

addMessage(&quot;confirmDelete&quot;,&quot;en&quot;, &quot;Are you sure you want to delete this {0}?&quot;);<br />addMessage(&quot;confirmDelete&quot;,&quot;nl&quot;, &quot;Weet u zeker dat u dit {0} wilt verwijderen?&quot;);<br />          <br />function confirmDelete(objectLabel)<br />{<br />  var confirmed;<br />  confirmed = confirm(getMessage(&quot;confirmDelete&quot;,[objectLabel]));<br />  if (confirmed)<br />  {<br />    return true;<br />  }<br />  else<br />  {<br />    return false;<br />  }<br />}<br />     &nbsp;<br />

Of course you can add messages in your own language as well.

Step 2 – Import this library in the pageConfig.jspx file

The MyUtils.js library must be available all across the application. We can achieve that by linking it to the pageConfig.jspx page (in public_html\common\regions) that provides the basic outline for all pages in our application:

  &lt;afh:script source=&quot;/jheadstart/MyUtils.js&quot;/&gt;<br />&nbsp;

Step 3 – Create a new template DeleteWithConfirmButton.vm

In addition to the Delete button currently generated using the DeleteButton.vm template, we want another Delete button that includes the Confirm functionality. We create a template that provides that functionality, by copying the DeleteButton.vm template and making a small modification in the onclick attribute:

onclick=&quot;return confirmDelete('${JHS.current.group.displayTitleSingular}');&quot;&nbsp;

Step 4 – Associate Groups in the Application Definition file with this template to achieve Delete With Confirm

 

 

 

Share.

About Author

Lucas Jellema, active in IT (and with Oracle) since 1994. Oracle ACE Director for Fusion Middleware. Consultant, trainer and instructor on diverse areas including Oracle Database (SQL & PLSQL), Service Oriented Architecture, BPM, ADF, Java in various shapes and forms and many other things. Author of the Oracle Press book: Oracle SOA Suite 11g Handbook. Frequent presenter on conferences such as JavaOne, Oracle OpenWorld, ODTUG Kaleidoscope, Devoxx and OBUG. Presenter for Oracle University Celebrity specials.

3 Comments

  1. Aino Andriessen on

    A small addition : using ${JHS.current.group.displayTitleSingular} instead of the word Employee makes it a generic button.

  2. Aino Andriessen on

    You don’t need a new javascript function, but you can use the existing js confirm method. You can even nls-enable the message by using built-in JHeadstart nls generator functionality. All you do is to create a button specific template that is based on the standard JHeadstart deleteButton template and replace the onclick property, e.g. :

    onclick=”return confirm (‘${JHS.nls(“Delete Confirm”, “LABEL_CONFIRM_DELETE”, “Are you sure you want to delete the current Employee? Are you sure?” )}’);”