| Author |
Message |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 25/11/2008 21:14:04
|
troy.sellers
Joined: 20/10/2008 00:00:00
Messages: 53
Offline
|
Hi All,
Pretty new to this so I hope this isn't a "stupid" question.
I can't seem to get the Hibernate Validator on my entity to fire on a partial submit?
Entity
Code:
@Entity
@Name("emailBean")
public class EmailBean {
private String email;
@Id
@Email(message="Email is not a valid email....")
public String getEmail() {
return email;
}
public void setEmail(String email) {
System.out.println("Setting email ["+email+"]");
this.email = email;
}
}
Form
Code:
<ice:panelGroup>
<ice:form>
<ice:message></ice:message>
<ice:outputText value="Email: "/>
<s:decorate>
<ice:inputText id="emailInput" value="${emailBean.email}" partialSubmit="true"/>
</s:decorate>
</ice:form>
</ice:panelGroup>
Can anyone see the problem here? Any hints appreciated.
Cheers,
Troy
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 26/11/2008 01:47:08
|
zzzz8
Joined: 07/12/2005 00:00:00
Messages: 249
Offline
|
I think you need to adjust the ice:message element where you indicate the error has been found for a particular element ID:
Code:
<ice:panelGroup>
<ice:form>
<ice:outputText value="Email: "/>
<s:decorate>
<ice:inputText id="emailInput" value="${emailBean.email}" partialSubmit="true"/>
<ice:message for="emailInput" />
</s:decorate>
</ice:form>
</ice:panelGroup>
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 26/11/2008 15:37:44
|
troy.sellers
Joined: 20/10/2008 00:00:00
Messages: 53
Offline
|
Hi zzzz
Thanks for the tip on that, however I think something more fundamental is going on here.
Firstly, I can assume that this should work? Is there any configuration steps that I need to take to ensure that this does work?
I can set and display faces messages using the @In private FacesMessages and facesMessages.add() method.
How can I tell if the validator is firing at least?
Updated code
Code:
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ice="http://www.icesoft.com/icefaces/component">
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet/styles.css"/>
<link rel="stylesheet" type="text/css" href="stylesheet/xp.css"/>
</head>
<ice:panelGroup>
<s:div rendered="#{!empty facesMessages.currentGlobalMessages}">
<ui:repeat var="msg" value="#{facesMessages.currentGlobalMessages}">
<h:panelGrid columns="1">
<h:outputText value="#{msg.summary}"/>
</h:panelGrid>
</ui:repeat>
</s:div>
<ice:form>
<ice:outputText value="Email :"/>
<s:decorate>
<ice:inputText id="emailInput" value="#{emailBean.email}" partialSubmit="true" />
<ice:message for="emailInput"/>
</s:decorate>
</ice:form>
</ice:panelGroup>
</html>
</ui:composition>
and Bean
Code:
package com.yum.matador.session;
import org.hibernate.validator.Email;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.faces.FacesMessages;
@Name("emailBean")
public class EmailBean {
@In
private FacesMessages facesMessages;
private String email;
@Email
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
System.out.println("setting email value ["+email+"]");
facesMessages.add("We have set the email ....");
}
}
Any hints on where to go to find out about configuration of this?
JBoss EAP 4.3
Seam 2.1.1.SP1
ICEFaces 1.7.2
Java 5
Cheers,
Troy
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 26/11/2008 16:43:09
|
judy.guglielmin
Joined: 20/02/2007 00:00:00
Messages: 1196
Offline
|
If you want to use the hibernate validator as well as do some of your own validation, I have found the following to be useful:-
Code:
<s:decorate id="emailField" template="layout/edit.xhtml">
<ui:define name="label">Email address</ui:define>
<ice:inputText id="emailAddress" value="#{newUser.emailAddress}"
validator="#{registerAction.emailNotTaken}"
size="40" required="true" partialSubmit="true"/>
</s:decorate>
#{newUser} is an instance of an Entity Bean (pretty much need this for the validator to use the annotations AFAIK). Then in registerAction, I am going to check that the emailAddress has not already been used (want them to be unique, right?).
Here is the code for the method emailNotTaken and it's helper methods:-
Code:
public void emailNotTaken(FacesContext context, UIComponent validate, Object value){
//since we have our own validator, need to check for hibernate annotation validations
checkHibernateAnnotations(context, validate, value);
String email = (String)value;
if (isEmailRegistered(email)){
FacesMessage msg = new FacesMessage("ice email already taken");
context.addMessage(validate.getClientId(context), msg);
emailValid=false;
}else emailValid=true;
}
public boolean isEmailRegistered(String email) {
return entityManager.createQuery(
"select m from Member m where m.emailAddress = ?1")
.setParameter(1, email).getResultList().size() > 0;
}
private void checkHibernateAnnotations(FacesContext context,
UIComponent validate, Object value) {
ModelValidator mv = new ModelValidator();
mv.validate(context, validate, value);
}
You can then use ajax via the ice input component for your non-annotated checks and also invoke the hibernate validator via Seam's ModelValidator class for the hibernate annotated validation.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 26/11/2008 17:45:36
|
troy.sellers
Joined: 20/10/2008 00:00:00
Messages: 53
Offline
|
Hi Judy,
Thanks for the tips, however I was hoping to not implement custom validators as the Hibernate ones are sufficient at the moment.
I created a simple ice faces and seam project using seam-gen, and the hibernate validaton works in that. I am wondering if there is any configuration that I might have missed when I built my project (started from seam-gen but mavenised and hacked etc).
Is there any documentation around on how this needs to be configured?
Cheers,
Troy
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 26/11/2008 19:20:01
|
troy.sellers
Joined: 20/10/2008 00:00:00
Messages: 53
Offline
|
Hi,
Just further testing on this.
I created a new project using seam-gen and it works with hibernate validators OOTB as I would expect, the message is rendered on a partial submit saying email is not a valid field.
I cannot get this working with my project however and I am not sure what configuration etc that I am missing?
Cheers,
Troy
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 26/11/2008 20:42:45
|
mark.collette

Joined: 07/02/2005 00:00:00
Messages: 1556
Offline
|
troy.sellers wrote:
Code:
<ice:panelGroup>
<s:div rendered="#{!empty facesMessages.currentGlobalMessages}">
<ui:repeat var="msg" value="#{facesMessages.currentGlobalMessages}">
<h:panelGrid columns="1">
<h:outputText value="#{msg.summary}"/>
</h:panelGrid>
</ui:repeat>
</s:div>
<ice:form>
<ice:outputText value="Email :"/>
<s:decorate>
<ice:inputText id="emailInput" value="#{emailBean.email}" partialSubmit="true" />
<ice:message for="emailInput"/>
</s:decorate>
</ice:form>
</ice:panelGroup>
I'd be careful with the <s:div>'s rendered attribute. With ICEfaces' DOM differencing algorithm, when that <s:div> changes between rendered and non-rendered, or vice-versa, it will cause the <ice:panelGroup> to be sent, including the <ice:form>. Generally, browsers don't play nice with entire forms being swapped in. You can lose keyboard focus in your inputText or worse. If you wrap the <s:div> with another one, or a panelGroup, that is always rendered, then the form will be safe.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 20/01/2009 10:41:09
|
tathagat
Joined: 20/01/2009 00:00:00
Messages: 1
Offline
|
Hi there.
I am having exactly the same problem.
Did you solve it?
I created my project using APPFUSE and then ported it to seam.
Thanks in advance.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 20/01/2009 13:34:55
|
judy.guglielmin
Joined: 20/02/2007 00:00:00
Messages: 1196
Offline
|
What you really need on your xhtml or jspx page are the <s:validate> or <s:validateAll> tags. (if you look at the seam-gen templates, you can see <s:decorate template="edit.xhtml"> or whatever, but look inside the edit decorator template and you will see the seam validation tags.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 20/01/2009 15:28:25
|
troy.sellers
Joined: 20/10/2008 00:00:00
Messages: 53
Offline
|
Hi,
My initial problem was that I was missing seam-ui dependency in the web project (was using EAR build).
As per judy's post, my requirements ensured that I needed to implement custom validators on each field. This was done with a combination of creating my own hibernate validators or simply validating in the seam layer.
Cheers,
Troy
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 26/11/2009 16:17:29
|
zzzz8
Joined: 07/12/2005 00:00:00
Messages: 249
Offline
|
I'm just wondering how you got the standard Hibernate Validators (e.g. @Email, @Pattern) to fire for you? I'm actually running into this issue right now where it doesn't seem to be firing for me. I'm using Seam 2.1.2 with ICEfaces 1.8.1 - I have jboss-seam-ui.jar in the WEB-INF/lib directory as well as in the top level lib directory. I'm using EAR packaging - and the project was initially created using Seam gen.
It's strange because the errors will display if the field is left as null - i.e. if I mark the field as required, it will say the field is required ("value is required"). But that's the only type of error I get...
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 27/11/2009 08:10:13
|
judy.guglielmin
Joined: 20/02/2007 00:00:00
Messages: 1196
Offline
|
You should not have the same jar (seam-ui) in both locations. Is there reason why you are doing so? Ensure you have the <s:validate> or <s:validateAll> tags around your field. Basic templates from seam-gen will give you working examples of this use, if you simply generate a simple table from a database.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 27/11/2009 14:11:49
|
zzzz8
Joined: 07/12/2005 00:00:00
Messages: 249
Offline
|
Hmm, I can't recall why I did that... Nevertheless, I removed the jboss-seam-ui.jar from the lib directory. I'm now getting a slightly different error:
Code:
Exception during request processing:
Caused by javax.servlet.ServletException with message: "Servlet execution threw an exception"
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:313)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
java.lang.Thread.run(Thread.java:595)
I'm using seam-gen, so the s:validateAll tag is in /layout/edit.xhtml.
BTW, here's a snippet of my entity code:
Code:
@Field(index = org.hibernate.search.annotations.Index.UN_TOKENIZED)
@Column(nullable = false, length = 64)
@NotNull(message = "#{messages['itemIdentifierNotNull']}")
@Length(max = 64, message = "#{messages['itemIdentifierLength']}")
@Index(name = "itemversion_identifier_index")
@Pattern(regex = "\\d{4}", message = "#{messages['itemIdentifierPattern']}")
private String identifier;
Any ideas?
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 27/11/2009 14:22:31
|
judy.guglielmin
Joined: 20/02/2007 00:00:00
Messages: 1196
Offline
|
Are you sure that's the entire stack trace? No "caused by...."?
You might want to try it without the "@Not Null" specification as well.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 27/11/2009 20:56:16
|
zzzz8
Joined: 07/12/2005 00:00:00
Messages: 249
Offline
|
Oops, it didn't show up in my console - so I checked the app server log. It then indicated it couldn't find the ModelValidator class (I had another Hibernate Validator class that was using this class). Then I realized why I put jboss-seam-ui.jar in the lib directory - which was for this reason. Anyway, when I removed the reference to the ModelValidator in the other Hibernate Validator class, the exception was gone. However, the standard Hibernate validators would still not fire so I'm still at a loss. I looked at the server logs and nothing comes up.
|
|
|
 |
|
|