當前位置: 首頁>>代碼示例>>Java>>正文


Java FacesMessage.getSummary方法代碼示例

本文整理匯總了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;
}
 
開發者ID:wwu-pi,項目名稱:tap17-muggl-javaee,代碼行數:53,代碼來源:CreditCardConverter.java


注:本文中的javax.faces.application.FacesMessage.getSummary方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。