List of usage examples for javax.el ELException getMessage
public String getMessage()
From source file:org.nuxeo.ecm.platform.ui.web.component.file.UIInputFile.java
@Override public void updateModel(FacesContext context) { if (context == null) { throw new IllegalArgumentException(); }//from w ww.j a va 2 s .c om if (!isValid() || !isLocalValueSet()) { return; } ValueExpression ve = getValueExpression("value"); if (ve == null) { return; } try { InputFileInfo local = getFileInfoLocalValue(); String choice = local.getConvertedChoice(); // set blob and filename if (InputFileChoice.DELETE.equals(choice)) { // set filename first to avoid error in case it maps the blob filename ValueExpression vef = getValueExpression("filename"); if (vef != null) { vef.setValue(context.getELContext(), local.getConvertedFilename()); } ve.setValue(context.getELContext(), local.getConvertedBlob()); setValue(null); setLocalValueSet(false); } else if (InputFileChoice.isUploadOrKeepTemp(choice)) { // set blob first to avoid error in case the filename maps the blob filename ve.setValue(context.getELContext(), local.getConvertedBlob()); setValue(null); setLocalValueSet(false); ValueExpression vef = getValueExpression("filename"); if (vef != null) { vef.setValue(context.getELContext(), local.getConvertedFilename()); } } else if (InputFileChoice.KEEP.equals(choice)) { // reset local value setValue(null); setLocalValueSet(false); if (getEditFilename()) { // set filename ValueExpression vef = getValueExpression("filename"); if (vef != null) { vef.setValue(context.getELContext(), local.getConvertedFilename()); } } } return; } catch (ELException e) { String messageStr = e.getMessage(); Throwable result = e.getCause(); while (result != null && result instanceof ELException) { messageStr = result.getMessage(); result = result.getCause(); } FacesMessage message; if (messageStr == null) { message = MessageFactory.getMessage(context, UPDATE_MESSAGE_ID, MessageFactory.getLabel(context, this)); } else { message = new FacesMessage(FacesMessage.SEVERITY_ERROR, messageStr, messageStr); } context.addMessage(getClientId(context), message); setValid(false); } catch (IllegalArgumentException | ConverterException e) { FacesMessage message = MessageFactory.getMessage(context, UPDATE_MESSAGE_ID, MessageFactory.getLabel(context, this)); context.addMessage(getClientId(context), message); setValid(false); } }
From source file:org.nuxeo.ecm.platform.ui.web.component.list.UIEditableList.java
/** * Overridden to handle diff boolean value, see NXP-16515. *//*w w w . ja va2 s .c om*/ public void updateModel(FacesContext context) { if (context == null) { throw new NullPointerException(); } if (!isValid() || !isLocalValueSet()) { return; } ValueExpression ve = getValueExpression("value"); if (ve != null) { Throwable caught = null; FacesMessage message = null; try { Boolean setDiff = getDiff(); if (setDiff) { // set list diff instead of the whole list // FIXME NXP-16515 // EditableModel model = getEditableModel(); // ve.setValue(context.getELContext(), model.getListDiff()); ve.setValue(context.getELContext(), getLocalValue()); } else { ve.setValue(context.getELContext(), getLocalValue()); } setValue(null); setLocalValueSet(false); } catch (ELException e) { caught = e; String messageStr = e.getMessage(); Throwable result = e.getCause(); while (null != result && result.getClass().isAssignableFrom(ELException.class)) { messageStr = result.getMessage(); result = result.getCause(); } if (null == messageStr) { message = MessageFactory.getMessage(context, UPDATE_MESSAGE_ID, MessageFactory.getLabel(context, this)); } else { message = new FacesMessage(FacesMessage.SEVERITY_ERROR, messageStr, messageStr); } setValid(false); } catch (Exception e) { caught = e; message = MessageFactory.getMessage(context, UPDATE_MESSAGE_ID, MessageFactory.getLabel(context, this)); setValid(false); } if (caught != null) { assert message != null; // PENDING(edburns): verify this is in the spec. UpdateModelException toQueue = new UpdateModelException(message, caught); ExceptionQueuedEventContext eventContext = new ExceptionQueuedEventContext(context, toQueue, this, PhaseId.UPDATE_MODEL_VALUES); context.getApplication().publishEvent(context, ExceptionQueuedEvent.class, eventContext); } } }
From source file:org.nuxeo.ecm.platform.ui.web.rest.services.URLPolicyServiceImpl.java
public void appendParametersToRequest(FacesContext facesContext, String pattern) { // try to get doc view from custom mapping DocumentView docView = null;//w w w . j a v a 2s . com ExpressionFactory ef = facesContext.getApplication().getExpressionFactory(); ELContext context = facesContext.getELContext(); HttpServletRequest httpRequest = (HttpServletRequest) facesContext.getExternalContext().getRequest(); // get existing document view from given pattern, else create it URLPatternDescriptor patternDesc = null; if (pattern != null && !"".equals(pattern)) { patternDesc = getURLPatternDescriptor(pattern); } else { // iterate over pattern descriptors, and take the first one that // applies, or use the default one List<URLPatternDescriptor> descs = getURLPatternDescriptors(); boolean applies = false; for (URLPatternDescriptor desc : descs) { String documentViewAppliesExpr = desc.getDocumentViewBindingApplies(); if (!StringUtils.isBlank(documentViewAppliesExpr)) { // TODO: maybe put view id to the request to help writing // the EL expression ValueExpression ve = ef.createValueExpression(context, documentViewAppliesExpr, Object.class); try { Object res = ve.getValue(context); if (Boolean.TRUE.equals(res)) { applies = true; } } catch (ELException e) { if (log.isDebugEnabled()) { log.debug(String.format("Error executing expression '%s' for " + "url pattern '%s': %s", documentViewAppliesExpr, desc.getName(), e.getMessage())); } } } if (applies) { patternDesc = desc; break; } } if (patternDesc == null) { // default on the default pattern desc patternDesc = getDefaultPatternDescriptor(); } } if (patternDesc != null) { // resolved doc view values thanks to bindings Object docViewValue = null; String documentViewBinding = patternDesc.getDocumentViewBinding(); if (!StringUtils.isBlank(documentViewBinding)) { ValueExpression ve = ef.createValueExpression(context, documentViewBinding, Object.class); docViewValue = ve.getValue(context); } if (docViewValue == null) { documentViewBinding = patternDesc.getNewDocumentViewBinding(); if (!StringUtils.isBlank(documentViewBinding)) { ValueExpression ve = ef.createValueExpression(context, documentViewBinding, Object.class); docViewValue = ve.getValue(context); } } if (docViewValue instanceof DocumentView) { docView = (DocumentView) docViewValue; // set pattern name in case it was just created docView.setPatternName(patternDesc.getName()); ValueBindingDescriptor[] bindings = patternDesc.getValueBindings(); if (bindings != null) { for (ValueBindingDescriptor binding : bindings) { if (!binding.getCallGetter()) { continue; } String paramName = binding.getName(); String expr = binding.getExpression(); try { Object value; if (ComponentTagUtils.isValueReference(expr)) { ValueExpression ve = ef.createValueExpression(context, expr, Object.class); value = ve.getValue(context); } else { value = expr; } if (docView != null) { // do not set attributes on the request as // document view will be put in the request // anyway docView.addParameter(paramName, (String) value); } else { httpRequest.setAttribute(paramName, value); } } catch (ELException e) { log.error( String.format("Could not get parameter %s from expression %s", paramName, expr), e); } } } } } // save document view to the request setDocumentViewInRequest(httpRequest, docView); }
From source file:org.richfaces.component.UIDatascroller.java
private void updateModel(int newPage) { UIData dataTable = getDataTable();//w ww. j a va 2 s . c o m if (isRendered(dataTable)) { dataTable.setFirst((newPage - 1) * getRows(dataTable)); } Map<String, Object> attributes = dataTable.getAttributes(); attributes.put(SCROLLER_STATE_ATTRIBUTE, newPage); FacesContext context = getFacesContext(); ValueExpression ve = getValueExpression("page"); if (ve != null) { try { ve.setValue(context.getELContext(), newPage); attributes.remove(SCROLLER_STATE_ATTRIBUTE); } catch (ELException e) { String messageStr = e.getMessage(); Throwable result = e.getCause(); while (null != result && result.getClass().isAssignableFrom(ELException.class)) { messageStr = result.getMessage(); result = result.getCause(); } FacesMessage message; if (null == messageStr) { message = MessageUtil.getMessage(context, UIInput.UPDATE_MESSAGE_ID, new Object[] { MessageUtil.getLabel(context, this) }); } else { message = new FacesMessage(FacesMessage.SEVERITY_ERROR, messageStr, messageStr); } context.getExternalContext().log(message.getSummary(), result); context.addMessage(getClientId(context), message); context.renderResponse(); } catch (IllegalArgumentException e) { FacesMessage message = MessageUtil.getMessage(context, UIInput.UPDATE_MESSAGE_ID, new Object[] { MessageUtil.getLabel(context, this) }); context.getExternalContext().log(message.getSummary(), e); context.addMessage(getClientId(context), message); context.renderResponse(); } catch (Exception e) { FacesMessage message = MessageUtil.getMessage(context, UIInput.UPDATE_MESSAGE_ID, new Object[] { MessageUtil.getLabel(context, this) }); context.getExternalContext().log(message.getSummary(), e); context.addMessage(getClientId(context), message); context.renderResponse(); } } }
From source file:org.sonar.plugins.web.checks.scripting.UnifiedExpressionCheck.java
private void validateExpression(TagNode element, Attribute attribute) { ExpressionLanguageContext context = new ExpressionLanguageContext(element); ExpressionBuilder builder = new ExpressionBuilder(attribute.getValue(), context); try {/* ww w . j a v a 2 s . c o m*/ builder.createValueExpression(Object.class); } catch (ELException e) { if (e.getMessage().startsWith("Error")) { createViolation(element.getStartLinePosition(), getRule().getDescription() + ": " + e.getMessage()); } } }