List of usage examples for javax.el ValueExpression getExpressionString
public abstract String getExpressionString();
From source file:org.apache.myfaces.component.html.ext.AbstractHtmlDataTable.java
/** * *///from w ww . ja v a 2s. c o m protected String getSortPropertyFromEL(UIComponent component) { if (getVar() == null) { log.warn( "There is no 'var' specified on the dataTable, sort properties cannot be determined automaticaly."); return null; } for (Iterator<UIComponent> iter = component.getChildren().iterator(); iter.hasNext();) { UIComponent aChild = (UIComponent) iter.next(); if (aChild.isRendered()) { ValueExpression vb = aChild.getValueExpression("value"); if (vb != null) { String expressionString = vb.getExpressionString(); int varIndex = expressionString.indexOf(getVar() + "."); if (varIndex != -1) { int varEndIndex = varIndex + getVar().length(); String tempProp = expressionString.substring(varEndIndex + 1, expressionString.length()); StringTokenizer tokenizer = new StringTokenizer(tempProp, " +[]{}-/*|?:&<>!=()%"); if (tokenizer.hasMoreTokens()) return tokenizer.nextToken(); } } else { String sortProperty = getSortPropertyFromEL(aChild); if (sortProperty != null) return sortProperty; } } } return null; }
From source file:org.apache.myfaces.custom.aliasbean.Alias.java
private void computeEvaluatedExpression(FacesContext facesContext) { if (evaluatedExpression != null) return;// w w w . ja va 2 s. c o m ValueExpression valueVB = null; if (_valueExpression == null) { valueVB = _aliasComponent.getValueExpression("value"); _valueExpression = valueVB.getExpressionString(); } if (valueVB == null) { if (_valueExpression.startsWith("#{")) { valueVB = facesContext.getApplication().getExpressionFactory() .createValueExpression(facesContext.getELContext(), _valueExpression, Object.class); evaluatedExpression = valueVB.getValue(facesContext.getELContext()); } else { evaluatedExpression = _valueExpression; } } else { evaluatedExpression = valueVB.getValue(facesContext.getELContext()); } }
From source file:org.apache.myfaces.custom.aliasbean.Alias.java
/** * Activate this alias (ie create the temporary name). *//*from w w w. j a v a 2 s. c om*/ void make(FacesContext facesContext) { if (_active) return; ValueExpression aliasVB; if (_aliasBeanExpression == null) { aliasVB = _aliasComponent.getValueExpression("alias"); if (aliasVB == null) return; _aliasBeanExpression = aliasVB.getExpressionString(); if (_aliasBeanExpression == null) return; } else { aliasVB = facesContext.getApplication().getExpressionFactory() .createValueExpression(facesContext.getELContext(), _aliasBeanExpression, Object.class); } computeEvaluatedExpression(facesContext); aliasVB.setValue(facesContext.getELContext(), evaluatedExpression); _active = true; log.debug("makeAlias: " + _valueExpression + " = " + _aliasBeanExpression); }
From source file:org.apache.myfaces.tomahawk.util.ErrorPageWriter.java
private static void writeAttributes(Writer writer, UIComponent c) { try {/*w ww . ja va2s. com*/ BeanInfo info = Introspector.getBeanInfo(c.getClass()); PropertyDescriptor[] pd = info.getPropertyDescriptors(); Method m = null; Object v = null; String str = null; for (int i = 0; i < pd.length; i++) { if (pd[i].getWriteMethod() != null && Arrays.binarySearch(IGNORE, pd[i].getName()) < 0) { m = pd[i].getReadMethod(); try { v = m.invoke(c, null); if (v != null) { if (v instanceof Collection || v instanceof Map || v instanceof Iterator) { continue; } writer.write(" "); writer.write(pd[i].getName()); writer.write("=\""); if (v instanceof Expression) { str = ((Expression) v).getExpressionString(); } writer.write(str.replaceAll("<", TS)); writer.write("\""); } } catch (Exception e) { // do nothing } } } ValueExpression binding = c.getValueExpression("binding"); if (binding != null) { writer.write(" binding=\""); writer.write(binding.getExpressionString().replaceAll("<", TS)); writer.write("\""); } } catch (Exception e) { // do nothing } }
From source file:org.nuxeo.ecm.platform.ui.web.validator.DocumentConstraintValidator.java
@Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { if (context == null) { throw new NullPointerException(); }//w w w .j av a 2s . c o m if (component == null) { throw new NullPointerException(); } ValueExpression ve = component.getValueExpression("value"); if (ve == null) { return; } ValueExpressionAnalyzer expressionAnalyzer = new ValueExpressionAnalyzer(ve); ValueReference vref = expressionAnalyzer.getReference(context.getELContext()); if (log.isDebugEnabled()) { log.debug(String.format("Validating value '%s' for expression '%s', base=%s, prop=%s", value, ve.getExpressionString(), vref.getBase(), vref.getProperty())); } if (isResolvable(vref, ve)) { List<ConstraintViolation> violations = doValidate(context, vref, ve, value); if (violations != null && !violations.isEmpty()) { Locale locale = context.getViewRoot().getLocale(); if (violations.size() == 1) { ConstraintViolation v = violations.iterator().next(); String msg = v.getMessage(locale); throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg)); } else { Set<FacesMessage> messages = new LinkedHashSet<FacesMessage>(violations.size()); for (ConstraintViolation v : violations) { String msg = v.getMessage(locale); messages.add(new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg)); } throw new ValidatorException(messages); } } } }
From source file:org.nuxeo.ecm.platform.ui.web.validator.DocumentConstraintValidator.java
@SuppressWarnings("rawtypes") private boolean isResolvable(ValueReference ref, ValueExpression ve) { if (ve == null || ref == null) { return false; }/*w w w . jav a 2 s. c o m*/ Object base = ref.getBase(); if (base != null) { Class baseClass = base.getClass(); if (baseClass != null) { if (DocumentPropertyContext.class.isAssignableFrom(baseClass) || (Property.class.isAssignableFrom(baseClass)) || (ProtectedEditableModel.class.isAssignableFrom(baseClass)) || (ListItemMapper.class.isAssignableFrom(baseClass))) { return true; } } } if (log.isDebugEnabled()) { log.debug(String.format("NOT validating %s, base=%s, prop=%s", ve.getExpressionString(), base, ref.getProperty())); } return false; }
From source file:org.nuxeo.ecm.platform.ui.web.validator.DocumentConstraintValidator.java
protected List<ConstraintViolation> doValidate(FacesContext context, ValueReference vref, ValueExpression e, Object value) {/*from ww w. jav a 2 s .c om*/ DocumentValidationService validationService = Framework.getService(DocumentValidationService.class); // document validation DocumentValidationReport report = null; if (!validationService.isActivated(CTX_JSFVALIDATOR, null)) { return null; } XPathAndField field = resolveField(context, vref, e); if (field != null) { boolean validateSubs = getHandleSubProperties().booleanValue(); // use the xpath to validate the field // this allow to get the custom message defined for field if there's error report = validationService.validate(field.xpath, value, validateSubs); if (log.isDebugEnabled()) { log.debug(String.format("VALIDATED value '%s' for expression '%s', base=%s, prop=%s", value, e.getExpressionString(), vref.getBase(), vref.getProperty())); } } else { if (log.isDebugEnabled()) { log.debug(String.format("NOT Validating value '%s' for expression '%s', base=%s, prop=%s", value, e.getExpressionString(), vref.getBase(), vref.getProperty())); } } if (report != null && report.hasError()) { return report.asList(); } return null; }
From source file:org.nuxeo.ecm.platform.ui.web.validator.DocumentConstraintValidator.java
protected XPathAndField resolveField(FacesContext context, ValueReference vref, ValueExpression ve) { Object base = vref.getBase(); Object propObj = vref.getProperty(); if (propObj != null && !(propObj instanceof String)) { // ignore cases where prop would not be a String return null; }/*w ww.j a v a 2s . c o m*/ String xpath = null; Field field = null; String prop = (String) propObj; Class<?> baseClass = base.getClass(); if (DocumentPropertyContext.class.isAssignableFrom(baseClass)) { DocumentPropertyContext dc = (DocumentPropertyContext) base; xpath = dc.getSchema() + ":" + prop; field = getField(xpath); } else if (Property.class.isAssignableFrom(baseClass)) { xpath = ((Property) base).getPath() + "/" + prop; field = getField(((Property) base).getField(), prop); } else if (ProtectedEditableModel.class.isAssignableFrom(baseClass)) { ProtectedEditableModel model = (ProtectedEditableModel) base; ValueExpression listVe = model.getBinding(); ValueExpressionAnalyzer expressionAnalyzer = new ValueExpressionAnalyzer(listVe); ValueReference listRef = expressionAnalyzer.getReference(context.getELContext()); if (isResolvable(listRef, listVe)) { XPathAndField parentField = resolveField(context, listRef, listVe); if (parentField != null) { field = getField(parentField.field, "*"); if (parentField.xpath == null) { xpath = field.getName().getLocalName(); } else { xpath = parentField.xpath + "/" + field.getName().getLocalName(); } } } } else if (ListItemMapper.class.isAssignableFrom(baseClass)) { ListItemMapper mapper = (ListItemMapper) base; ProtectedEditableModel model = mapper.getModel(); ValueExpression listVe; if (model.getParent() != null) { // move one level up to resolve parent list binding listVe = model.getParent().getBinding(); } else { listVe = model.getBinding(); } ValueExpressionAnalyzer expressionAnalyzer = new ValueExpressionAnalyzer(listVe); ValueReference listRef = expressionAnalyzer.getReference(context.getELContext()); if (isResolvable(listRef, listVe)) { XPathAndField parentField = resolveField(context, listRef, listVe); if (parentField != null) { field = getField(parentField.field, prop); if (field == null || field.getName() == null) { // it should not happen but still, just in case return null; } if (parentField.xpath == null) { xpath = field.getName().getLocalName(); } else { xpath = parentField.xpath + "/" + field.getName().getLocalName(); } } } } else { log.error(String.format("Cannot validate expression '%s, base=%s'", ve.getExpressionString(), base)); } // cleanup / on begin or at end if (xpath != null) { xpath = StringUtils.strip(xpath, "/"); } else if (field == null && xpath == null) { return null; } return new XPathAndField(field, xpath); }
From source file:org.primefaces.component.imagecropper.ImageCropperRenderer.java
/** * Attempt to obtain the resource from the server by parsing the valueExpression of the image attribute. Returns null * if the valueExpression is not of the form #{resource['path/to/resource']} or #{resource['library:name']}. Otherwise * returns the value obtained by ResourceHandler.createResource(). *//*from w w w. j a v a2s . com*/ private Resource getImageResource(FacesContext facesContext, ImageCropper imageCropper) { Resource resource = null; ValueExpression imageValueExpression = imageCropper .getValueExpression(ImageCropper.PropertyKeys.image.toString()); if (imageValueExpression != null) { String imageValueExpressionString = imageValueExpression.getExpressionString(); if (imageValueExpressionString.matches("^[#][{]resource\\['[^']+'\\][}]$")) { imageValueExpressionString = imageValueExpressionString.replaceFirst("^[#][{]resource\\['", ""); imageValueExpressionString = imageValueExpressionString.replaceFirst("'\\][}]$", ""); String resourceLibrary = null; String resourceName; String[] resourceInfo = imageValueExpressionString.split(":"); if (resourceInfo.length == 2) { resourceLibrary = resourceInfo[0]; resourceName = resourceInfo[1]; } else { resourceName = resourceInfo[0]; } if (resourceName != null) { Application application = facesContext.getApplication(); ResourceHandler resourceHandler = application.getResourceHandler(); if (resourceLibrary != null) { resource = resourceHandler.createResource(resourceName, resourceLibrary); } else { resource = resourceHandler.createResource(resourceName); } } } } return resource; }
From source file:org.primefaces.extensions.component.sheet.Sheet.java
/** * Gets the rendered col index of the column corresponding to the current sortBy. This is used to keep track of the current sort column in the page. * * @return/*from w w w.j ava 2 s . co m*/ */ public int getSortColRenderIndex() { final ValueExpression veSortBy = getValueExpression(PropertyKeys.sortBy.name()); if (veSortBy == null) { return -1; } final String sortByExp = veSortBy.getExpressionString(); int colIdx = 0; for (final SheetColumn column : getColumns()) { if (!column.isRendered()) { continue; } final ValueExpression veCol = column.getValueExpression(PropertyKeys.sortBy.name()); if (veCol != null) { if (veCol.getExpressionString().equals(sortByExp)) { return colIdx; } } colIdx++; } return -1; }