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,

Wednesday, May 15, 2013

Simple number validation in JSF

There are many ready validator in JSF, eg. <f:validateLongRange />, <f:validateDoubleRange />, <f:validateRegex />, etc.
for more information about JSF validator, please refer here.

to validate number value, we can use the ready made JSF validator, that is <f:validateLongRange /> and <f:validateDoubleRange />

Sample code:
managedBean
private String longValue;
// getter & setter for longValue

private String doubleValue;
// getter & setter for doubleValue;

Monday, May 13, 2013

Team Synchronization with CVS in Java Delopment

Team synchronization is very important is software development to make sure the team are working on the same stuffs and version.
at this moment, CVS is chosen to do the synchronization, more details about CVS please refer wikipedia.
The reason the title only for Java Development because Eclipse is chosen as the CVS client.

A) CVS
  1. Set up CVS sever in Linux
  2. Set up CVS ACL for access right control (coming soon)
  3. Set up CVS client with Eclipse
  4. Sharing project(s) with Eclipse
  5. Checkout project with Eclipse
  6. CVS Branching
  7. Switching CVS repository for a Eclipse workspace.
  8. Mirroring the CVS server

B) SVN
  1. Set up SVN server in Linux
  2. Set up CVS client with Eclipse
  3. Sharing project(s) with Eclipse
  4. Checkout project from SVN server with Eclipse
  5. SVN Branching

C) eGit
  1. Set up eGit server in Linux
  2. Set up eGit client with Eclipse
  3. Sharing project(s) with Eclipse
  4. Checkout project from eGit server with Eclipse
  5. eGit Branching

Done!!


How to switch CVS repository in eclipse

<< Back to CVS tutorial home

Workspace's CVS repository could be changed.
Normally due to upgrading the CVS machine or moving the CVS machine to another data center and hardware failure on the original CVS machine.

After the server migration completed or pointing to the CVS backup server due to hardware failure, configuration from CVS client is pretty simple.

Steps:
1. Window > Open Perspective > Other... > CVS Repository Exploring > OK
Choosing CVS Repository Exploring from perspective

Thursday, May 9, 2013

How to create custom taglib descriptor in a JSF project

A taglib descriptor in JSF is a taglib.xml.
Name the taglib descriptor always start with a word and follow by "taglib.xml", eg. kian.taglib.xml
taglib descriptor allowed us to define our custom namespaceconvertor, validator, composite component, and facelets function.
more details about taglib descriptor could be found here.

Monday, May 6, 2013

How to validate multiple form fields with jQuery validation plugin

jQuery validation plugin is a helpful and easy to use validation tool to validate form.
From the examples shown in the jQuery validation plugin official site, we can see the validation on single form field only.
Credit card validation and Email validation with jQuery in my blog are the single form field validation example.
We can actually validate multiple form fields in one shot with jQuery.

Below is the sample syntax to validate multiple form fields with jQuery validation plugin.
COMMA(,) is the separator of multiple form fields.
<script>
$(document).ready(function(){
  $("#myform").validate({
    rules: {
      field1: {
        email: true
      },
      field2: {
        required: true
      },
      fieldN: {
        creditcard: true
      }
    }
  });
});
</script>

Credit Card validation with jQuery

This is a lightweight and easy to implement credit card validation with jQuery.
With jQuery, server processing is not required; and all the complexities are hide.
another way to validate credit card is with regular expression.

There is only 3 steps to validate credit card number with jQuery.

Sunday, May 5, 2013

How to increase console line number in Eclipse

The objective of this post is to increase the line number in Eclipse console log, so that more information logged and show to us to increase the ability to debug and resolve an issue.

Steps:
1. R-click on the console area > Preferences...
eclipse console preference

2. (a) increase the line number (default 8000) if just to show all more lines console log.
    (b) Uncheck "Limit console output" if want to show all lines of console output
changing console properties

3. click "OK"


Done!!


Saturday, May 4, 2013

Email Validation with jQuery

There are many ways to validate email address, the most famous way could be regular expression.
and now comes an easiest way, it is jQuery validation.

The benefits to do validation with jQuery are light weight, and jQuery performs client side validation, thus it can improve server performance by reducing server calls, and reduce bandwidth.

There are only three steps to go.

Wednesday, May 1, 2013

How to create CVS branch with Eclipse

<< Back to CVS tutorial home

This is a tutorial to show the branching process in CVS server with Eclipse as the CVS client, and this is part Team Synchronization tutorial.

1. Window > Open perspective > Other... > CVS repository exploring > OK

2. R-click on selected project(s) to branch > Add to branch list...
adding CVS branch

3. Enter a Branch name in the Branch Tag dialog > OK
enter new CVS branch name
    p/s: for existing branch, just copy the branch name into the text field.

Output:
new branch in CVS repository


<< Back to CVS tutorial home

Done!!


How to checkout project from CVS with Eclipse

<< Back to CVS tutorial home

This is a tutorial to show the checkout process from CVS server with Eclipse as the CVS client, and this is part Team Synchronization tutorial.

1. File > New > Project... > CVS > Projects from CVS > Next
select Projects from CVS

2. Use existing repository location, choose preferred repository > Next
choose Use existing repository location
    If there are no existing repository, choose Create a new reposity location.

3. Use an existing module, choose one or more modules > Finish, or Next to choose branch other than HEAD.
choose 1 or more project from the module list

4. Next > Next > Refresh Tags > Choose preferred Branch or Version > Finish.
Choose preferred branch or version

5. Wait for the checkout and available to use in workspace.


<< Back to CVS tutorial home

Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...