List of usage examples for javax.el ValueExpression getType
public abstract Class<?> getType(ELContext context);
From source file:org.nuxeo.ecm.platform.ui.web.binding.alias.AliasValueExpression.java
@Override public Class<?> getType(ELContext context) { ValueExpression ve = resolveExpression(context); if (ve != null) { return ve.getType(context); }//from www.j a v a 2 s .co m return Object.class; }
From source file:org.primefaces.extensions.converter.JsonConverter.java
public Object getAsObject(FacesContext context, UIComponent component, String value) { java.lang.reflect.Type objType; if (getType() == null) { ValueExpression expression = component.getValueExpression("value"); objType = expression.getType(context.getELContext()); } else {/*from w w w . j a v a2 s . co m*/ objType = getObjectType(getType().trim(), false); } return GsonConverter.getGson().fromJson(value, objType); }
From source file:org.rhq.enterprise.gui.common.upload.UploadRenderer.java
public void decode(FacesContext context, UIComponent component) { ExternalContext external = context.getExternalContext(); HttpServletRequest request = (HttpServletRequest) external.getRequest(); String clientId = component.getClientId(context); FileItem item = (FileItem) request.getAttribute(clientId); Object newValue;//from w ww . jav a 2 s . c o m ValueExpression valueExpression = component.getValueExpression("value"); if (valueExpression != null) { Class valueType = valueExpression.getType(context.getELContext()); if (valueType == byte[].class) { newValue = item.get(); } else if (valueType == InputStream.class) { try { newValue = item.getInputStream(); } catch (IOException ex) { throw new FacesException(ex); } } else { String encoding = request.getCharacterEncoding(); if (encoding != null) { try { newValue = item.getString(encoding); } catch (UnsupportedEncodingException ex) { newValue = item.getString(); } } else { newValue = item.getString(); } } ((EditableValueHolder) component).setSubmittedValue(newValue); ((EditableValueHolder) component).setValid(true); } Object target = component.getAttributes().get("target"); if (target != null) { File file; if (target instanceof File) { file = (File) target; } else { ServletContext servletContext = (ServletContext) external.getContext(); String realPath = servletContext.getRealPath(target.toString()); file = new File(realPath); } try { item.write(file); } catch (Exception ex) { throw new FacesException(ex); } } }
From source file:org.richfaces.component.UICalendar.java
public void updateCurrentDate(FacesContext context, Object currentDate) { if (context == null) { throw new NullPointerException(); }//from w w w. ja v a2 s . c o m // RF-1073 try { ValueExpression ve = getValueExpression("currentDate"); if (ve != null) { ELContext elContext = context.getELContext(); if (ve.getType(elContext).equals(String.class)) { DateTimeConverter convert = new DateTimeConverter(); convert.setLocale(getAsLocale(getLocale())); convert.setPattern(getDatePattern()); ve.setValue(context.getELContext(), convert.getAsString(context, this, currentDate)); return; } else if (ve.getType(elContext).equals(Calendar.class)) { Calendar c = Calendar.getInstance(); c.setTime((Date) currentDate); ve.setValue(elContext, c); return; } else { ve.setValue(elContext, currentDate); return; } } else { setCurrentDate(currentDate); } } catch (Exception e) { setValid(false); // XXX nick - kaa - add log.debug(...) if (log.isDebugEnabled()) { log.debug(" updateCurrentDate method throws exception: " + e.toString(), e); } e.printStackTrace(); String messageString = e.toString(); FacesMessage message = new FacesMessage(messageString); message.setSeverity(FacesMessage.SEVERITY_ERROR); context.addMessage(getClientId(context), message); } }
From source file:org.richfaces.renderkit.CalendarRendererBase.java
@Override public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws ConverterException { if ((context == null) || (component == null)) { throw new NullPointerException(); }/*www . j a v a 2 s . com*/ // skip conversion of already converted date if (submittedValue instanceof Date) { return (Date) submittedValue; } // Store submitted value in the local variable as a string String newValue = (String) submittedValue; // if we have no local value, try to get the valueExpression. ValueExpression valueExpression = component.getValueExpression("value"); Converter converter = null; UICalendar calendar = (UICalendar) component; converter = calendar.getConverter(); if ((converter == null) && (valueExpression != null)) { Class<? extends Object> converterType = valueExpression.getType(context.getELContext()); if ((converterType != null) && (converterType != Object.class)) { // if getType returns a type for which we support a default // conversion, acquire an appropriate converter instance. converter = getConverterForClass(converterType, context); } } // in case the converter hasn't been set, try to use default DateTimeConverter if (converter == null) { converter = createDefaultConverter(); } setupDefaultConverter(converter, calendar); return converter.getAsObject(context, component, newValue); }
From source file:yoyo.framework.screen.iface.jsf.UploadRenderer.java
/** {@inheritDoc} */ @Override/*from w ww .ja v a 2 s . c om*/ public void decode(final FacesContext context, final UIComponent component) { final ExternalContext external = context.getExternalContext(); final HttpServletRequest request = (HttpServletRequest) external.getRequest(); final String clientId = component.getClientId(context); final FileItem item = (FileItem) request.getAttribute(clientId); if ((item == null) || StringUtils.isEmpty(item.getName())) { return; } LOG.fine("item:" + item); final ValueExpression valueExpr = component.getValueExpression("value"); if (valueExpr != null) { ((EditableValueHolder) component).setSubmittedValue( findSubmittedValue(request, item, valueExpr.getType(context.getELContext()))); ((EditableValueHolder) component).setValid(true); } final Object target = component.getAttributes().get("target"); LOG.fine("target=" + target); if (target != null) { File file; if (target instanceof File) { file = (File) target; } else { final ServletContext servletContext = (ServletContext) external.getContext(); final String itemName = item.getName(); final String dirPath = "WEB-INF/" + target; LOG.fine("dirPath=" + dirPath); new File(servletContext.getRealPath(dirPath)).mkdirs(); final String filePath = dirPath + "/" + itemName; final String realPath = servletContext.getRealPath(filePath); LOG.fine("realPath=" + realPath); file = new File(realPath); } // UGH ?????????commons-upload? try { LOG.fine("item.write"); item.write(file); } catch (final Exception ex) { throw new FacesException(ex); } } }