myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matthias Niehoff" <niehoff.matth...@googlemail.com>
Subject AW: Bean Validation (JSR 303)
Date Mon, 27 Sep 2010 11:38:15 GMT
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.kurz@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-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NUL
> L</par
> am-name>
>          <param-value>true</param-value>
>      </context-param>
>
>          <context-param>
>          <param-name>javax.faces.VALIDATE_EMPTY_FIELDS</param-name>
>          <param-value>auto</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
>


Mime
View raw message