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

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

Related

Spring resource bundle customization - use variant with country suffix

I would like to customize the way Spring retrieves resource bundles.
I have the following files:
messagess_it_IT.properties (with Italian messages)
and
messagess.properties (with English ones).
When someone has Accept-Language header set to it, I want messagess_it_IT.properties to be used.
Currently, my app falls back to messagess.properties instead.

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

Redirecting back to Portlet from ResourceMapping in Spring 3 portlets

I am trying to work out a way to provide a CSV download through a Spring 3 Portlet. I have a method that uses the #ResourceMapping annotation to define a handler that takes some report params in the form of a #ModelAttribute, builds the report, and returns it. The catch-22 I am running into is validating the parameters being send in from the client form.
If I make the handler a #ResourceMapping, I can set the headers and write out the report as using the ResourceResponse, but I can't seem to figure out how to redirect the user back to the Portlet view with errors when their input fails validation. However, if I make it an #ActionMapping, I can then check the BindingResults and forward them back to the form as needed, but the ActionResponse doesn't allow me to set the Content-Disposition header nor write out the CSV bytes, which is sort of critical for sending the report back.
I am at a total loss here, as I don't even know what my options are. Is it even possible to do what I am trying to do with a Portlet? Are there other examples I could look at for a possible work-around?
I suggest you to use both #ActionMapping and #ResourceMapping to fulfill your requirement.
As you said you were able to handle the validation errors using the #ActionResponse, I'll tell you how to handle the Resource Streaming.
As you know every #ActionResponse is followed by a #RenderResponse, just return the same view but, with a hidden iframe this time whose src points to the ResourceURL.
Now the Request you receive in #ResourceMapping is something which is already Validated. So, you can now serve your CSV.
I dont know how complex is your UI and if you are using jsp as views in your application. If nicely managed, Validation can be handled by #ResourceMapping.
Thank you

How to use internationalization in Label fields in Screens in Oracle Policy Automation

I am very new to Oracle Policy Automation. I am developing a screen which will give the option to the user to select languages. Based on his/her selection, the next screen should display a welcome message in the language selected.
I have two properties files (one for each language) and I have placed them inside the /classes/configuration folder.
Now, my query is how to invoke these properties files based on user selection and what should I write in the label field so that the messages are dynamically picked up.
Thanks in advance for the help.
I guess you may have figured this out by now.
In OPA the locale has to be set at the start of an interactive session (part of the start investigation URL) and cannot be changed subsequently. The locale specific resource files under configuration will then be used.
Your locale selection screen would probably need to be outside of OPA triggering a session start of the correct type. If you are using OWD then it will actually provide it's own locale selection screen if you try to access a rulebase without specifying the locale to use. We are working on some additional tooling around OWD to make this process a lot more straightforward

Grails Validation Errors - Developer vs User

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

Resources