Reader Challenge - Popup Applet "X" button

[Requirement]

"How to show alert to user after closing a Pick Applet from the "X" button [top right corner]. I want to show the alert or confirm(yes/no) box just after closing the pickapplet.

I tried using the window.onunload event in browser script of pickapplet, but it didn't worked.

please help"

Source: Oracle Forums
Link: http://forums.oracle.com/forums/thread.jspa?threadID=924827&tstart=195

[Challenge]

To clarify, the developer wants to display a confirmation dialog after the applet has been closed, and not to prevent the applet from being closed.

There are a few solutions that come to mind.

1. Put some code on the applet that invokes the popup applet, when focus returns to the first applet, pop up the dialog.

This is ugly because you need to put code on all the base applets across the application that use this popup applet.

2. OnLoad of the pop up applet, create a looping mechanism to check the name of the active applet, when the active applet is no longer the active popup applet, pop up the dialog.

This solution dosnt provide a real time notification, and creates un-neccessary load on the application and browser.

So your challenge is to find an alternative solution, which should be pretty tough ruling out the above possibilities.

To test the water, I seeked opinion from Michael Feng, of scriptless VBC fame, who initially dismissed it as impossible, but when I said, there is a solution.

He came up with a concept and a working solution in a few days. His solution allowed an alert to be displayed in REAL TIME when the X was clicked on a popup applet.

Its been a year since the above requirement was posted to the Oracle forums, if you are the author of the above post, or you are a customer who needs the solution, send me a message on LinkedIn, and i'll gladly fill you in.

To keep you entertained until then, heres a flash back to the 80s, and an introduction to "Joy", the greatest band to come out of Austria.



Joy enjoyed success across Europe and East Asia, with numerous hits such as Touch by touch, Hey Hello, and Valerie.

XSLT 1.0 upper-case() & lower-case()

In the last article, we looked at using XSLT "includes", and along the way, encountered a requirement to convert a string to uppercase in XSLT 1.0.

XSLT 2.0 users have the luxury of upper-case() & lower-case(), but oddly, functions for converting characters to upper and lowercase are not available in XSLT 1.0.

XSLT isnt the mother language of most Siebel professionals, or if you dont use it everyday, youre going to get rusty (i know i am), so this walkthrough should appeal to a lot of readers.

Lets take a look at our XSLT functions file from last time
<!--XSLTfunctions.xslt-->
<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" /> 
    <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" /> 
    <xsl:template name="FORMATBOOLEAN">
        <xsl:param name="BooleanChar"/>
        <xsl:choose>             
            <xsl:when test="translate($BooleanChar, $smallcase, $uppercase)='Y'">true</xsl:when>
            <xsl:when test="translate($BooleanChar, $smallcase, $uppercase)='YES'">true</xsl:when>
            <xsl:when test="translate($BooleanChar, $smallcase, $uppercase)='TRUE'">true</xsl:when>
            <xsl:otherwise>false</xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>


It works by taking a string value, converting it to uppercase and comparing it to 3 static values, but with a little bit of effort, we can optimise it to be more efficient. Instead of calling translate on the same variable 3 times to get the same result. We will engineer it so its only called once.

We start by creating our own custom UPPER and LOWER functions
    <xsl:template name="UPPER">
        <xsl:param name="text"/>
        <xsl:value-of select="translate($text, $smallcase, $uppercase)"/>
    </xsl:template>
    
    <xsl:template name="LOWER">
        <xsl:param name="text"/>
        <xsl:value-of select="translate($text, $uppercase, $smallcase)"/>
    </xsl:template>   


In XSLT we cannot reassign the value of a variable once it is declared, so we create a new variable called $BooleanCharUPPER,and call the UPPER function from inside our FORMATBOOLEAN function and return the result.
    <xsl:template name="FORMATBOOLEAN">
        <xsl:param name="BooleanChar"/>

        <xsl:variable name="BooleanCharUPPER">
            <xsl:call-template name="UPPER">
                <xsl:with-param name="text">
                    <xsl:value-of select="$BooleanChar"/>
                </xsl:with-param>
            </xsl:call-template>
        </xsl:variable>  
  
    </xsl:template>


Finally we evaluate the $BooleanCharUPPER against our static values.
        <xsl:choose>             
            <xsl:when test="$BooleanCharUPPER='Y'">true</xsl:when>
            <xsl:when test="$BooleanCharUPPER='YES'">true</xsl:when>
            <xsl:when test="$BooleanCharUPPER='TRUE'">true</xsl:when>
            <xsl:otherwise>false</xsl:otherwise>
        </xsl:choose>  


We can now use these functions in any XSLT, where we've included them
        <xsl:call-template name="UPPER">
            <xsl:with-param name="text">
                <xsl:text>bad boys blue</xsl:text> 
            </xsl:with-param>
        </xsl:call-template>

Result: BAD BOYS BLUE

        <xsl:call-template name="LOWER">
            <xsl:with-param name="text">
                <xsl:text>BAD BOYS BLUE</xsl:text>
            </xsl:with-param>
        </xsl:call-template>

Result: bad boys blue

Here is the final XSLTFunctions.xsl file.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  
    <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" /> 
    <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" /> 
    
    <xsl:template name="UPPER">
        <xsl:param name="text"/>
        <xsl:value-of select="translate($text, $smallcase, $uppercase)"/>
    </xsl:template>
    
    <xsl:template name="LOWER">
        <xsl:param name="text"/>
        <xsl:value-of select="translate($text, $uppercase, $smallcase)"/>
    </xsl:template>   
    
    <xsl:template name="FORMATBOOLEAN">
        <xsl:param name="BooleanChar"/>
        <xsl:variable name="BooleanCharUPPER">
            <xsl:call-template name="UPPER">
                <xsl:with-param name="text">
                    <xsl:value-of select="$BooleanChar"/>
                </xsl:with-param>
            </xsl:call-template>
        </xsl:variable>        
        <xsl:choose>             
            <xsl:when test="$BooleanCharUPPER='Y'">true</xsl:when>
            <xsl:when test="$BooleanCharUPPER='YES'">true</xsl:when>
            <xsl:when test="$BooleanCharUPPER='TRUE'">true</xsl:when>
            <xsl:otherwise>false</xsl:otherwise>
        </xsl:choose>        
    </xsl:template>
   
</xsl:stylesheet>


Bad Boys Blue, are a eurodance group that came to fame around the same era as Modern Talking and Sandra back in the 80s, and like many of their contemporaries, their music evolved from the more traditional europop to a more upbeat eurodance style. Its hard to pick a favourite BBB track, but check out "You're a woman, i'm a man" for a little taste of their magic.

XSLT 1.0 include

A few years back, I ran a technical session for a client, on how to use XSLT to solve tricky Siebel problems and i came to realise that not every developer is exposed to XSLT.

On some projects XSLT is handled by the middleware team, and Siebel professionals just send across the raw Siebel Message for the external team to perform the transformations.

In a recent discussion with a new client, they wanted to upgrade to XSLT 2.0 to take advantage of include in XSLT to reduce the size of all their XSLTs. I advised them that it was not necessary to upgrade the XSLT engine for this reason, because this feature already exists in XSLT 1.0.

Keen readers of Impossible Siebel would know that the engine behind the EAI XSLT Service, which is used to transform all XML in Siebel, uses XSLT 1.0.

Casual implementors of XSLT might not know about the include statement, but this feature allows you to declare all your XSLT functions in a seperate file, and import it into the current stylesheet.

The following sample shows how to include an external file containing some XLST functions.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:include href="XSLTfunctions.xslt"/>
</xsl:stylesheet>

<!--XSLTfunctions.xsl-->
<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" /> 
    <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" /> 
    <xsl:template name="FORMATBOOLEAN">
        <xsl:param name="BooleanChar"/>
        <xsl:choose>             
            <xsl:when test="translate($BooleanChar, $smallcase, $uppercase)='Y'">true</xsl:when>
            <xsl:when test="translate($BooleanChar, $smallcase, $uppercase)='YES'">true</xsl:when>
            <xsl:when test="translate($BooleanChar, $smallcase, $uppercase)='TRUE'">true</xsl:when>
            <xsl:otherwise>false</xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

In the above example, i've presented a function to ensure that booleans are formatted consistently, this can helpful if you have different source systems that have slightly different representations of booleans.

Since XSLT 1.0 dosnt have upper-case() and lower-case() functions, i used the translate function to perform this operation. The use of translate can be further refactored into a seperate function for speed.

Finally, here is how you would call these external included functions from your XSLT.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:include href="XSLTfunctions.xslt"/>
    
    <xsl:template match="/">
    <xsl:call-template name="FORMATBOOLEAN">
        <xsl:with-param name="BooleanChar">
            <xsl:text>y</xsl:text>
        </xsl:with-param>
    </xsl:call-template>
    </xsl:template >
</xsl:stylesheet>


Result: true

Using the "include" allows you to easily maintain all your XSLT functions in one place, it will reduce the size and clutter of your stylesheets, as well make it lighter and hence perform better, and maximise its re-usability.

In the next article, we'll look at how we can optimize the above function to perform better.