cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hunsberger, Peter" <Peter.Hunsber...@STJUDE.ORG>
Subject RE: Trap Duplicate Request Post in Cocoon Framework.
Date Wed, 06 Oct 2004 13:41:14 GMT
meenal.ashtikar@wipro.com <meenal.ashtikar@wipro.com> asks:

> I want to trap the event when the user SUBMITs a form twice (Duplicate
post), 
> and display an error message to the user.

We do this on the front end with some JavaScript that removes any submit
buttons from the form once one has been selected (it also reveals a
cycling graphic that is hidden by default).  We have an onClick event
fire code like the following:

function setWait( name )
{
    if ( name == undefined ) {
        name = "form";
    }
    document.getElementById( name + "-buttons").style.display = "none";
    document.getElementById( name + "-wait").style.display = "";
}

Of course, this requires JavaScript on the browser so it isn't a
universal solution.  On the back end we also have flow script that looks
like:

function _sendPageAndValidate( page, collection, args ) {
    var kont = cocoon.sendPageAndWait( page, args );        
    var action = _getAction();
    if ( action != '' && (
         action.startsWith("cocoon-action-Insert") ||       
         action.startsWith("cocoon-action-Delete") ) ) {
        if ( lastAction == kont.id ) {
            if ( action.startsWith("cocoon-action-Insert") ) {
                cocoon.session.setAttribute(
Packages....SESSION_MESSAGE, DUPLICATE_INSERT  );
            }
            else {
                cocoon.session.setAttribute( Packages...SESSION_MESSAGE,
DUPLICATE_DELETE  );
            }
            return false;
        }
        lastAction = kont.id;
    }
    .
    .
    .

function _getAction() {
    var paramNames = cocoon.request.getParameterNames();
    while( paramNames.hasMoreElements()  ) {
        var name = paramNames.nextElement();
        if ( name.search( /cocoon-action-/ ) > -1 ) {
            if (name.indexOf('.') > -1) {
                return name.substring(0, name.indexOf('.'));
            }
            return name;
        }
    }
    return "";
}

Where lastAction is a top level flow script variable.


Mime
View raw message