Grails Validation Errors - Developer vs User - validation

What is the best way to convert the developer-oriented validation error list you receive from calling validate() on a Grails domain object into user-oriented error messages?
Example:
Property [email] of class [class testproj.AuthUser] with value [x] is not a valid e-mail address
would rather have it read:
Email given is not a valid e-mail address
Is there anything built-in that already does this?

the messages.properties files in grails-app/i18n
check out this documentation
http://grails.org/doc/latest/guide/7.%20Validation.html
To get all the error codes, look here http://grails.org/doc/latest/ref/Constraints/email.html. Enable the quick nav on the right. At the bottom of every constraint is the properties key that you use to change the error message.

There is also a nice plugin called:
grails install-plugin i18n-templates
which can be found here http://www.grails.org/plugin/i18n-templates
e.g. you have a Domain class in 'org.example.User' and you want to specify the localization messages. Use the following command:
grails generate-i18n-messages org.example.User
This will generate a list of possible messages for you in the console.
Copy and paste this output into your messages.properties for the English language and in every other message.properties for the language you want to have localizations.
Then you just have to edit these property-files in order to have your page localized.
Eclipse/STS has a nice GUI, which makes localization of these property-files even faster.
Greetings,
Jan

Related

Accept-language sent from browser does not change JSF validation messages locales

In the JSF app I'm working on we use message bundles and locales extensivelly. Nearly all labels are defined in a set of *.properties file, there is one file for each language, etc. This works great, whenever the user changes its language preferences on the browser and refreshes the page, those labels change accordingly.
The only labels that do not change are the 'native' JSF validation messages. Those messages are always on the language defined in the JVM during server startup (we use JBoss 7.1 and eap 6.3). So, for example, if in the startup script the this is defined: -Duser.language=en the validation messages will always be in English.
example: Validation Error: Value is required.
If, however we change the property to -Duser.language=pt the validation messages will come up in portuguese.
example: Erro de validação: Valor é necessário.
All the other labels do not have that behavior, so they do change according to the browser's language preference.
We did not specify custom validation messages anywhere.
In faces-config.xml we have the following:
<locale-config>
<default-locale>pt</default-locale>
<supported-locale>pt</supported-locale>
<supported-locale>en</supported-locale>
</locale-config>
If I understand what you're asking right, it sounds like what you're wanting is
message bundles.
A message bundle works like a resource bundle does, except they apply to warnings and errors.
I believe the following answer will help you: https://stackoverflow.com/a/2668602/4042348

How do I run/call/kickoff an external program (custom code) whenever certain attributes or objects are added or modified in OpenDJ’s database?

How do I run/call/kickoff an external program (custom code) whenever certain attributes or objects are added or modified in OpenDJ’s database?
Here is my real world need. (Feel free to change my thought direction entirely).
Whenever a new email address gets created or changed in the OpenDJ database I want to initiate some java code that does some email verification/validation (send the “click here” link with a token to prove the user owns the email they just signed up with).
I know, I could use OpenIDM/AM to accomplish this but to take this a step further I need to validate other information and other credentials (custom) which users supply that are not supported by OpenIDM/AM suites.
Initiating/calling custom code upon ADD or MODIFY of specific objects and attributes is what I want and would like to know how to accomplish this. Preferably without having to scrape logs.
Please Help.
Chad
OpenDJ has a plugin interface where you can plug Java calls on Add or Modify. A sample of this kind of plugin is the attribute uniqueness which verifies that some attributes have a unique value in the directory.
The plugin interface javadoc can be found here : http://docs.forgerock.org/en/opendj/2.6.0/javadoc/org/opends/server/api/plugin/DirectoryServerPlugin.html

Error Adding a Switch Mediator inside a Proxy Service in WSO2 Developer Studio

I'm trying to do a simple Proxy Service using the Developer Studio tool from the open-source SOA middleware provider WSO2.
When I drag into the flow a Switch Mediator in the graphical view there is no problem but when I changed to the text view, I'm facing the following error:
Cannot update source view. The following error(s) have been detected
Reason: XPathFactoty#newInstance() failed to create an XPathFactoty for the default object model: http://java.sun.com/jaxp/xpath/dom with the XPathFactotyConfigurationException: javax.xml.xpath.XPathFactotyConfigurationException: java.util.ServiceConfigurationError javax.xml.xpath.XPathFactoty: bundleresource://1013.fwk317983781:21/META-INF/services/javax.xml.xpath.XPathFa ctory:2: Illegal configuration-file syntax
And the XML is empty, so I can't to add any Switch Mediator and get it working with the WSO2 DS.
This is happening with the 3.5.0 and 3.6.0 version of the tool, and I even try one of the sample in the website but with the same result.
Anyone have any reason why this error is happening?
Thank you!
Each switch element needs to have an attribute called 'source'. This is the Xpath attribute that is checked against the criteria in each case. To add the 'source' attribute, type the Xpath and then click 'update' or 'save'. With that required attribute, a valid xml configuration file may be created and viewed as text.
Here is more documentation on the switch mediator: https://docs.wso2.org/display/ESB481/Switch+Mediator

How to customize validation messages in Laravel?

I searched a lot before asking this question but found nothing to help me.
I started using Laravel as a PHP framework. As I started to do form validation, I used the Validator class to manage all my validation and error messages. But I'd like to know how I can customize the error messages (I'd like to put them in another language for example).
The documentation says:
Language strings are stored in files within the resources/lang directory. Within this directory there should be a subdirectory for each language supported by the application.
Just create a directory with the supported language code, and add a validation.php file (it is wise to just copy the one provided in English then start translating).
An example for Spanish translation would be created at resources/lang/es/validation.php. And it will look as follow:
<?php
return array(
"required" => "El campo :attribute es requerido.",
);
After that, you will need to change the default language.
The default language for your application is stored in the app/config/app.php configuration file. You may change the active language at any time using the App::setLocale method.
Example of changing the default language at runtime:
App::setLocale('es');
in laravel 5 the validation.php file comes under the folder resources.
resources/lang/en/validation.php

Check Using JSTL/Spring-MVC tag regarding Spring Binding Error

I am trying to find a way by which i can check if there is any binding error and based on them i want to show some messages to the user in Spring-MVC. i know one way of this like
<spring:hasBindErrors name="userName">
</spring:hasBindErrors>
but this seems to be with respect to a specific filed of my form, what i want is to check if there is any binding error at all for the current input form or not?
i have also experience of Struts2 and they have a very convient method hasError() which allow a developer to see if there is any error at all for the input fields.
Is there such method defined for Spring-MVC validation or not?
Not an expert of Spring-MVC as i have used it very rarely but if i am correct all you want an equivalent of bindingResult.hasErrors() and if i am correct all you need to use
hasBindErrors tag. For more details refer to the doc
hasBindErrors
Hope this might help you

Resources