Monday, November 1, 2010

ADF Date convert secondary pattern

This will try the second pattern if there is an error with the first. This should
sort out most situations you need else you will need to write a custom tag.

<af:convertDateTime pattern="yyyyMMdd" secondaryPattern="yyyy-MM-dd" />

NOTE: interesting javascript override
Java [custom converter]

public class YourDateConverter
extends DateTimeConverter implements ClientConverter {

public Object getAsObject(
FacesContext facesContext,
UIComponent uiComponent, String string){//do convert here}

public String getAsString(
FacesContext facesContext, UIComponent uiComponent, Object object)
{//do convert here}

public java.lang.String getClientConversion(
javax.faces.context.FacesContext fc,
javax.faces.component.UIComponent c){
String conv = super.getClientConversion(fc, c);
return "new YourDateTimeConverter('dd/MM/yyyy',null,'01/11/2010','DATE')";

function YourDateTimeConverter(
  pattern, locale, exampleString, type, messages) {
    this._exampleString = exampleString;
    this._pattern = pattern;
    this.trconverter =
     new TrDateTimeConverter(
       pattern, locale, exampleString, type, messages);

YourDateTimeConverter.prototype = new TrConverter();

YourDateTimeConverter.prototype.getAsString = function (formatTime) {
  //do your convert here date to string

YourDateTimeConverter.prototype.getAsObject = function (parseString, label) {
  //do your convert here string 2 date

No comments:

Post a Comment