Saturday, May 25, 2013

jQuery validation plugin localization

The default language for jQuery validation plugin is English.
It could be overridden with the localization js file, eg. es, zh, fr, etc.
Please refer here for the list of supported languages.

To enable languages support, we just need to add other language message js into our webpage (html/jsp/xhtml).
for french
<script type="text/javascript" src="http://jzaefferer.github.io/jquery-validation/localization/messages_fr.js" />
for chinese
<script type="text/javascript" src="http://jzaefferer.github.io/jquery-validation/localization/messages_zh.js" />
Same for other languages, just find the appropriate language js and add the js into the webpage.

Friday, May 24, 2013

How to handle multilingual error messages for jQuery validation plugins

In How to customize error messages for jQuery validation plugin guides us customize error messages for jQuery validation plugin.
But nowadays, multilingual is a requirement for most of the application.
Thus on top of customized messages, we need to provide multilingual support for the error messages.

This article will show an easy way to provide multilingual support for jQuery validation plugin.

The trick is to keep our customized error messages in resource bundle.

Steps:
1.  write the customized error messages in our application's resource bundle. eg, messages.properties
e.g.
invalid_email=Invalid email format

Monday, May 20, 2013

Mirroring CVS server to a backup server


The last step in setting up CVS is to set up the mirror server for disaster recovery, when there are any unexpected event happen, then we can switch to the mirror server immediately without affecting our development.
Steps: 1. create rsync script in the CVS mirror server
  • Install rsync if not already installed
  • write the following rsync script and save it in mirror-cvs.sh
  • rsync -vaz --delete [source-server-ip]:[/path/to/cvs/repo] [/local/path/to/cvs/repo]
2. schedule the rsync script every 30 minutes with the following script
*/30 * * * * /path/to/script/directory/mirror-cvs.sh
for more information about cronjob, please refer here.

3. setup ssh to login without passwd
  • create public and private keys with the following script
ssh-keygen
  • copy the public key to remote host with the following script
ssh-copy-id –I ~/.ssh/id_rsa.pub remote host

Done!!

Sunday, May 19, 2013

How to use jQuery validation plugin in JSF

jQuery validation plugin is a lightweight, easy to use and powerful validation tool.
But when we want to use it with JSF, some special handling are required for it to work, due to the JSF component's clientId.

In this article, Primefaces 3.5 is used, and solution demonstrated below should be suitable for all other JSF implementations.

Steps:
1. Create the form and components that required validation.
<h:form id="myform">
  <p:inputText id="emailAddr" value="#{user.email}" />
</h:form>

2. If the target project is not JSF (strust, servlet, etc), the following syntax used.
<script>
$(document).ready(function(){
$("#myform").validate({
    rules: {
        emailAddr: {
            email: true
            }
        }
    });
});
</script>

Saturday, May 18, 2013

How to customize error messages for jQuery validation plugin

jQuery validation plugin is lightweight and easy to use, the validation rules and error messages are provided by default.
Thus, it's save our time to validate various form fields. eg, credit card, email, etc.
But sometimes, we still customization to it, one of the very common customization is error message.

The option to customize error messages is opened, we can always provide our own error messages.
Here shown a sample for custom error messages.
messages: {
    field: {
        email: "Invalid email format"
    }
}

Complete source,

LinkWithin

Related Posts Plugin for WordPress, Blogger...