form {
  onsubmit() {
       try {
          users.persist(getmodelobject());
       } catch (usernamealreadyexistsexception e) {
          error("error.username.exists");
       }
   }
}

-igor

On Fri, Sep 25, 2009 at 9:05 AM, Ryan Gravener <r...@ryangravener.com> wrote:
> I think you are overcomplicating things.  Validate the users input, if
> two users want the same name within 1 second of each request you
> probably have bigger problems to deal with.  Anyhow,  when submit is
> called, if you get a nonunique exception.  Catch in dao/service and
> throw an exception wicket can handle and present.
>
> Ryan Gravener
> http://bit.ly/no_word_docs
>
>
>
> On Fri, Sep 25, 2009 at 11:58 AM, Paul Huang <paulhuan...@gmail.com> wrote:
>> Hello,
>>
>> I would like to get your suggestion about how to validate a user name input
>> by checking if the name has already been taken (exists in the back-end
>> database); and how to show feedback messages right next to the input field
>> if it has.
>>
>> Typically, when a user registers to a website, he needs to choose a user
>> name, a password, etc. To make sure that the chosen name is unique, one
>> needs to access the back-end database to check if it already exists.
>>
>> My solution right now is to extend "AbstractValidator<String>", and override
>> "onValidate(IValidatable<String> validatable)" to put the database-checking
>> logic in it. But the more I think about it, the more I felt it might be a
>> wrong solution. The problem (I think, not 100% sure) is that
>> "onValidate(IValidatable<String> validatable)" will be called during the
>> form validation process, even if this process goes through, I may still find
>> out later that the user chosen name has been taken when trying to save all
>> the user inputs (name, password, etc) to the database. This happens when
>> another user registers with the same name between the time the validation
>> process finished and the time I start persisting all inputs from the first
>> user to the database,
>>
>> So now I am trying to figure out another solution. Here is the idea: Instead
>> of putting the database-checking logic into the validation process, I simply
>> try to save all the user inputs into the database after receiving them. If
>> an unique key exception happens, I know that the user chosen name has been
>> taken. Now my questions are:
>> 1. where should I put this save-catch-exception logic? Is "Form.onSubmit()"
>> the right place to put it?
>> 2. After I catch an unique key exception. How can I show a feedback message
>> like "This name has already been taken" RIGHT NEXT to the user name input
>> field? (Just like what a typical Wicket Validator does though
>> "FeedbackPanel").
>>
>> I am new to Wicket and your inputs and suggestions are greatly appreciated.
>>
>> Cheers
>> Paul
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to