-->
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.  [ 8 posts ] 
Author Message
 Post subject: Validator: Struts 1.1 - Input field labels in Error
PostPosted: Tue Feb 16, 2010 2:31 pm 
Regular
Regular

Joined: Mon Aug 07, 2006 5:07 am
Posts: 56
Hi,

I have a small question concerning Hibernate Validator and the integration of it in a Struts 1.1 application.

We have a kind of ValidationUtil class where we can call the methods isValid() and getValidationErrors() on a POJO, which delegates to Hibernate ClassValidator.
I would like to integrate Hibernate Validator in the Struts form where my POJO resides.

In the validate() method of the ActionForm I call the validation and try to make suitable ActionErrors out of the information received by Hibernate Validaor (the InvalidValues[] array).

It's kind of like this:
Code:
public ActionErrors validate(ActionForm actionForm, HttpServletRequest request) {
   ActionErrors errors = new ActionErrors();
   DetailForm detailForm = (DetailForm)actionForm;
   if (!detailForm.getPojo().isValid()) {
      for (InvalidValue value : detailForm.getPojo().getValidationErrors()) {
         errors.add(value.getProperty(), new ActionError(value.getMessage(), <LABEL-KEY>));
      }
   }
   return errors;
}


Now, I already thought that the InvalidValue.getMessage() already gives back the I18N-ed message String in the correct language...but the Struts ActionError class expects a key.
I found out that when you get a ConstraintViolationException or IllegalStateException from Hibernate itself, you can get the messageKey out of the Exception.
From the InvalidValue, I cannot seem to get the message key ... But I thought I got that sorted out by specifying my own key.

Now ...
Next to every <html:text> tag and alikes, we have a <bean:message> tag to display a label for the field.
It's THAT I18N-ed label name that I want to include in the error message that I got back from Hibernate Validator, or that I have to create an ActionError with.

I don't want to check the "if property == this-name then take that-label-key" stuff. I want to be able to do it generically/dynamically.
Also ... I can't use the getPropertyPath method also, because all our labels on screen are already defined in property files and the keys do not match classnames and propertypaths. IMHO, I would like to use the label "name" from one key, and don't have to specify it every single time for a different property path.

Can anyone help me with this?
With JSF it's easy ... It works like a charm and takes the label- or for- attribute in consideration when building the error message, also there ... I use the EventListener so accually he does it before persisting it.
Here in Struts 1, it appears to need customization, and I want to do it before persisting it, but also on the screen in the validate() method of the ActionForm.
I only find information regarding the integration of Hibernate Validator in Struts 2.x and JSF applications...

Thanks for any information you can give me.

Kind regards,

Steve


Top
 Profile  
 
 Post subject: Re: Validator: Struts 1.1 - Input field labels in Error
PostPosted: Wed Feb 17, 2010 8:10 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
What version of Validator are you using? Reading about ClassValidator it seems you are using Hibernate Validator 3.x which is really legacy code now. The current version of Validator 4.x is a new code base with a new API based on the Bean Validation specification.

Unless you try to modify some existing legacy code I recommend you are using Hibernate Validator 4.x.

--Hardy


Top
 Profile  
 
 Post subject: Re: Validator: Struts 1.1 - Input field labels in Error
PostPosted: Wed Feb 17, 2010 8:16 am 
Regular
Regular

Joined: Mon Aug 07, 2006 5:07 am
Posts: 56
We were integrating with Hibernate Validator, but my colleague told me there was a bug in Hibernate Validator 4 working together with Hibernate 3 or something. That's why we reverted back to Validator 3.

I'll have to check with him what the issue exactly was.


Top
 Profile  
 
 Post subject: Re: Validator: Struts 1.1 - Input field labels in Error
PostPosted: Wed Feb 17, 2010 8:23 am 
Regular
Regular

Joined: Mon Aug 07, 2006 5:07 am
Posts: 56
My colleague told me that there were issues combining Hibernate Validator 4.x, Hibernate 3.x and JDK 5 due to dependencies of Hbiernate Validator / Bean Validation spec to JDK 6.

We have to implement to and compile for JDK 5, and do not have access to or possibilities to install JDK 6.

He didn't remember the JIRA number though.


Top
 Profile  
 
 Post subject: Re: Validator: Struts 1.1 - Input field labels in Error
PostPosted: Wed Feb 17, 2010 10:43 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
There is no such dependency. Hibernate Validator 4.x works fine with Java 5. You only need some additional libraries in order to get JAXB support (JAXB is used for parsing of the xml mapping files). On Java 6 JAXB classes are included in the JVM core libraries.
I am not aware of any bug in Validator which would prevent using it in a Java 5 environment. Have you actually tried? Do you have any concrete problems?

--Hardy


Top
 Profile  
 
 Post subject: Re: Validator: Struts 1.1 - Input field labels in Error
PostPosted: Wed Feb 17, 2010 11:01 am 
Regular
Regular

Joined: Mon Aug 07, 2006 5:07 am
Posts: 56
I myself haven't had any issues, but I'm not working on the application framework integrating our older EJB 2.0, Struts 1.1 application with Hibernate and Hibernate Validator.
So I'm afraid I cannot respond to your question.

When using Hibernate Validator at home, in JDK 5, I do not experience any problems.
But then again, I use Maven and it gets all the necessary dependencies automatically.


Top
 Profile  
 
 Post subject: Re: Validator: Struts 1.1 - Input field labels in Error
PostPosted: Thu Feb 18, 2010 10:32 am 
Regular
Regular

Joined: Mon Aug 07, 2006 5:07 am
Posts: 56
I've let my colleague do some more research about the problem, and indeed...the JIRA issue he forwarded me concerns a NoClassDefFound of JAXB.

http://jira.springframework.org/browse/ ... l-tabpanel

It was not that obvious in the information he found at the time (beginning of january) as to what was the problem.
But now we found the exact Hibernate Validator JIRA issue and there you (Hardy) indeed indicate it's only a matter of adding the JAXB dependencies, because they are not yet prt of JDK 5 but are included in JDK 6.
http://opensource.atlassian.com/project ... e/HHH-4427

My colleague now integrated Hibernate Validator 4 again, and we have access to the error messageKey instead of only the already I18N-ed error message.

Thank you very much for your help and patience (of having to suffer the same - already resolved - question again).

Kind regards,

Steve


Top
 Profile  
 
 Post subject: Re: Validator: Struts 1.1 - Input field labels in Error
PostPosted: Thu Feb 18, 2010 10:38 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
My pleasure ;-)
I guess the online docs should be clearer. I created a Jira issue to make sure to add some thing to the docs - HV-289

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.