Does the userVerif.equals(user) clause actually result in true? If not,
then recordError wouldn't run, and validation would be considered to have
passed. Check User.java's equals method, or better yet, maybe just compare
the username strings directly.

On Jan 12, 2018 7:04 AM, "Christopher Dodunski" <ChrisFromTapestry@
christopher.net.nz> wrote:

> Hi there,
>
> Below is my onValidate() method of a BeanEditForm for updating a user's
> profile, where I simply check that a user isn't changing his username to
> an already taken username.  The error output (below it) suggests that
> BeanEditForm is committing the change to the database even before
> onValidate() is called - certainly not what I wish to occur.
>
> Could someone please explain what is happening here, as it runs contrary
> to my understanding of form validation.  Thanks very much for your help.
>
>
> ======================================================================
>             FORM VALIDATION METHOD
> ======================================================================
>
> /**
>  * Do the cross-field validation
>  * Record any error, and thereby prevent Tapestry from emitting a
> "success" event
>  */
> @Log
> public void onValidateFromUpdateForm(){
>         LOG.debug("onValidateFromUpdateForm");
>
>     LOG.debug("Form user: [" + user.getUserName() + "|" +
> user.getFirstName() + "|" + user.getLastName() + "]");  //For
> debugging only (delete)
>
>     //Validate user name (remains unique)
>     User userVerif =
> crudServiceDAO.findUniqueWithNamedQuery(User.BY_USERNAME,
> QueryParameters.with("userName", user.getUserName()).parameters());
>
>     LOG.debug("Verify user: [" + userVerif.getUserName() + "|" +
> userVerif.getFirstName() + "|" + userVerif.getLastName() + "]");
> //For debugging only (delete)
>
>     if(!userVerif.equals(user)){
>         //User name already taken by someone else
>         updateForm.recordError(messages.get("error.userNameTaken"));
>     }
> }
>
>
> ======================================================================
>             LOG OUTPUT
> ======================================================================
>
> 13-01-2018 00:28:09 DEBUG UpdateUser:74 - [ENTER]
> onValidateFromUpdateForm()
> 13-01-2018 00:28:09 DEBUG UpdateUser:177 - onValidateFromUpdateForm
> 13-01-2018 00:28:09 DEBUG UpdateUser:179 - Form user: [Kimmy|James|Cook]
> 13-01-2018 00:28:09 WARN  SqlExceptionHelper:145 - SQL Error: 1062,
> SQLState: 23000
> 13-01-2018 00:28:09 ERROR SqlExceptionHelper:147 - Duplicate entry 'Kimmy'
> for key 'UK_h029unq4qgmbvesub83df4vok'
> 13-01-2018 00:28:09 DEBUG UpdateUser:165 - [ FAIL]
> onValidateFromUpdateForm --
> org.hibernate.exception.ConstraintViolationException
> org.hibernate.exception.ConstraintViolationException: could not execute
> statement
> ...
> Caused by: java.sql.SQLIntegrityConstraintViolationException: Duplicate
> entry 'Kimmy' for key 'UK_h029unq4qgmbvesub83df4vok'
> ...
> 13-01-2018 00:28:09 ERROR Registry:208 - could not execute statement
> 13-01-2018 00:28:09 ERROR Registry:209 - Operations trace:
> 13-01-2018 00:28:09 ERROR Registry:218 - [ 1] Handling traditional
> 'action' component event request for user/Update:updateform.form.
> 13-01-2018 00:28:09 ERROR Registry:218 - [ 2] Triggering event 'action' on
> user/Update:updateform.form
> 13-01-2018 00:28:09 ERROR Registry:218 - [ 3] Triggering event 'validate'
> on user/Update:updateform.form
> 13-01-2018 00:28:09 ERROR RequestExceptionHandler:236 - Processing of
> request failed with uncaught exception:
> org.apache.tapestry5.runtime.ComponentEventException: could not execute
> statement [at classpath:com/optomus/harbour/components/OptoEditForm.tml,
> line 2]
> org.apache.tapestry5.runtime.ComponentEventException: could not execute
> statement [at classpath:com/optomus/harbour/components/OptoEditForm.tml,
> line 2]
> ...
> Caused by: org.apache.tapestry5.ioc.internal.OperationException: could not
> execute statement [at
> classpath:com/optomus/harbour/components/OptoEditForm.tml, line 2]
> ...
> Caused by: org.apache.tapestry5.runtime.ComponentEventException: could not
> execute statement [at
> classpath:com/optomus/harbour/components/OptoEditForm.tml, line 2]
> ...
> Caused by: org.hibernate.exception.ConstraintViolationException: could not
> execute statement
> ...
> Caused by: java.sql.SQLIntegrityConstraintViolationException: Duplicate
> entry 'Kimmy' for key 'UK_h029unq4qgmbvesub83df4vok'
> ...
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

Reply via email to