struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dudley Butt@i-Commerce <Dudley.B...@za.didata.com>
Subject RE: Tokens?
Date Thu, 30 Aug 2001 10:30:17 GMT
ok, let me first explain the concept that i used. I have a menu item to add
a new taxpayer, this link calls a handler, RequestAdd
I have the following code in this actionhandler. Make sure your
actionhandler class extends Action!! NB
All important code is in bold red
 
here is the save token method in this request add handler code
 
 
//***************************************
public final class TaxPayerActionHandlerRequestAdd extends Action implements
IActionHandler{
 
   TaxPayerActionForm actionFormObject = null;
   HttpServletRequest aRequest = null;
 
   UserForm user = null;
 
    public ActionHandlerResponse executeAction(ActionMapping mapping,
ActionForm form, HttpServletRequest request){
 
        System.out.println("In " + this.getClass());
        actionFormObject = (TaxPayerActionForm)form;
        aRequest = request;
        ActionErrors errors = null;
        errors = doTaxPayerRequestAdd();
        if (errors == null){
            return new
ActionHandlerResponse(errors,mapping.findForward("success"));
        }
        else {
            return new ActionHandlerResponse(errors,
mapping.findForward("failure"));
        }
 
    }
 
  public ActionErrors doTaxPayerRequestAdd(){
 
    ActionErrors errors = null;
 
    try {
 
        HttpSession session = null;
        if (aRequest.getSession(false) == null){
          System.out.println("Session is null");
          session = (HttpSession)aRequest.getSession(true);
        }
        else{
          session = (HttpSession)aRequest.getSession(false);
        }
        actionFormObject.setAction(Constants.ACTION_ADD);
        saveToken(aRequest);

 
    }
    catch (Exception ex) {
      ex.printStackTrace();
      errors = new ActionErrors();
      errors.add("taxPayerReqAdd", new
ActionError("error.taxPayerAdd",ex.toString()));
    }
    return errors;
  }
}
 
//***************************************
 
then when you r ready to do the add action to actually add this taxpayer
i.e. database save, then you have some more code to evaluate this token,
here is the code from my Add action handler
 
//***************************************
 
 
public final class TaxPayerActionHandlerAdd extends Action implements
IActionHandler {
 
   TaxPayerActionForm actionFormObject = null;
   HttpServletRequest aRequest = null;
 
   UserForm user = null;
 
    public ActionHandlerResponse executeAction(ActionMapping mapping,
ActionForm form, HttpServletRequest request){
 
        System.out.println("In " + this.getClass());
        actionFormObject = (TaxPayerActionForm)form;
        aRequest = request;
        ActionErrors errors = null;
        errors = doTaxPayerAdd();
        if (errors == null){
            return new
ActionHandlerResponse(errors,mapping.findForward("success"));
        }
        else {
            actionFormObject.setAction(Constants.ACTION_ADD);
            return new ActionHandlerResponse(errors, new
ActionForward(mapping.getInput()));
        }
 
    }
 
  public ActionErrors doTaxPayerAdd(){
 
    ActionErrors errors = null;
 
    try {
 
        HttpSession session = null;
        if (aRequest.getSession(false) == null){
          System.out.println("Session is null");
          session = (HttpSession)aRequest.getSession(true);
        }
        else{
          session = (HttpSession)aRequest.getSession(false);
        }
        user = new UserForm();
        user = (UserForm)session.getAttribute(Constants.USER_KEY);
        try{
 

            Object obj =
(Object)EJBUtil.getBeanHome(EFilerSessionHome.JNDI_NAME, user.getUsername(),
user.getPassword());
            EFilerSessionHome eFilerSessionHome =
(EFilerSessionHome)PortableRemoteObject.narrow(obj,
EFilerSessionHome.class);
            EFilerSession eFilerSession = eFilerSessionHome.create();
            TaxPayerForm emptyFormObject =
eFilerSession.getEmptyTaxPayerForm();
            TaxPayerForm populatedFormObject =
actionFormObject.getFormProperties(emptyFormObject);
 
            FieldErrorList fldErr = null;
            //Do validations
            fldErr = populatedFormObject.validate();
            if (fldErr !=null && fldErr.size() > 0) {
                return ErrorUtil.toActionErrors(fldErr);
            }
 
            ActionErrors tokenErrors = new ActionErrors();
            if (!isTokenValid(aRequest)) {
              tokenErrors.add("addTaxpayer",
                         new
ActionError("error.transaction.token.add.taxpayer"));
            }
            resetToken(aRequest);
           if (!tokenErrors.empty()) {
              return tokenErrors;
            }
            eFilerSession.registerNewTaxPayer(user, populatedFormObject);
 

        }
        catch (PaymentSessionException ex) {
            errors = ErrorUtil.toActionErrors(ex.getFieldErrors());
        }
        catch (RemoteException ex) {
            if (errors==null) {
              errors = new ActionErrors();
            }
            errors.add("remoteEx", ErrorUtil.toActionError(ex));
        }
    }
    catch (Exception ex) {
      ex.printStackTrace();
      if (errors==null) {
         errors = new ActionErrors();
      }
      errors.add("taxPayerAdd", new ActionError("error.taxPayerAdd"));
    }
    return errors;
  }
}
 

-----Original Message-----
From: Claudio Parnenzini [mailto:Claudio.Parnenzini@linkvest.com]
Sent: Thursday, August 30, 2001 11:05 AM
To: struts-user@jakarta.apache.org
Subject: RE: Tokens?


I'm interested for the code. Can you send me an examples please.
 
Thank you very much

-----Original Message----- 
From: Dudley Butt@i-Commerce 
Sent: Thu 8/30/2001 10:45 AM 
To: 'struts-user@jakarta.apache.org' 
Cc: 
Subject: RE: Tokens?


one would typically use tokens as a means to prevent the user from
submitting a page twice when it is undesirable to do so...if u would like
more info and some examples let me know

-----Original Message-----
From: Steven Leija [mailto:Steven.Leija@valtech.com]
Sent: Wednesday, August 29, 2001 5:24 PM
To: 'Struts (struts-user@jakarta.apache.org)'
Subject: Tokens?


Hello All,
 
I'm going over the Action javadocs and came across several methods that use
the keyword of "token".  The docs aren't very intuitive on what exactly
defines a token.  
 
What do the token methods do?  
 
generateToken()
resetToken()
saveToken()
isTokenValid()

Have a good one, 

Steven 

 



**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************




**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************

Mime
View raw message