Re: User name validation - how to check database to find if a name has already been taken?

2009-10-01 Thread Nicolas Melendez
Thanks Igor.Always is good another point of view.
NM


On Wed, Sep 30, 2009 at 5:14 PM, Igor Vaynberg igor.vaynb...@gmail.comwrote:

 actually you got it completely wrong. especially as your project, and
 the number of devs who work on it, grows exceptions are a much more
 scalable way of handling errors.

 1) the compiler tells you exactly what the exceptions are right off the bat
 2) exception class name gives you a clue as to what the error is
 without reading javadoc
 3) exception classes can contain error-related data that is easy to
 retrieve
 4) you cannot forget to handle a checked exception
 5) if someone adds a new error code you do not have to hunt down all
 the places that now need to be changed - once again you get a compile
 time error
 6) a bunch of other stuff i dont feel like typing out

 -igor

 On Wed, Sep 30, 2009 at 7:55 AM, Nicolas Melendez
 nmelen...@getsense.com.ar wrote:
  why do you use an exception for user already exits?Don`t you think that
  return true/false, could be better?
  i said that, because if the application start growing, you will have lot
 of
  exceptions class.
  thanks,
  NM
 
 
  On Wed, Sep 30, 2009 at 4:43 PM, Paul Huang paulhuan...@gmail.com
 wrote:
 
 
 
 
  igor.vaynberg wrote:
  
   form {
 onsubmit() {
  try {
 users.persist(getmodelobject());
  } catch (usernamealreadyexistsexception e) {
 error(error.username.exists);
  }
  }
   }
  
   -igor
  
 
  Thanks, it works like a charm. I did not  know I could show an error
  message
  by calling Component.error and then use a filter to catch all error
  messages targeting a specific FormComponent.
 
 
  --
  View this message in context:
 
 http://www.nabble.com/User-name-validation---how-to-check-database-to-find-if-a-name-has--already-been-taken--tp25614625p25682499.html
  Sent from the Wicket - User mailing list archive at Nabble.com.
 
 
  -
  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




Re: User name validation - how to check database to find if a name has already been taken?

2009-09-30 Thread Paul Huang



igor.vaynberg wrote:
 
 form {
   onsubmit() {
try {
   users.persist(getmodelobject());
} catch (usernamealreadyexistsexception e) {
   error(error.username.exists);
}
}
 }
 
 -igor
 

Thanks, it works like a charm. I did not  know I could show an error message
by calling Component.error and then use a filter to catch all error
messages targeting a specific FormComponent.


-- 
View this message in context: 
http://www.nabble.com/User-name-validation---how-to-check-database-to-find-if-a-name-has--already-been-taken--tp25614625p25682499.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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



Re: User name validation - how to check database to find if a name has already been taken?

2009-09-30 Thread Nicolas Melendez
why do you use an exception for user already exits?Don`t you think that
return true/false, could be better?
i said that, because if the application start growing, you will have lot of
exceptions class.
thanks,
NM


On Wed, Sep 30, 2009 at 4:43 PM, Paul Huang paulhuan...@gmail.com wrote:




 igor.vaynberg wrote:
 
  form {
onsubmit() {
 try {
users.persist(getmodelobject());
 } catch (usernamealreadyexistsexception e) {
error(error.username.exists);
 }
 }
  }
 
  -igor
 

 Thanks, it works like a charm. I did not  know I could show an error
 message
 by calling Component.error and then use a filter to catch all error
 messages targeting a specific FormComponent.


 --
 View this message in context:
 http://www.nabble.com/User-name-validation---how-to-check-database-to-find-if-a-name-has--already-been-taken--tp25614625p25682499.html
 Sent from the Wicket - User mailing list archive at Nabble.com.


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




Re: User name validation - how to check database to find if a name has already been taken?

2009-09-30 Thread Paul Huang




The AbstractValidator approach is fine, or you can do it the shorter
way the Igor showed.

Either way, when the page that has the username is submitted, you're
going to have to write that record to the database, even if you don't
have all the info.  The way you wrote the question, I presume you are
collecting info on multiple pages.  First page gets username et al, then
next  as in a wizard page.

When you check the username and it's not in use, write the record.
The table should have audit columns that include record_status and
last_mod_datetime.  Initially write the record with status I (in process)
and when the user is finished registering, update it with A (active).


If the user fills out page 1 and then closes the browser you'll have a
record there with status I.  You'll need a job that fires off periodically
(I do it once a day at 2 or 3am) that finds those records that are more
than, say, 24 hours old, and purges them.

Then, to quote a sith, there is no conflict.

-hth

Thanks for your suggestion. Currently, I  only have a single user input
page. But as the application evolves, I may eventually need to have a wizard
and implement the record_status check process as you suggested  to  make
sure that the database is always consistent.
-- 
View this message in context: 
http://www.nabble.com/User-name-validation---how-to-check-database-to-find-if-a-name-has--already-been-taken--tp25614625p25682624.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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



Re: User name validation - how to check database to find if a name has already been taken?

2009-09-30 Thread Igor Vaynberg
actually you got it completely wrong. especially as your project, and
the number of devs who work on it, grows exceptions are a much more
scalable way of handling errors.

1) the compiler tells you exactly what the exceptions are right off the bat
2) exception class name gives you a clue as to what the error is
without reading javadoc
3) exception classes can contain error-related data that is easy to retrieve
4) you cannot forget to handle a checked exception
5) if someone adds a new error code you do not have to hunt down all
the places that now need to be changed - once again you get a compile
time error
6) a bunch of other stuff i dont feel like typing out

-igor

On Wed, Sep 30, 2009 at 7:55 AM, Nicolas Melendez
nmelen...@getsense.com.ar wrote:
 why do you use an exception for user already exits?Don`t you think that
 return true/false, could be better?
 i said that, because if the application start growing, you will have lot of
 exceptions class.
 thanks,
 NM


 On Wed, Sep 30, 2009 at 4:43 PM, Paul Huang paulhuan...@gmail.com wrote:




 igor.vaynberg wrote:
 
  form {
    onsubmit() {
         try {
            users.persist(getmodelobject());
         } catch (usernamealreadyexistsexception e) {
            error(error.username.exists);
         }
     }
  }
 
  -igor
 

 Thanks, it works like a charm. I did not  know I could show an error
 message
 by calling Component.error and then use a filter to catch all error
 messages targeting a specific FormComponent.


 --
 View this message in context:
 http://www.nabble.com/User-name-validation---how-to-check-database-to-find-if-a-name-has--already-been-taken--tp25614625p25682499.html
 Sent from the Wicket - User mailing list archive at Nabble.com.


 -
 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



Re: User name validation - how to check database to find if a name has already been taken?

2009-09-27 Thread Flavius


The AbstractValidator approach is fine, or you can do it the shorter
way the Igor showed.

Either way, when the page that has the username is submitted, you're
going to have to write that record to the database, even if you don't
have all the info.  The way you wrote the question, I presume you are
collecting info on multiple pages.  First page gets username et al, then
next  as in a wizard page.

When you check the username and it's not in use, write the record.
The table should have audit columns that include record_status and
last_mod_datetime.  Initially write the record with status I (in process)
and when the user is finished registering, update it with A (active).

If the user fills out page 1 and then closes the browser you'll have a
record there with status I.  You'll need a job that fires off periodically
(I do it once a day at 2 or 3am) that finds those records that are more
than, say, 24 hours old, and purges them.

Then, to quote a sith, there is no conflict.

-hth



Paul Huang wrote:
 
 
 
 Ryan Gravener-3 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.  
 
 So you think my current solution (extending AbstractValidator) is OK?
 But I still need to catch nonunique exceptions when saving all user
 inputs. 
 
 
 
 
 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
 For additional commands, e-mail: users-h...@wicket.apache.org
 
 
 Can you be a little bit more specific? After I catch a nonuqniue
 exception,
 how should I change the page markup to present an error message? Any 
 examples/references  will be helpful.
 
 
 

-- 
View this message in context: 
http://www.nabble.com/User-name-validation---how-to-check-database-to-find-if-a-name-has--already-been-taken--tp25614625p25638843.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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



Re: User name validation - how to check database to find if a name has already been taken?

2009-09-25 Thread Ryan Gravener
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 AbstractValidatorString, and override
 onValidate(IValidatableString 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(IValidatableString 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



Re: User name validation - how to check database to find if a name has already been taken?

2009-09-25 Thread Paul Huang



Ryan Gravener-3 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.  

So you think my current solution (extending AbstractValidator) is OK?
But I still need to catch nonunique exceptions when saving all user inputs. 




 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
 For additional commands, e-mail: users-h...@wicket.apache.org
 

Can you be a little bit more specific? After I catch a nonuqniue exception,
how should I change the page markup to present an error message? Any 
examples/references  will be helpful.


-- 
View this message in context: 
http://www.nabble.com/User-name-validation---how-to-check-database-to-find-if-a-name-has--already-been-taken--tp25614625p25615006.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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



Re: User name validation - how to check database to find if a name has already been taken?

2009-09-25 Thread Igor Vaynberg
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 AbstractValidatorString, and override
 onValidate(IValidatableString 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(IValidatableString 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