Hibernate Validator: Built-in Way to Use Locale for Validation Messages - bean-validation

Is there any built-in mechanism or simple integration with Hibernate Validator so that I can use the HttpRequestServlet's locale to generate validation messages?

No, there is no out-of-the-box solution for this currently.
You'd have to plug in a custom message interpolator which applies the right locale. Unfortunately, the solution likely will be a bit hack-ish at this point. E.g. check out this post on a description for solving the issue for JAX-RS.

Related

Requiring a Module With Alloy MVC

Right, so, if I was simply using Titanium, I could write:
var platino = require("co.lanica.platino");
And I'd be good to go. Since moving to Alloy, I don't know how to replicate the same line in the afforementioned MVC framework.
Do I add it under the global namespace? I already added the module in tiapp.xml, but I have no idea how to access it as a variable "platino".
The docs for Alloy are pretty sparse...any suggestions?
Require method is almost same in Alloy, you can use the require keyword in your js file and implement as in classic approach.
checkout the docs.

How to internationalize a handlebars + backbone view?

I would like to be able to internationalize a backbone + Handlebars application but I am not clear what the best way to do it. Are there any specific best practices for internationalizing backbone + Handlebar views?
On the server side I am using SpringMVC and have access to standard java internationalization facilities.
Here are some very good resources on internationalization for the client side.
http://2012.jsconf.eu/speaker/2012/08/28/client-side-internationalization.html really worth watching it provides a good explanation of the issues with internationalization and is java-script focused.
http://alexsexton.com/blog/2012/03/the-ux-of-language/ Good article about the internationalization
JavaScript libraries for internationalization:
https://github.com/SlexAxton/messageformat.js
http://slexaxton.github.com/Jed/
Standards:
http://userguide.icu-project.org/formatparse/messages (very useful read)
http://cldr.unicode.org/ (more of a reference)
Currently I'm working with an app with (very limited) internationalization, and I mix in an object with the model before sending it to the template in the Backbone.Marionette.Renderer.render function. If you have a similar central function which renders your templates (which I assume you have) you can do this logic there. You could for instance mix the internationalized content (language preselected in) in a namespace, for instance
data = _.extend(model, {t: translations(:dutch))
Leaves how to get the translations from the backend to the frontend, but I don't know enough of SpringMVC to give you advise on that.
We use i18next (http://i18next.com) in our Require/Backbone/Handlebars app with very good results. It supports plural and context forms and there are converters from PO to JSON and vice versa. (PO is widely used for translations here.) The documentation is clean and full of helpfull examples.
It's possible to use it in Handlebars with both static keys (strings) or dynamic variables. You will have to setup your own Handlebars helpers but the documentation of i18next provides example code for this.
In this post, I've added more implementation details:
https://stackoverflow.com/a/17728920/621690

validation with Entity framework and WPF/Silverlight or ASP.Net

In a wpf application using POCO classes with Entity framework, what is the best way to perform validation on data. I am aware of data annotations but if I am not compeltely wrong they are more used with ASP.Net MVC than WPF (i didnt find many examples with WPF). Earlier I was having my Domain classes implement the IDataErrorInfo interface but I wasnt sure if this was the correct approach. If I would want to share my EntityFramework classes at a later stage with say a silverlight application or an ASP.NET application what would be my best approach so that I can reuse my validation rules. (With ASP.net i believe my IDataErrorInfo way of handling errors would be useless?).I can find a lot of similar questions but not one that particularly meets my needs. It would be great if anyone can point me in the right direction
I have been using T4 templates on my domain model to generate the POCO classes and have been using these POCO class objects as business objects too
Out of the box, WPF Validation uses IDataErrorInfo and/or ValidationRule's on bindings. IDataErrorInfo being the partial classes that provide a way to tie in additional logic to make sure the value is valid (IE: The Person.Age property is between 1-100) and ValidationRule's being able to inspect the value before it is ever applied to the binding (IE: The Person.Age property is an integer at all). IDataErrorInfo is obviously only helpful when the value of a Binding gets updated with a compatible datatype, ValidationRule's are helpful in the event somebody types "Ten" instead of 10, in your Age textbox and the datatypes are not compatible.
IDataErrorInfo is reusable for all WPF/Silverlight/ASP.NET projects, (see: How to use IDataErrorInfo in ASP.NET)
Whereas ValidationRule's are to be used with Bindings and therefore not useful in a ASP.NET project. They could be considered the equivalent of Javascript validation.
In short, IDataErrorInfo is exactly what you're looking for and will provide the most reuse for those technologies.
IDataErrorInfo is not supported out-of-the box with EF validation. Annotations are used not only for validation but also can be used to define your model (e.g. Required, MaxLenght, StringLength attributes etc.). Out-of-the box you can use a few more mechanisms to validate your entities - by writing your own attribute by deriving from ValidationAttribute, by using CustomValidationAttribute or by implementing IValidatableObject. That's what EF supports out of the box. If neither of these works for you can replace built-in validation by overwriting DbContext.ValidateEntity() method and use any validation mechanism that works for you. A couple useful links: http://blogs.msdn.com/b/adonet/archive/2010/12/15/ef-feature-ctp5-validation.aspx
http://blogs.msdn.com/b/adonet/archive/2011/05/27/ef-4-1-validation.aspx

VirtualPathUtility.ToAbsolute() VS. Url.Content()

I have been working in an MVC project, and have seen both of these used. I was wondering what the difference between them is? Is it incorrect to use one over the other? My understanding is that I should be using Url.Content(), but VirtualPathUtility.ToAbsolute() seems to be working as well.
Url.Content() is an utility method part of MVC. Being there to uniformize and centralize utility classes I guess.
VirtualPathUtility.ToAbsolute() is a .NET Framework method. Maybe the MVC one is using it, we would have to check the source...
Hope the helps
If you are doing this conversion within a Controller, then I'd favour VirtualParthUtility.ToAbsolute() over Url.Content().
The benefit comes when you want to unit test the controller actions. Rather than call it directly though, I'd define an interface IPathUtilities, say, with one implementation using VirtualPathUtility methods for the live site, and another using some sort of mock when testing.
If you call VirtualPathUtility directly, then you won't be able to test the action method (you might have thought some clever mocking of HttpContext would get round this, but having tried this myself I couldn't find a way to do it).

javascript and regularexpression?

i have a doubt that whether javascript expression is better or regularexpression is better.
i mean for validation javascript is best or ?How it is different form each other? thank you.
It depends on the kind of validation that you need.
Suppose if you need to compare two dates then regex won't be enough.
This one is a nice read
12 Reasons to Learn and Use Regular Expressions
Surya,
Javascript can help you to build some validation but you should madder what implement the same input validation on the server side.
So it's only to make it more user friendly, so you should start implementing your server input validation when you are done and if you have time add the javascript validation.

Resources