示例#1
0
 public AppFacesException(String messageCode, Object[] args, Throwable cause) {
   super(cause);
   final FacesContext context = FacesContext.getCurrentInstance();
   final FacesMessage facesMessage = FacesMessageUtil.getMessage(context, messageCode, args);
   String message = facesMessage.getDetail();
   if (message == null) {
     message = facesMessage.getSummary();
   }
   this.messageCode = messageCode;
   this.args = args;
   this.message = message;
   this.facesMessage = facesMessage;
 }
示例#2
0
 public static Object getConvertedValue(
     final FacesContext context, final UIInput component, final Object submittedValue) {
   try {
     final Renderer renderer = getRenderer(context, component);
     if (renderer != null) {
       return renderer.getConvertedValue(context, component, submittedValue);
     } else if (submittedValue instanceof String) {
       return getConvertedUIOutputValue(context, component, submittedValue);
     }
   } catch (final ConverterException e) {
     final FacesMessage facesMessage = e.getFacesMessage();
     if (facesMessage != null) {
       context.addMessage(component.getClientId(context), facesMessage);
     } else {
       final Object[] args = new Object[] {UIComponentUtil.getLabel(component)};
       context.addMessage(
           component.getClientId(context),
           FacesMessageUtil.getMessage(context, UIInput.CONVERSION_MESSAGE_ID, args));
     }
     component.setValid(false);
   }
   return submittedValue;
 }
示例#3
0
 public Object getValue() {
   Object value = super.getValue();
   if (value instanceof SelectItem[] || value instanceof SelectItem) {
     return value;
   }
   List list = new ArrayList();
   boolean nullLabelSet = false;
   if (nullLabelRequired) {
     SelectItem si = new SelectItem();
     si.setValue("");
     final FacesContext context = getFacesContext();
     FacesMessage mes = FacesMessageUtil.getMessage(context, NULL_LABEL_MESSAGE_CODE, null);
     si.setLabel(mes.getSummary());
     list.add(si);
     nullLabelSet = true;
   }
   if (value != null && value.getClass().isArray()) {
     value = Arrays.asList((Object[]) value);
   }
   if (value instanceof Collection) {
     final Collection valueCollection = (Collection) value;
     if (!nullLabelSet && valueCollection.size() == 0) {
       list.add(BLANK_SELECT_ITEM);
     } else {
       for (Iterator it = valueCollection.iterator(); it.hasNext(); ) {
         Object item = it.next();
         if (item instanceof SelectItem) {
           list.add(item);
         } else if (item instanceof Map) {
           Map map = (Map) item;
           SelectItem si = new SelectItem();
           Object itemValueValue = map.get(itemValue);
           if (itemValueValue != null) {
             si.setValue(itemValueValue);
           }
           Object itemLabelValue = map.get(itemLabel);
           if (itemLabelValue == null) {
             itemLabelValue = itemValueValue;
           }
           if (itemLabelValue != null) {
             si.setLabel(itemLabelValue.toString());
           }
           list.add(si);
         } else {
           SelectItem si = new SelectItem();
           BeanDesc bd = BeanDescFactory.getBeanDesc(item.getClass());
           PropertyDesc pd = bd.getPropertyDesc(itemValue);
           Object itemValueValue = (pd.isReadable()) ? pd.getValue(item) : null;
           if (itemValueValue != null) {
             si.setValue(itemValueValue);
           }
           Object itemLabelValue = null;
           if (bd.hasPropertyDesc(itemLabel)) {
             pd = bd.getPropertyDesc(itemLabel);
             itemLabelValue = (pd.isReadable()) ? pd.getValue(item) : null;
           }
           if (itemLabelValue == null) {
             itemLabelValue = itemValueValue;
           }
           if (itemLabelValue != null) {
             si.setLabel(itemLabelValue.toString());
           }
           list.add(si);
         }
       }
     }
   } else if (value instanceof Map) {
     final Map map = (Map) value;
     if (!nullLabelSet && map.size() == 0) {
       list.add(BLANK_SELECT_ITEM);
     } else {
       for (Iterator it = map.keySet().iterator(); it.hasNext(); ) {
         Object key = it.next();
         Object val = map.get(key);
         SelectItem si = new SelectItem();
         if (key != null) {
           si.setLabel(key.toString());
         }
         if (val != null) {
           si.setValue(val);
         }
         list.add(si);
       }
     }
   } else {
     if (!nullLabelSet && value == null) {
       list.add(BLANK_SELECT_ITEM);
     }
   }
   return list;
 }