BeanEditForm onValidate()

"Christopher Dodunski" <[email protected]>
Newsgroups gmane.comp.java.tapestry.user
Message-ID <[email protected]>
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: [email protected]
For additional commands, e-mail: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.