-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Test Bean Validation Oracle WebLogic
PostPosted: Thu Apr 27, 2017 8:34 am 
Newbie

Joined: Thu Apr 27, 2017 8:04 am
Posts: 4
The Medellin JUG tested the Bean Validation with a small app on Weblogic 12c, Tomcat 8.5 and Glassfish 4.1. Some features like @Email and @Negative don't work. Also we tested @Size(min=2, max=100) @NotNull and these worked.

Next the apps description.

Classes:
Users: Pojo with one field: @Email @NotNull private String email;
AlphaBean: JSF Managed bean with one field: private User user; and one method wich is submitted from a JSF page

Pages:
index.jsf
user.jsf: JSF page with a <h:form> <h:messages/> <h:inputText value="#{alphaBean.user.email}" /> and <h:commandButton>


The form is not submited if the inputTest doesn't have value, but if it has a value, it is submitted when the value is an not valid email.

MavenDependencies
com.sun.faces: jsf-impl 2.2.13
com.sun.faces jsf-api 2.2.13
javax.servlet javax.servlet-api 3.1.0
javax.validation validation-api 2.0.0.Alpha2
org.hibernate.validator hibernate-validator 6.0.0.Alpha2

Next the full codes:

1. User.java


package model.entity;

import java.io.Serializable;


import javax.validation.constraints.Email;


public class User implements Serializable{

@SuppressWarnings("compatibility")
private static final long serialVersionUID = 7849527309510430856L;



@NotNull
@Email
private String email;



public User() {
super();
}

@Override
public String toString() {
return "email: " + this.email ;
}


public void setEmail(String email) {
this.email = email;
}

public String getEmail() {
return email;
}


}


2. AlphaBean.java


package view.controller;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;


import javax.validation.constraints.Email;

import model.entity.User;


@ManagedBean
@SessionScoped
public class AlphaBean implements Serializable {

private static final long serialVersionUID = 5443351151396868724L;
private User user;



public AlphaBean() {

}

public String goAddUserAction(){
this.user = new User();

return "user";
}


public void addUserAction(){
try{

FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Submit OK: " + this.user , "Submit OK " + this.user));

}catch(Exception e){
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), e.getMessage()));
}
}


public void setUser(User user) {
this.user = user;
}

public User getUser() {
return user;
}


}

3. index.jsf

<?xml version='1.0' encoding='windows-1252'?>
<!DOCTYPE html>
<f:view xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:h="http://xmlns.jcp.org/jsf/html">

<h:head></h:head>
<h:body>
<h:form>

<h:commandButton action="#{alphaBean.goAddUserAction}" value="New user" />
</h:form>
</h:body>

</f:view>

4. user.jsf

<?xml version='1.0' encoding='windows-1252'?>
<!DOCTYPE html>
<f:view xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:h="http://xmlns.jcp.org/jsf/html">

<h:head></h:head>
<h:body>
<h:form >
<h:messages/>

<h:panelGrid columns="2">
<h:outputText value="E-Mail"/>
<h:inputText value="#{alphaBean.user.email}" />

</h:panelGrid>


<h:commandButton action="#{alphaBean.addUserAction}" value="Create" />
</h:form>
</h:body>

</f:view>


Top
 Profile  
 
 Post subject: Re: Test Bean Validation Oracle WebLogic
PostPosted: Fri Apr 28, 2017 4:14 am 
Hibernate Team
Hibernate Team

Joined: Thu Jan 05, 2017 6:04 am
Posts: 13
Hi,

It might be that your application server is using the Bean Validation implementation it embeds and not the new one you provide but as I understand it, you also have the issue with Tomcat?

When you say @Email is not working, I suppose the annotation is simply ignored?

Could you upload your Maven project somewhere so that I can try to deploy it on Tomcat and debug what is happening for you?

Thanks!

--
Guillaume


Top
 Profile  
 
 Post subject: Re: Test Bean Validation Oracle WebLogic
PostPosted: Wed May 03, 2017 10:04 am 
Newbie

Joined: Thu Apr 27, 2017 8:04 am
Posts: 4
Hi,

You can download the maven project from https://github.com/medellinjug/beanvalidation , we use jdeveloper as ide

We deployed the .war on glassfish and tomcat too, the issue go the same as you say: the annotation are simple ignored.

Thanks for your help


Top
 Profile  
 
 Post subject: Re: Test Bean Validation Oracle WebLogic
PostPosted: Wed May 03, 2017 10:46 am 
Hibernate Team
Hibernate Team

Joined: Thu Jan 05, 2017 6:04 am
Posts: 13
Hi,

validation-api.jar is just the Bean Validation API. You need a compliant implementation to be able to use the features of Bean Validation 2.0.

At the moment, you are using the implementations provided by the app server which is probably compliant with Bean Validation 1.1 but does not support the new features of Bean Validation 2.0.

To make it work, you would need to override your app server BV implementation with the latest Hibernate Validator 6.0.0.Alpha2 which will be the RI of BV 2.0 (so it will be the first implementation of BV 2.0).

I can't help you on the app server front though!

HTH

--
Guillaume


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.