Hi,
the token is associated to user session and it is stored in the session.
So you can "save" the token before to execute the business logic and
"reset" the token if an exception occured.
I have solved the problem in the following way:
BR
/Amleto


public abstract class TokenFormBaseAction extends Action {
    public ActionForward execute( ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse ) {

        String token = checkToken( httpServletRequest );

        ActionForward forward = null;
        try {
            if ( !isCancelled( httpServletRequest ) ) {
                forward = okButton( actionMapping, actionForm,
httpServletRequest, httpServletResponse );
            } else {
                forward = cancelButton( actionMapping, actionForm,
httpServletRequest, httpServletResponse );
            }
        }
        catch ( RuntimeException e ) {
            //Reset the toekn
            httpServletRequest.getSession( false ).setAttribute(
Globals.TRANSACTION_TOKEN_KEY, token);
            throw e;
        }

        return forward;

    }

    protected String checkToken( HttpServletRequest httpServletRequest )
{
        String token = (String) httpServletRequest.getSession( false
).getAttribute( Globals.TRANSACTION_TOKEN_KEY );

        if (!isTokenValid( httpServletRequest, true ))
                //You can be return null if you want or an other
exception
            throw new RuntimeException( "" );
        return token;
    }


    public abstract ActionForward okButton( ActionMapping actionMapping,
ActionForm actionForm,
                                            HttpServletRequest
httpServletRequest, HttpServletResponse httpServletResponse );

    public ActionForward cancelButton( ActionMapping actionMapping,
ActionForm actionForm,
                                       HttpServletRequest
httpServletRequest, HttpServletResponse httpServletResponse ) {
        return actionMapping.findForward( "CANCEL" );
    }
}



> -----Messaggio originale-----
> Da: Nicolas De Loof [mailto:[EMAIL PROTECTED] 
> Inviato: lunedì 5 dicembre 2005 15.04
> A: Struts Users Mailing List
> Oggetto: how to set token after an exception occurs ?
> 
> 
> 
> Hello,
> 
> I'm using token to avoid multiple submits in this flow :
> 
> "/commande.do" creates an empty form-bean, saves a token and 
> forwards to 
> "tile:commande.new"
> "/commande/create.do" checks for token and creates datas in 
> the database.
> 
> If an exception occurs, an exceptionHandler is used to 
> display an error 
> message. I'm using it to catch Data integrity exception when 
> user try to 
> create an allready-existing entry. In this case, no token is saved 
> anymore and user cannot change it's input and resubmit.
> 
> How can I setup struts to have a new token beeing saved when an 
> exception occurs, to allow the user to correct the form and submit ?
> 
> Nico.
> 
> 
> This message contains information that may be privileged or 
> confidential and is the property of the Capgemini Group. It 
> is intended only for the person to whom it is addressed. If 
> you are not the intended recipient,  you are not authorized 
> to read, print, retain, copy, disseminate,  distribute, or 
> use this message or any part thereof. If you receive this  
> message in error, please notify the sender immediately and 
> delete all  copies of this message.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> -- 
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.362 / Virus Database: 267.13.11/191 - Release 
> Date: 02/12/2005
>  
> 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.13.11/191 - Release Date:
02/12/2005
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to