Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java Open Source > Struts
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Struts section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 18th, 2006, 08:17 AM
Registered User
 
Join Date: Jan 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default diffrence between addErrors&saveErrors

 what is the diffrence between addErrors&saveErrors?

mohanrao
 
Old January 18th, 2006, 08:30 AM
Registered User
 
Join Date: Jan 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

use saveErrors() in validate() method of ActionForm class and use addErrors() in else where

M Kalyan Tilak
 
Old August 12th, 2006, 04:05 AM
Authorized User
 
Join Date: Aug 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to sachin.tathod
Default

Follwing example of the ActionForm and action class will give u clear idea abt diff.


1.Validate method in the form
 public ActionErrors validate(ActionMapping mapping, HttpServletRequest req) {
        ActionErrors errors = super.validate(mapping, req);

        if (guaranteeRequired == 1) {
            //No Guest Guarantee
            if ("".equals(planName)) {
                errors.add(ActionErrors.GLOBAL_ERROR,
                    new ActionError("PPlDC_ValErrMsg_6"));
            }

            if ("".equals(otherPayNotes)) {
                errors.add(ActionErrors.GLOBAL_ERROR,
                    new ActionError("PPlDC_ValErrMsg_1"));
            }

            if (!("".equals(receiveDate))) {
                Date date = DateValidator.isValid(receiveDate,new Locale("EN_US"));

                if (date == null) {
                    errors.add(ActionErrors.GLOBAL_ERROR,
                        new ActionError("PPlDC_ValErrMsg_5"));
                    receiveDate = "";
                }
            }

            //Flag for checking "no guest guar required" in gpaytypevo
            if ((amount != null) && !("".equals(amount))) {
                double amountDouble = 0;

                try {
                    amountDouble = Double.parseDouble(amount.trim());
                } catch (NumberFormatException numEx) {
                    //Amount should be a numeric value
                    errors.add(ActionErrors.GLOBAL_ERROR,
                        new ActionError("PX_ERR_GP_AMOUNT"));
                }

                if ((amount.trim().length() > 10) || (amountDouble > 999999.99)) {
                    //Amount should be less that 10 characters and should not be greater than 999999.99
                    errors.add(ActionErrors.GLOBAL_ERROR,
                        new ActionError("PX_ERR_GP_AMOUNTRANGE"));
                }
            }

            if ((referenceItem != null) && !("".equals(referenceItem))) {
                int refItem = 0;
                if (referenceItem.trim().length() > 40) {
                    //Reference Item should not be greater than 40 characters long
                    errors.add(ActionErrors.GLOBAL_ERROR,
                        new ActionError("PX_ERR_GP_REFITEM"));
                }
                try {
                    refItem = Integer.parseInt(referenceItem);
                } catch (NumberFormatException numEx) {
                    //Reference Item should be a numeric value
                    errors.add(ActionErrors.GLOBAL_ERROR,
                        new ActionError("PX_ERR_GP_REFITEMNUME"));
                }

                if (refItem < 0) {
                    //Reference Item should be greater than zero
                    errors.add(ActionErrors.GLOBAL_ERROR,
                        new ActionError("PX_ERR_GP_REFITEMRANGE"));
                }
            }

            if ((checkNumber != null) && !("".equals(checkNumber))) {
                int checkNumInt = 0;
                if (checkNumber.trim().length() > 40) {
                    //Check Number should not be greater than 40 characters long
                    errors.add(ActionErrors.GLOBAL_ERROR,
                        new ActionError("PX_ERR_GP_CHECKNUM"));
                }

                try{
                    checkNumInt = Integer.parseInt(checkNumber);
                } catch (NumberFormatException numEx) {
                    //Check Number should be a numeric value
                    errors.add(ActionErrors.GLOBAL_ERROR,
                        new ActionError("PX_ERR_GP_CHECKNUMNUME"));
                }


                if (checkNumInt < 0) {
                    //Check Number should be greater than zero
                    errors.add(ActionErrors.GLOBAL_ERROR,
                        new ActionError("PX_ERR_GP_CHECKNUMRANGE"));
                }
            }
        } else {
            if (paymentByCC || paymentByNonCC) {
                if ("".equals(guaranteePlanName)) {
                    errors.add(ActionErrors.GLOBAL_ERROR,
                        new ActionError("PPlDC_ValErrMsg_6"));
                }
            }

            if (paymentByNonCC) {

                    if (!("".equals(dueDate))) {
                    Date date = DateValidator.isValid(dueDate,new Locale("EN_US"));

                    if (date == null) {
                        errors.add(ActionErrors.GLOBAL_ERROR,
                            new ActionError("PPlDC_ValErrMsg_3"));
                        dueDate = "";
                    } else {
                        dueDate = new SimpleDateFormat("MM/dd/yyyy").format(date);
                    }
                }

                if (!(numDaysDue.equals("")) || !(numDaysDue.length() == 0)) {
                    Pattern p = Pattern.compile("[0-9]+");

                    //Match the given string with the pattern
                    Matcher m = p.matcher(numDaysDue.trim());

                    //check whether match is found
                    boolean matchFound = m.matches();

                    if (!matchFound) {
                        errors.add(ActionErrors.GLOBAL_ERROR,
                            new ActionError("PPlDC_ValErrMsg_4"));
                        }
                    }
                }
            }

        if (errors.size() > 0) {
            validationErrors = true;
        } else {
            validationErrors = false;
        }

        return errors;
    }

2. Action class method using save error in the exception class.

    public ActionForward remove(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        logger.entering();

        List paymentPlanList = null;
        ActionErrors errors = new ActionErrors();

        GuaranteePaymentForm paymentForm = (GuaranteePaymentForm) form;

        try {
            ResdeskSessionManager session = ResdeskPageAction.getResdeskSessionManager(request );
            PKComponentRequestVO requestVO = session.getPKComponentRequestVO();
            PKResdeskXDelegate pkResdeskXDelegate = new PKResdeskXDelegate();

            if (ResdeskPageAction.checkAndTouchLogin(request, response,
                        PasskeyUtils.getResDeskAppID().intValue())) {
                return null; // session has expired
            }

            requestVO.setComponentTypeId(PKComponentRequestVO. GUARANTEE);

            String paymentPlanIdStr = request.getParameter("paymentPlanId");

            if (paymentPlanIdStr != null) {
                int paymentPlanId = new Integer(paymentPlanIdStr).intValue();
                requestVO.setComponentId(paymentPlanId);
                pkResdeskXDelegate.remove(requestVO, new GuaranteePlanCVO());
            }

            paymentPlanList = pkResdeskXDelegate.listByEvent(requestVO);
            session.putSessionData(ConstantDeclareI.GUARANTEEP LANLIST,
                paymentPlanList);

            AccessPrivilegeVO accessPriviligeVO = pkResdeskXDelegate.getAccessPrivileges(requestVO);
            request.setAttribute(ConstantDeclareI.PAYMENTPLAN_ ACCESSPREVILEGE,
                accessPriviligeVO);

        } catch (Exception exp) {
            paymentForm.setValidationErrors(true);
            errors.add(ActionErrors.GLOBAL_ERROR,
                new ActionError(exp.getMessage()));
            saveErrors(request, errors);
        }

        logger.exiting();

        return mapping.findForward("planlist");
    }



Thanks and Regards,
SACHIN S.TATHOD
Patni Computer System Ltd.
Magarpatta City, Cyber City,
Tower 3,Level I & II,
Hadapsar,Pune - 411028
Mobile No:- +91-9881239401
Email ID:- [email protected]
 
Old November 13th, 2006, 07:37 AM
Registered User
 
Join Date: Oct 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to sparun1607
Default

As I'm new to struts I am able to understand your code wat u given .
So i was not able to understand addErrors and saveErrors and where to use it...

Arun





Similar Threads
Thread Thread Starter Forum Replies Last Post
ch10 action.saveErrors() AlienLoi BOOK: Professional Jakarta Struts 0 May 11th, 2007 04:37 AM
Difference between addErrors() and saveErrors() tilakkalyan Struts 2 February 15th, 2006 03:02 PM
Javascript && keeps turnig into &amp;&amp; ayrton Pro VB.NET 2002/2003 3 June 27th, 2005 03:34 PM
Linux & KDE & C++ & QT & MYSQL & Kdevelop Munnnki Linux 0 January 2nd, 2005 05:41 PM
sql & join tables & find a field in multiple table trangd Beginning PHP 2 January 29th, 2004 07:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.