Created
March 11, 2015 22:49
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.faces.application.FacesMessage; | |
import javax.faces.component.UIComponent; | |
import javax.faces.context.FacesContext; | |
import javax.faces.convert.Converter; | |
import javax.faces.convert.ConverterException; | |
public class MobileNumberConverter implements Converter | |
{ | |
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String string) // set | |
{ | |
if ( string == null || string.trim().equals("") ) | |
{ | |
return null; | |
} | |
if(string.length() != 10) | |
{ | |
FacesMessage message = new FacesMessage("You have to enter mobile number in this format [089xxxxxxx]."); | |
message.setSeverity(FacesMessage.SEVERITY_ERROR); | |
throw new ConverterException(message); | |
} | |
String number = string.substring(1, 10); | |
number = "353" + number; | |
return number; | |
} | |
public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object object) // get | |
{ | |
if ( object == null ) | |
{ | |
return ""; | |
} | |
String obj = object.toString(); | |
String number = obj.substring(3, 12); | |
number = "0" + number; | |
return number; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment