本文整理匯總了Java中javax.faces.application.FacesMessage.getSummary方法的典型用法代碼示例。如果您正苦於以下問題:Java FacesMessage.getSummary方法的具體用法?Java FacesMessage.getSummary怎麽用?Java FacesMessage.getSummary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.faces.application.FacesMessage
的用法示例。
在下文中一共展示了FacesMessage.getSummary方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAsString
import javax.faces.application.FacesMessage; //導入方法依賴的package包/類
/**
* Formats the value by inserting space after every four characters for
* better readability if they don't already exist. In the process converts
* any
* <code>"-"</code> characters into blanks for consistency.
*/
@Override
public String getAsString(FacesContext context,
UIComponent component, Object value)
throws ConverterException {
String inputVal = null;
logger.log(Level.INFO, "Entering CreditCardConverter.getAsString");
if (value == null) {
return "";
}
// Value must be of a type that can be cast to a String.
try {
inputVal = (String) value;
} catch (ClassCastException ce) {
FacesMessage errMsg = new FacesMessage(CONVERSION_ERROR_MESSAGE_ID);
FacesContext.getCurrentInstance().addMessage(null, errMsg);
throw new ConverterException(errMsg.getSummary());
}
// Insert spaces after every four characters for better
// readability if they are not already present.
char[] input = inputVal.toCharArray();
StringBuilder builder = new StringBuilder(input.length + 3);
for (int i = 0; i < input.length; ++i) {
if (((i % 4) == 0) && (i != 0)) {
if ((input[i] != ' ') || (input[i] != '-')) {
builder.append(" ");
// if there any "-"'s convert them to blanks.
} else if (input[i] == '-') {
builder.append(" ");
}
}
builder.append(input[i]);
}
String convertedValue = builder.toString();
logger.log(Level.INFO, "Converted value is {0}", convertedValue);
return convertedValue;
}