Uppercase Converter

“In many situations it’s useful to store some properties in upper case. It’s a common practice of many data modeller and designers which prefer upper case for visible unique keys like codes, names, etc.”

Let’s say we have an unique requirement of changing the inputted string to its Uppercase type. There are indeed 2 ways to salvage this.

1. Using JavaScript.

<h:inputText ... onblur="value=value.toUpperCase()" />

2. Using JSF.

JSF Page:

<h:inputText value="#{exampleTableBean.object.code}" converter="UpperCaseConverter" 
             required="true" requiredMessage="#{msg.error_required_example_code}" />


<?xml version="1.0" encoding="UTF-8"?>

<faces-config version="1.2"			

Converter Class

package com.example.util.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

 * @author k.mutlu
public class UpperCaseConverter implements Converter {
	public Object getAsObject(FacesContext context, UIComponent component, String value) {
		return value.toUpperCase();

	public String getAsString(FacesContext context, UIComponent component, Object value) {
		return value.toString();

“The JS approach is extremely simple. However, this is tamperable by the enduser as it’s performed fully at the client side, under full control of the enduser. The enduser can disable/skip that JS code and/or edit the request parameter before it’s actually being sent to the server side. The JSF approach isn’t tamperable as this is performed fully at the server side, so this results in a more solid and reliable result.

You have to decide based on those facts which one fits the business requirements the best.”






About kaanmutlu

Software Developer - Computer Engineer from Istanbul, Turkey
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

One Response to Uppercase Converter

  1. Diorgenes Morais says:

    Tão bom, que funcionou aqui, congratulations

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s