Portlet Factory, Version 6.1.2


 

Formatter infrastructure

Before adding the code that does the formatting, translating, and validating, you need to facilitate the creation of the various expression lists and some error message text. The SimpleFormatter uses the following member variables for the formatter infrastructure:

private String errorMessage; private WebAppAccess webApp; protected static List formatExpressionList = null; protected static List translateExpressionList = null; protected static List validateExpressionList = null;
// Set constants for format expressions public final static String PHONEDOTS = "Phone # with Dot Separators"; public final static String PHONEDASHES = "Phone # with Dash Separators";
// Build up array of format expression constants private static final String[] formatExpressions = PHONEDOTS, PHONEDASHES
};
// Use the makeList method to build up the expression lists static formatExpressionList = makeList(formatExpressions);
//translateExpressionList = makeList(translateExpressions);
//validateExpressionList = makeList(validateExpressions);
// You can create your own way to build up the expression lists or copy this one protected static List makeList(String[] array) List list = new ArrayList(array.length); for (int i = 0; i < array.length; i++) list.add(array[i]); return list;
}

Also, the IInputFieldFormatter interface declares methods to get and set these resources. The following code shows simple implementations of these methods:

/* These methods are quick implementations of those defined in the IInputFieldFormatter
*/ public void setErrorMessage(String msg) { errorMessage = msg; } public String getErrorMessage() { return errorMessage;} public void setWebAppAccess(WebAppAccess webApp) { this.webApp = webApp; } public WebAppAccess getWebAppAccess() { return webApp; } public void setTranslateSuccessFlag(boolean parm1) { } public boolean getTranslateSuccessFlag() { return true; } public List getFormatExpressionList() { return formatExpressionList; } public List getTranslateExpressionList() { return translateExpressionList; } public List getValidateExpressionList() { return validateExpressionList; }

Parent topic: About creating a formatter class


Library | Support |