2
votes

I am missing something really basic (related to class-loading in EAR or EAR configuration). I could not figure out, why my JSR 303 validations and Hibernate validations not triggers from inside an EAR... It does triggers if I create a new WAR project.

I am setting up a new project with Maven, JSF 2.0, Open-JPA, EJB 3.0 on Weblogic Server 10.3. I created all the projects using maven archetypes. I have a final EAR build which is structured as:

  • PROJName
    • ejb
    • web
    • lib
    • META-INF

In the Web, I have a login.xhtml with userName and Password fields mapped with TestMPB variables and poms having the dependencies: validation-api 1.0.0.GA, hibernate-validator 4.2.0.Final…

The page backing bean's (TestMPB) variable has @Pattern and @NotEmpty annotations, but they are never triggered by JSF validation phase. JSF validations works fine, but I want to use JSR 303 and Hibernate validations.

login.xhtml contains following impt lines:

<h:messages layout="table" showDetail="false" showSummary="true"/>
<h:inputText class="textbox" id="userId" value="#{testMPB.userId}"></h:inputText>
<h:commandButton id="button" action="#{testMPB.login}" value="Login" ></h:commandButton>

TestMPB contains:

@Pattern(regexp = "^(?=.*[a-zA-Z])[a-zA-Z0-9_]{2,15}\\s*$", message = "userId invalid")
@NotEmpty(message = "userId empty")
private String userId = "";

public String login(){ System.out.println("User Login ::"+getUserId());
    return "/web/ui/s/home/home.xhtml";
}

Application.xml contains

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" version="5">
<display-name>ear</display-name>
  <module>
    <web>
      <web-uri>web</web-uri>
      <context-root>/NewAccountsWeb</context-root>
    </web>
  </module>
  <module>
    <ejb>ejb</ejb>
  </module>
  <library-directory>lib</library-directory>
</application>

For debug, I made sure:

  • The JSF managed page bean (TestMPB) initializes on page load (by adding SOP in constructor)
  • On Page submit, the method is invoked and the userName value is printed.
  • JARs dependencies are added in the POM are correct and they exists in the final EAR build.
  • Same JSR 303 and Hibernate validations works with same set of login.xhtml and TestMPB.java when I create a WAR project.
  • Created a phase listener and printed all the phases to make sure the phases are invoked.
  • For testing, I also added JSF validations (required=true), which works and show messages in h:message.

Can think of anything which might solve this issue?

1
Can you show where the bean validation api and hibernate validator jar end up in your final ear? Bean Validation should indeed be enabled automatically, when the Bean Validation API is detected on the classpath. My guess is that there is a classloading issue.Hardy

1 Answers

1
votes

I was able to fix this issue on my own...

I added slf4j-log4j12 1.6.4 jar in my project class-path and both bean & hibernate field-level validations started working... jboss-logging-3.1.0.GA.jar might also work... Also Log4j jar was already in classpath.

It seems, for the purposes of logging, Hibernate Validator uses the some Logging API, an abstraction layer which supports some logging solutions as implementation. So if you just add a supported logging library to the classpath and logging will delegate any log requests to that provider.

Its strange that there were no errors in my server-logs or at compile-time, that a logging dependency is missing for Hibernate (or Bean JSR 303) validations... I wasted 3 days on it, but glad that its working now...