AW: Bean Validation (JSR 303)
Thanks for your help. I solved the problem. After I fixed a version mismatch in SLF4J Bean Validation was enabled. Maybe the initialization checks the logger? Regards -Ursprüngliche Nachricht- Von: Jan-Kees van Andel [mailto:jankeesvanan...@gmail.com] Gesendet: Montag, 27. September 2010 21:55 An: MyFaces Discussion Betreff: Re: Bean Validation (JSR 303) Yeah, but there is more. First, did you package the myfaces jars in the application or in a shared library or something? And the same question for the validation api and impl jars And this Class.forName check is not the complete check. After Class.forName, we completely initialize the bean validation framework, using the default factory. If this fails, I decided to disable bean validation. But in this case, you should see more logging. For example the error message, explaining why the beanval initialization failed. You can set the logger for javax.faces.validator to fine to see the error message, if any. Otherwise, putting a breakpoint in the javax.faces.validator.BeanValidator.createValidatorFactory() method and stepping into _ExternalSpecifications.isBeanValidationAvailable() would also be a very good first step. @Committers: I decided to log it as fine a year ago, because I can't decide whether or not the exception is important. I didn't want to irritate and scare developers when there is no issue. But we might be better off logging it as info, for cases like this one. Or maybe a second catch clause for specific bean validation exceptions that logs its messages as info. But then again, not every exception thrown by the buildDefaultValidatorFactory has to be that type. For example, NoClassDefFoundErrors could also occur. What do you think? Regards, Jan-Kees 2010/9/27 Jakob Korherr jakob.korh...@gmail.com Hi, That's weird, because ExternalSpecifications does this: beanValidationAvailable = (Class.forName(javax.validation.Validation) != null); Thus it will be true if javax.validation.Validation is on the classpath! Regards, Jakob 2010/9/27 Matthias Niehoff niehoff.matth...@googlemail.com: Hey, I get this message: 27.09.2010 15:57:32 org.apache.myfaces.util.ExternalSpecifications isBeanValidationAvailable INFO: MyFaces Bean Validation support disabled I double checked the classpath. javax.validation.Validation is on it. Regards Matthias -Ursprüngliche Nachricht- Von: Jan-Kees van Andel [mailto:jankeesvanan...@gmail.com] Gesendet: Montag, 27. September 2010 13:52 An: MyFaces Discussion Betreff: Re: Bean Validation (JSR 303) Hey, If you specify javax.faces.VALIDATE_EMPTY_FIELDS=auto, MyFaces will look for a class named javax.validation.Validation on the classpath. If it is found, it will try to initialize it, using: Validation.buildDefaultValidatorFactory().getValidator(); This call may fail, for instance, because of a configuration error in your bean validation code. And if it does, MyFaces will catch this error and log an error message: Error initializing Bean Validation (could be normal) Afterwards, you should see a message in the log: MyFaces Bean Validation support enabled or MyFaces Bean Validation support disabled, depending on whether initalization succeeded or not. Do you see those log messages? Regards, Jan-Kees 2010/9/27 Matthias Niehoff niehoff.matth...@googlemail.com Yes, using Hibernate Validator 4.1.0 Final and Validation API 1.0.0. Is there anything else to configure? Regards Matthias -Ursprüngliche Nachricht- Von: Michael Kurz [mailto:michi.k...@gmx.at] Gesendet: Montag, 27. September 2010 13:33 An: users@myfaces.apache.org Betreff: Re: Bean Validation (JSR 303) Do you have a bean validation implementation like Hibernate Validator on your classpath? regards Michael Am 27.09.2010 13:21, schrieb Matthias Niehoff: Hi, I'm trying to realize Bean Validation. I annotated my attributes and set javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL true. Furthermore I added a h:message tag in my form. When I test the validation nothing happens. The input is accepted (and in my case persisted). Relevant parts of the Code: Web.xml context-param param-namejavax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_A S_N UL L/par am-name param-valuetrue/param-value /context-param context-param param-namejavax.faces.VALIDATE_EMPTY_FIELDS/param-name param-valueauto/param-value /context-param User.java import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.Email; public class User { @NotNull private String nachname; @NotNull private String vorname; @NotNull private String userID; @NotNull private String password
Re: Bean Validation (JSR 303)
Great! I guess the logger version mismatch causes a noclassdeffounderror or something inside beanval. I guess we need to implement some additional logging inside myfaces to debug such issues... Regards, Jan-Kees 2010/9/28 Matthias Niehoff niehoff.matth...@googlemail.com Thanks for your help. I solved the problem. After I fixed a version mismatch in SLF4J Bean Validation was enabled. Maybe the initialization checks the logger? Regards -Ursprüngliche Nachricht- Von: Jan-Kees van Andel [mailto:jankeesvanan...@gmail.com] Gesendet: Montag, 27. September 2010 21:55 An: MyFaces Discussion Betreff: Re: Bean Validation (JSR 303) Yeah, but there is more. First, did you package the myfaces jars in the application or in a shared library or something? And the same question for the validation api and impl jars And this Class.forName check is not the complete check. After Class.forName, we completely initialize the bean validation framework, using the default factory. If this fails, I decided to disable bean validation. But in this case, you should see more logging. For example the error message, explaining why the beanval initialization failed. You can set the logger for javax.faces.validator to fine to see the error message, if any. Otherwise, putting a breakpoint in the javax.faces.validator.BeanValidator.createValidatorFactory() method and stepping into _ExternalSpecifications.isBeanValidationAvailable() would also be a very good first step. @Committers: I decided to log it as fine a year ago, because I can't decide whether or not the exception is important. I didn't want to irritate and scare developers when there is no issue. But we might be better off logging it as info, for cases like this one. Or maybe a second catch clause for specific bean validation exceptions that logs its messages as info. But then again, not every exception thrown by the buildDefaultValidatorFactory has to be that type. For example, NoClassDefFoundErrors could also occur. What do you think? Regards, Jan-Kees 2010/9/27 Jakob Korherr jakob.korh...@gmail.com Hi, That's weird, because ExternalSpecifications does this: beanValidationAvailable = (Class.forName(javax.validation.Validation) != null); Thus it will be true if javax.validation.Validation is on the classpath! Regards, Jakob 2010/9/27 Matthias Niehoff niehoff.matth...@googlemail.com: Hey, I get this message: 27.09.2010 15:57:32 org.apache.myfaces.util.ExternalSpecifications isBeanValidationAvailable INFO: MyFaces Bean Validation support disabled I double checked the classpath. javax.validation.Validation is on it. Regards Matthias -Ursprüngliche Nachricht- Von: Jan-Kees van Andel [mailto:jankeesvanan...@gmail.com] Gesendet: Montag, 27. September 2010 13:52 An: MyFaces Discussion Betreff: Re: Bean Validation (JSR 303) Hey, If you specify javax.faces.VALIDATE_EMPTY_FIELDS=auto, MyFaces will look for a class named javax.validation.Validation on the classpath. If it is found, it will try to initialize it, using: Validation.buildDefaultValidatorFactory().getValidator(); This call may fail, for instance, because of a configuration error in your bean validation code. And if it does, MyFaces will catch this error and log an error message: Error initializing Bean Validation (could be normal) Afterwards, you should see a message in the log: MyFaces Bean Validation support enabled or MyFaces Bean Validation support disabled, depending on whether initalization succeeded or not. Do you see those log messages? Regards, Jan-Kees 2010/9/27 Matthias Niehoff niehoff.matth...@googlemail.com Yes, using Hibernate Validator 4.1.0 Final and Validation API 1.0.0. Is there anything else to configure? Regards Matthias -Ursprüngliche Nachricht- Von: Michael Kurz [mailto:michi.k...@gmx.at] Gesendet: Montag, 27. September 2010 13:33 An: users@myfaces.apache.org Betreff: Re: Bean Validation (JSR 303) Do you have a bean validation implementation like Hibernate Validator on your classpath? regards Michael Am 27.09.2010 13:21, schrieb Matthias Niehoff: Hi, I'm trying to realize Bean Validation. I annotated my attributes and set javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL true. Furthermore I added a h:message tag in my form. When I test the validation nothing happens. The input is accepted (and in my case persisted). Relevant parts of the Code: Web.xml context-param param-namejavax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_A S_N UL L/par am-name param-valuetrue/param-value /context-param context-param param-namejavax.faces.VALIDATE_EMPTY_FIELDS/param-name
Re: Bean Validation (JSR 303)
Great to hear! +1 on the additional logging if bean validation is there but fails to initialize! Regards, Jakob 2010/9/28 Jan-Kees van Andel jankeesvanan...@gmail.com: Great! I guess the logger version mismatch causes a noclassdeffounderror or something inside beanval. I guess we need to implement some additional logging inside myfaces to debug such issues... Regards, Jan-Kees 2010/9/28 Matthias Niehoff niehoff.matth...@googlemail.com Thanks for your help. I solved the problem. After I fixed a version mismatch in SLF4J Bean Validation was enabled. Maybe the initialization checks the logger? Regards -Ursprüngliche Nachricht- Von: Jan-Kees van Andel [mailto:jankeesvanan...@gmail.com] Gesendet: Montag, 27. September 2010 21:55 An: MyFaces Discussion Betreff: Re: Bean Validation (JSR 303) Yeah, but there is more. First, did you package the myfaces jars in the application or in a shared library or something? And the same question for the validation api and impl jars And this Class.forName check is not the complete check. After Class.forName, we completely initialize the bean validation framework, using the default factory. If this fails, I decided to disable bean validation. But in this case, you should see more logging. For example the error message, explaining why the beanval initialization failed. You can set the logger for javax.faces.validator to fine to see the error message, if any. Otherwise, putting a breakpoint in the javax.faces.validator.BeanValidator.createValidatorFactory() method and stepping into _ExternalSpecifications.isBeanValidationAvailable() would also be a very good first step. @Committers: I decided to log it as fine a year ago, because I can't decide whether or not the exception is important. I didn't want to irritate and scare developers when there is no issue. But we might be better off logging it as info, for cases like this one. Or maybe a second catch clause for specific bean validation exceptions that logs its messages as info. But then again, not every exception thrown by the buildDefaultValidatorFactory has to be that type. For example, NoClassDefFoundErrors could also occur. What do you think? Regards, Jan-Kees 2010/9/27 Jakob Korherr jakob.korh...@gmail.com Hi, That's weird, because ExternalSpecifications does this: beanValidationAvailable = (Class.forName(javax.validation.Validation) != null); Thus it will be true if javax.validation.Validation is on the classpath! Regards, Jakob 2010/9/27 Matthias Niehoff niehoff.matth...@googlemail.com: Hey, I get this message: 27.09.2010 15:57:32 org.apache.myfaces.util.ExternalSpecifications isBeanValidationAvailable INFO: MyFaces Bean Validation support disabled I double checked the classpath. javax.validation.Validation is on it. Regards Matthias -Ursprüngliche Nachricht- Von: Jan-Kees van Andel [mailto:jankeesvanan...@gmail.com] Gesendet: Montag, 27. September 2010 13:52 An: MyFaces Discussion Betreff: Re: Bean Validation (JSR 303) Hey, If you specify javax.faces.VALIDATE_EMPTY_FIELDS=auto, MyFaces will look for a class named javax.validation.Validation on the classpath. If it is found, it will try to initialize it, using: Validation.buildDefaultValidatorFactory().getValidator(); This call may fail, for instance, because of a configuration error in your bean validation code. And if it does, MyFaces will catch this error and log an error message: Error initializing Bean Validation (could be normal) Afterwards, you should see a message in the log: MyFaces Bean Validation support enabled or MyFaces Bean Validation support disabled, depending on whether initalization succeeded or not. Do you see those log messages? Regards, Jan-Kees 2010/9/27 Matthias Niehoff niehoff.matth...@googlemail.com Yes, using Hibernate Validator 4.1.0 Final and Validation API 1.0.0. Is there anything else to configure? Regards Matthias -Ursprüngliche Nachricht- Von: Michael Kurz [mailto:michi.k...@gmx.at] Gesendet: Montag, 27. September 2010 13:33 An: users@myfaces.apache.org Betreff: Re: Bean Validation (JSR 303) Do you have a bean validation implementation like Hibernate Validator on your classpath? regards Michael Am 27.09.2010 13:21, schrieb Matthias Niehoff: Hi, I'm trying to realize Bean Validation. I annotated my attributes and set javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL true. Furthermore I added a h:message tag in my form. When I test the validation nothing happens. The input is accepted (and in my case persisted). Relevant parts of the Code: Web.xml context-param param-namejavax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_A S_N UL L/par am-name
Bean Validation (JSR 303)
Hi, I'm trying to realize Bean Validation. I annotated my attributes and set javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL true. Furthermore I added a h:message tag in my form. When I test the validation nothing happens. The input is accepted (and in my case persisted). Relevant parts of the Code: Web.xml context-param param-namejavax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL/par am-name param-valuetrue/param-value /context-param context-param param-namejavax.faces.VALIDATE_EMPTY_FIELDS/param-name param-valueauto/param-value /context-param User.java import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.Email; public class User { @NotNull private String nachname; @NotNull private String vorname; @NotNull private String userID; @NotNull private String password; @NotNull @Email private String email; @NotNull private String role; ... } UserBean.java @ManagedBean @SessionScoped public class UserBean { private User user = new User(); public void setUser(User user) { this.user = user; } public User getUser() { return user; } public String save() { [...] return /admin/user/showUser.xhtml; } [...] } And last but not least: editUser.xhtml body h:form id=form h:messages showDetail=true showSummary=false / h:panelGrid columns=2 id=grid h:outputLabel value=Vorname: for=firstName / h:inputText id=firstName value=#{userBean.user.vorname} / h:outputLabel value=Nachname: for=lastName / h:inputText id=lastName value=#{userBean.user.nachname} / h:outputLabel value=Email: for=email / h:inputText id=email value=#{userBean.user.email} / h:outputLabel value=Rolle: for=role / h:inputText id=role value=#{userBean.user.role} / h:outputLabel value=Passwort: for=password / h:inputSecret id=password value=#{userBean.user.password} / h:commandButton id=save action=#{userBean.save} value=Speichern / /h:panelGrid /h:form /body Did I miss a point? I thougt it would only be annotating the Beans. Thanks for your help! Matthias Niehoff
Re: Bean Validation (JSR 303)
Do you have a bean validation implementation like Hibernate Validator on your classpath? regards Michael Am 27.09.2010 13:21, schrieb Matthias Niehoff: Hi, I'm trying to realize Bean Validation. I annotated my attributes and set javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL true. Furthermore I added a h:message tag in my form. When I test the validation nothing happens. The input is accepted (and in my case persisted). Relevant parts of the Code: Web.xml context-param param-namejavax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL/par am-name param-valuetrue/param-value /context-param context-param param-namejavax.faces.VALIDATE_EMPTY_FIELDS/param-name param-valueauto/param-value /context-param User.java import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.Email; public class User { @NotNull private String nachname; @NotNull private String vorname; @NotNull private String userID; @NotNull private String password; @NotNull @Email private String email; @NotNull private String role; ... } UserBean.java @ManagedBean @SessionScoped public class UserBean { private User user = new User(); public void setUser(User user) { this.user = user; } public User getUser() { return user; } public String save() { [...] return /admin/user/showUser.xhtml; } [...] } And last but not least: editUser.xhtml body h:form id=form h:messages showDetail=true showSummary=false / h:panelGrid columns=2 id=grid h:outputLabel value=Vorname: for=firstName / h:inputText id=firstName value=#{userBean.user.vorname} / h:outputLabel value=Nachname: for=lastName / h:inputText id=lastName value=#{userBean.user.nachname} / h:outputLabel value=Email: for=email / h:inputText id=email value=#{userBean.user.email} / h:outputLabel value=Rolle: for=role / h:inputText id=role value=#{userBean.user.role} / h:outputLabel value=Passwort: for=password / h:inputSecret id=password value=#{userBean.user.password} / h:commandButton id=save action=#{userBean.save} value=Speichern / /h:panelGrid /h:form /body Did I miss a point? I thougt it would only be annotating the Beans. Thanks for your help! Matthias Niehoff
AW: Bean Validation (JSR 303)
Yes, using Hibernate Validator 4.1.0 Final and Validation API 1.0.0. Is there anything else to configure? Regards Matthias -Ursprüngliche Nachricht- Von: Michael Kurz [mailto:michi.k...@gmx.at] Gesendet: Montag, 27. September 2010 13:33 An: users@myfaces.apache.org Betreff: Re: Bean Validation (JSR 303) Do you have a bean validation implementation like Hibernate Validator on your classpath? regards Michael Am 27.09.2010 13:21, schrieb Matthias Niehoff: Hi, I'm trying to realize Bean Validation. I annotated my attributes and set javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL true. Furthermore I added a h:message tag in my form. When I test the validation nothing happens. The input is accepted (and in my case persisted). Relevant parts of the Code: Web.xml context-param param-namejavax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NUL L/par am-name param-valuetrue/param-value /context-param context-param param-namejavax.faces.VALIDATE_EMPTY_FIELDS/param-name param-valueauto/param-value /context-param User.java import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.Email; public class User { @NotNull private String nachname; @NotNull private String vorname; @NotNull private String userID; @NotNull private String password; @NotNull @Email private String email; @NotNull private String role; ... } UserBean.java @ManagedBean @SessionScoped public class UserBean { private User user = new User(); public void setUser(User user) { this.user = user; } public User getUser() { return user; } public String save() { [...] return /admin/user/showUser.xhtml; } [...] } And last but not least: editUser.xhtml body h:form id=form h:messages showDetail=true showSummary=false / h:panelGrid columns=2 id=grid h:outputLabel value=Vorname: for=firstName / h:inputText id=firstName value=#{userBean.user.vorname} / h:outputLabel value=Nachname: for=lastName / h:inputText id=lastName value=#{userBean.user.nachname} / h:outputLabel value=Email: for=email / h:inputText id=email value=#{userBean.user.email} / h:outputLabel value=Rolle: for=role / h:inputText id=role value=#{userBean.user.role} / h:outputLabel value=Passwort: for=password / h:inputSecret id=password value=#{userBean.user.password} / h:commandButton id=save action=#{userBean.save} value=Speichern / /h:panelGrid /h:form /body Did I miss a point? I thougt it would only be annotating the Beans. Thanks for your help! Matthias Niehoff
Re: Bean Validation (JSR 303)
Hey, If you specify javax.faces.VALIDATE_EMPTY_FIELDS=auto, MyFaces will look for a class named javax.validation.Validation on the classpath. If it is found, it will try to initialize it, using: Validation.buildDefaultValidatorFactory().getValidator(); This call may fail, for instance, because of a configuration error in your bean validation code. And if it does, MyFaces will catch this error and log an error message: Error initializing Bean Validation (could be normal) Afterwards, you should see a message in the log: MyFaces Bean Validation support enabled or MyFaces Bean Validation support disabled, depending on whether initalization succeeded or not. Do you see those log messages? Regards, Jan-Kees 2010/9/27 Matthias Niehoff niehoff.matth...@googlemail.com Yes, using Hibernate Validator 4.1.0 Final and Validation API 1.0.0. Is there anything else to configure? Regards Matthias -Ursprüngliche Nachricht- Von: Michael Kurz [mailto:michi.k...@gmx.at] Gesendet: Montag, 27. September 2010 13:33 An: users@myfaces.apache.org Betreff: Re: Bean Validation (JSR 303) Do you have a bean validation implementation like Hibernate Validator on your classpath? regards Michael Am 27.09.2010 13:21, schrieb Matthias Niehoff: Hi, I'm trying to realize Bean Validation. I annotated my attributes and set javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL true. Furthermore I added a h:message tag in my form. When I test the validation nothing happens. The input is accepted (and in my case persisted). Relevant parts of the Code: Web.xml context-param param-namejavax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NUL L/par am-name param-valuetrue/param-value /context-param context-param param-namejavax.faces.VALIDATE_EMPTY_FIELDS/param-name param-valueauto/param-value /context-param User.java import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.Email; public class User { @NotNull private String nachname; @NotNull private String vorname; @NotNull private String userID; @NotNull private String password; @NotNull @Email private String email; @NotNull private String role; ... } UserBean.java @ManagedBean @SessionScoped public class UserBean { private User user = new User(); public void setUser(User user) { this.user = user; } public User getUser() { return user; } public String save() { [...] return /admin/user/showUser.xhtml; } [...] } And last but not least: editUser.xhtml body h:form id=form h:messages showDetail=true showSummary=false / h:panelGrid columns=2 id=grid h:outputLabel value=Vorname: for=firstName / h:inputText id=firstName value=#{userBean.user.vorname} / h:outputLabel value=Nachname: for=lastName / h:inputText id=lastName value=#{userBean.user.nachname} / h:outputLabel value=Email: for=email / h:inputText id=email value=#{userBean.user.email} / h:outputLabel value=Rolle: for=role / h:inputText id=role value=#{userBean.user.role} / h:outputLabel value=Passwort: for=password / h:inputSecret id=password value=#{userBean.user.password} / h:commandButton id=save action=#{userBean.save} value=Speichern / /h:panelGrid /h:form /body Did I miss a point? I thougt it would only be annotating the Beans. Thanks for your help! Matthias Niehoff
AW: Bean Validation (JSR 303)
Hey, I get this message: 27.09.2010 15:57:32 org.apache.myfaces.util.ExternalSpecifications isBeanValidationAvailable INFO: MyFaces Bean Validation support disabled I double checked the classpath. javax.validation.Validation is on it. Regards Matthias -Ursprüngliche Nachricht- Von: Jan-Kees van Andel [mailto:jankeesvanan...@gmail.com] Gesendet: Montag, 27. September 2010 13:52 An: MyFaces Discussion Betreff: Re: Bean Validation (JSR 303) Hey, If you specify javax.faces.VALIDATE_EMPTY_FIELDS=auto, MyFaces will look for a class named javax.validation.Validation on the classpath. If it is found, it will try to initialize it, using: Validation.buildDefaultValidatorFactory().getValidator(); This call may fail, for instance, because of a configuration error in your bean validation code. And if it does, MyFaces will catch this error and log an error message: Error initializing Bean Validation (could be normal) Afterwards, you should see a message in the log: MyFaces Bean Validation support enabled or MyFaces Bean Validation support disabled, depending on whether initalization succeeded or not. Do you see those log messages? Regards, Jan-Kees 2010/9/27 Matthias Niehoff niehoff.matth...@googlemail.com Yes, using Hibernate Validator 4.1.0 Final and Validation API 1.0.0. Is there anything else to configure? Regards Matthias -Ursprüngliche Nachricht- Von: Michael Kurz [mailto:michi.k...@gmx.at] Gesendet: Montag, 27. September 2010 13:33 An: users@myfaces.apache.org Betreff: Re: Bean Validation (JSR 303) Do you have a bean validation implementation like Hibernate Validator on your classpath? regards Michael Am 27.09.2010 13:21, schrieb Matthias Niehoff: Hi, I'm trying to realize Bean Validation. I annotated my attributes and set javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL true. Furthermore I added a h:message tag in my form. When I test the validation nothing happens. The input is accepted (and in my case persisted). Relevant parts of the Code: Web.xml context-param param-namejavax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_N UL L/par am-name param-valuetrue/param-value /context-param context-param param-namejavax.faces.VALIDATE_EMPTY_FIELDS/param-name param-valueauto/param-value /context-param User.java import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.Email; public class User { @NotNull private String nachname; @NotNull private String vorname; @NotNull private String userID; @NotNull private String password; @NotNull @Email private String email; @NotNull private String role; ... } UserBean.java @ManagedBean @SessionScoped public class UserBean { private User user = new User(); public void setUser(User user) { this.user = user; } public User getUser() { return user; } public String save() { [...] return /admin/user/showUser.xhtml; } [...] } And last but not least: editUser.xhtml body h:form id=form h:messages showDetail=true showSummary=false / h:panelGrid columns=2 id=grid h:outputLabel value=Vorname: for=firstName / h:inputText id=firstName value=#{userBean.user.vorname} / h:outputLabel value=Nachname: for=lastName / h:inputText id=lastName value=#{userBean.user.nachname} / h:outputLabel value=Email: for=email / h:inputText id=email value=#{userBean.user.email} / h:outputLabel value=Rolle: for=role / h:inputText id=role value=#{userBean.user.role} / h:outputLabel value=Passwort: for=password / h:inputSecret id=password value=#{userBean.user.password} / h:commandButton id=save action=#{userBean.save} value=Speichern / /h:panelGrid /h:form /body Did I miss a point? I thougt it would only be annotating the Beans. Thanks for your help! Matthias Niehoff
Re: Bean Validation (JSR 303)
Hi, That's weird, because ExternalSpecifications does this: beanValidationAvailable = (Class.forName(javax.validation.Validation) != null); Thus it will be true if javax.validation.Validation is on the classpath! Regards, Jakob 2010/9/27 Matthias Niehoff niehoff.matth...@googlemail.com: Hey, I get this message: 27.09.2010 15:57:32 org.apache.myfaces.util.ExternalSpecifications isBeanValidationAvailable INFO: MyFaces Bean Validation support disabled I double checked the classpath. javax.validation.Validation is on it. Regards Matthias -Ursprüngliche Nachricht- Von: Jan-Kees van Andel [mailto:jankeesvanan...@gmail.com] Gesendet: Montag, 27. September 2010 13:52 An: MyFaces Discussion Betreff: Re: Bean Validation (JSR 303) Hey, If you specify javax.faces.VALIDATE_EMPTY_FIELDS=auto, MyFaces will look for a class named javax.validation.Validation on the classpath. If it is found, it will try to initialize it, using: Validation.buildDefaultValidatorFactory().getValidator(); This call may fail, for instance, because of a configuration error in your bean validation code. And if it does, MyFaces will catch this error and log an error message: Error initializing Bean Validation (could be normal) Afterwards, you should see a message in the log: MyFaces Bean Validation support enabled or MyFaces Bean Validation support disabled, depending on whether initalization succeeded or not. Do you see those log messages? Regards, Jan-Kees 2010/9/27 Matthias Niehoff niehoff.matth...@googlemail.com Yes, using Hibernate Validator 4.1.0 Final and Validation API 1.0.0. Is there anything else to configure? Regards Matthias -Ursprüngliche Nachricht- Von: Michael Kurz [mailto:michi.k...@gmx.at] Gesendet: Montag, 27. September 2010 13:33 An: users@myfaces.apache.org Betreff: Re: Bean Validation (JSR 303) Do you have a bean validation implementation like Hibernate Validator on your classpath? regards Michael Am 27.09.2010 13:21, schrieb Matthias Niehoff: Hi, I'm trying to realize Bean Validation. I annotated my attributes and set javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL true. Furthermore I added a h:message tag in my form. When I test the validation nothing happens. The input is accepted (and in my case persisted). Relevant parts of the Code: Web.xml context-param param-namejavax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_N UL L/par am-name param-valuetrue/param-value /context-param context-param param-namejavax.faces.VALIDATE_EMPTY_FIELDS/param-name param-valueauto/param-value /context-param User.java import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.Email; public class User { @NotNull private String nachname; @NotNull private String vorname; @NotNull private String userID; @NotNull private String password; @NotNull @Email private String email; @NotNull private String role; ... } UserBean.java @ManagedBean @SessionScoped public class UserBean { private User user = new User(); public void setUser(User user) { this.user = user; } public User getUser() { return user; } public String save() { [...] return /admin/user/showUser.xhtml; } [...] } And last but not least: editUser.xhtml body h:form id=form h:messages showDetail=true showSummary=false / h:panelGrid columns=2 id=grid h:outputLabel value=Vorname: for=firstName / h:inputText id=firstName value=#{userBean.user.vorname} / h:outputLabel value=Nachname: for=lastName / h:inputText id=lastName value=#{userBean.user.nachname} / h:outputLabel value=Email: for=email / h:inputText id=email value=#{userBean.user.email} / h:outputLabel value=Rolle: for=role / h:inputText id=role value=#{userBean.user.role} / h:outputLabel value=Passwort: for=password / h:inputSecret id=password value=#{userBean.user.password} / h:commandButton id=save action=#{userBean.save} value=Speichern / /h:panelGrid /h:form /body Did I miss a point? I thougt it would only be annotating the Beans. Thanks for your help! Matthias Niehoff -- Jakob Korherr blog: http://www.jakobk.com twitter: http://twitter.com/jakobkorherr work: http://www.irian.at
Re: Bean Validation (JSR 303)
Yeah, but there is more. First, did you package the myfaces jars in the application or in a shared library or something? And the same question for the validation api and impl jars And this Class.forName check is not the complete check. After Class.forName, we completely initialize the bean validation framework, using the default factory. If this fails, I decided to disable bean validation. But in this case, you should see more logging. For example the error message, explaining why the beanval initialization failed. You can set the logger for javax.faces.validator to fine to see the error message, if any. Otherwise, putting a breakpoint in the javax.faces.validator.BeanValidator.createValidatorFactory() method and stepping into _ExternalSpecifications.isBeanValidationAvailable() would also be a very good first step. @Committers: I decided to log it as fine a year ago, because I can't decide whether or not the exception is important. I didn't want to irritate and scare developers when there is no issue. But we might be better off logging it as info, for cases like this one. Or maybe a second catch clause for specific bean validation exceptions that logs its messages as info. But then again, not every exception thrown by the buildDefaultValidatorFactory has to be that type. For example, NoClassDefFoundErrors could also occur. What do you think? Regards, Jan-Kees 2010/9/27 Jakob Korherr jakob.korh...@gmail.com Hi, That's weird, because ExternalSpecifications does this: beanValidationAvailable = (Class.forName(javax.validation.Validation) != null); Thus it will be true if javax.validation.Validation is on the classpath! Regards, Jakob 2010/9/27 Matthias Niehoff niehoff.matth...@googlemail.com: Hey, I get this message: 27.09.2010 15:57:32 org.apache.myfaces.util.ExternalSpecifications isBeanValidationAvailable INFO: MyFaces Bean Validation support disabled I double checked the classpath. javax.validation.Validation is on it. Regards Matthias -Ursprüngliche Nachricht- Von: Jan-Kees van Andel [mailto:jankeesvanan...@gmail.com] Gesendet: Montag, 27. September 2010 13:52 An: MyFaces Discussion Betreff: Re: Bean Validation (JSR 303) Hey, If you specify javax.faces.VALIDATE_EMPTY_FIELDS=auto, MyFaces will look for a class named javax.validation.Validation on the classpath. If it is found, it will try to initialize it, using: Validation.buildDefaultValidatorFactory().getValidator(); This call may fail, for instance, because of a configuration error in your bean validation code. And if it does, MyFaces will catch this error and log an error message: Error initializing Bean Validation (could be normal) Afterwards, you should see a message in the log: MyFaces Bean Validation support enabled or MyFaces Bean Validation support disabled, depending on whether initalization succeeded or not. Do you see those log messages? Regards, Jan-Kees 2010/9/27 Matthias Niehoff niehoff.matth...@googlemail.com Yes, using Hibernate Validator 4.1.0 Final and Validation API 1.0.0. Is there anything else to configure? Regards Matthias -Ursprüngliche Nachricht- Von: Michael Kurz [mailto:michi.k...@gmx.at] Gesendet: Montag, 27. September 2010 13:33 An: users@myfaces.apache.org Betreff: Re: Bean Validation (JSR 303) Do you have a bean validation implementation like Hibernate Validator on your classpath? regards Michael Am 27.09.2010 13:21, schrieb Matthias Niehoff: Hi, I'm trying to realize Bean Validation. I annotated my attributes and set javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL true. Furthermore I added a h:message tag in my form. When I test the validation nothing happens. The input is accepted (and in my case persisted). Relevant parts of the Code: Web.xml context-param param-namejavax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_N UL L/par am-name param-valuetrue/param-value /context-param context-param param-namejavax.faces.VALIDATE_EMPTY_FIELDS/param-name param-valueauto/param-value /context-param User.java import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.Email; public class User { @NotNull private String nachname; @NotNull private String vorname; @NotNull private String userID; @NotNull private String password; @NotNull @Email private String email; @NotNull private String role; ... } UserBean.java @ManagedBean @SessionScoped public class UserBean { private User user = new User(); public void setUser(User user) { this.user = user; } public User getUser() { return