Results 1 to 2 of 2

Thread: Validating request parameters in formBackingObject()

  1. #1
    Join Date
    Aug 2004
    Location
    Athens, GA
    Posts
    20

    Default Validating request parameters in formBackingObject()

    I was just wondering what the best way to validate a request parameter that is used to query a database for the command object e.g.

    Code:
        protected Object formBackingObject(HttpServletRequest request)
                throws Exception {
            String reservationNumber = request.getParameter("reservationNumber");
            if(reservationNumber == null || reservationNumber.equals("")){
                return super.formBackingObject(request);
            }
            ReservationEntity reservationEntity = reservationService.findReservationEntity(reservationNumber);
            return (reservationEntity == null) ? super.formBackingObject(request) : reservationEntity;
        }
    Only problem with this code if someone screws around with the parameter reservationNumber and set it to something wierd that causes a sql error.

    I can add validation logic in the method or in a helper class/method, but is this really the right solution?

  2. #2
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    First up, try using RequestUtils.getRequiredStringParameter, as it will throw nice error messages if the parameter is missing.

    In relation to control characters, your DAO layer should be made responsible for escaping them, not your web controller.

Similar Threads

  1. Hibernate Long Session Per Flow?
    By akw in forum Web Flow
    Replies: 21
    Last Post: Dec 12th, 2005, 08:06 PM
  2. Replies: 9
    Last Post: Nov 1st, 2005, 10:36 PM
  3. Request parameters not in command object
    By fallofrome in forum Web Flow
    Replies: 4
    Last Post: Aug 2nd, 2005, 04:10 PM
  4. RequestScope and request parameters
    By Christian in forum Web Flow
    Replies: 2
    Last Post: Jun 29th, 2005, 10:33 AM
  5. Replies: 7
    Last Post: Nov 30th, 2004, 03:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •