Results 1 to 5 of 5

Thread: Binding a password and confirmPassword field

  1. #1
    Join Date
    May 2005
    Location
    Boise, Idaho
    Posts
    4

    Default Binding a password and confirmPassword field

    I have a form that allows the user to edit their profile ( username, email, password ). In the case of the password I only want to bind the password field to the command object when the confirmPassword field is also provided. When password and confirmPassword are left blank I would like NO binding to take place for the password on the command object.

    The primary motivation is to only update a user's password when both password and confirmPassword are supplied.

  2. #2
    Join Date
    Oct 2004
    Location
    Herndon, VA, US
    Posts
    648

    Default

    Look at one of the onBind() methods and see if you can override it for custom binding.
    --Jing Xue

  3. #3
    Join Date
    May 2005
    Location
    Boise, Idaho
    Posts
    4

    Default

    It is my understand that onBind() occurs after the other binding has taken place. This means that the password and confirmPassword have already been bound and have overwritten the password that was in the user command object. This causes a blank password when saved with Hibernate.

    I did potentially find a way to prevent fields from being bound using the DataBinder.setAllowedFields. I could remove the password and confirmPassword fields from the "allowed fields" when they are empty ("" or null) in the request. Therefore, the DataBinder will skip binding these fields and generate a warning.

    I know the allowedFields is intended to be used a security feature to prevent unwanted request variables from setting properties on the command object. Is this method of changing the allowedFields per request a "hack"?

  4. #4
    Join Date
    Oct 2004
    Location
    Herndon, VA, US
    Posts
    648

    Default

    Quote Originally Posted by jacksonakj
    It is my understand that onBind() occurs after the other binding has taken place. This means that the password and confirmPassword have already been bound and have overwritten the password that was in the user command object. This causes a blank password when saved with Hibernate.
    Well if the property is called 'password' in the command object, who says you have to name the html field the same way if you don't want a direct binding? Usually password fields don't get prefilled when the form is shown back to the user, so there is no point to have a direct binding, right?
    --Jing Xue

  5. #5
    Join Date
    May 2005
    Location
    Boise, Idaho
    Posts
    4

    Default

    Excellent point. I was looking for a complex answer to a simple solution. Thanks for the advice.

Posting Permissions

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