@Override public DocumentModel getSearchDocumentModel() { if (searchDocumentModel == null) { if (searchDocumentModelBinding != null) { // initialize from binding FacesContext context = FacesContext.getCurrentInstance(); Object value = ComponentTagUtils.resolveElExpression(context, searchDocumentModelBinding); if (value != null && !(value instanceof DocumentModel)) { log.error( "Error processing expression '" + searchDocumentModelBinding + "', result is not a DocumentModel: " + value); } else { setSearchDocumentModel((DocumentModel) value); } } if (searchDocumentModel == null) { // generate a bare document model of given type String docType = getSearchDocumentModelType(); if (docType != null) { DocumentModel bareDoc = DocumentModelFactory.createDocumentModel(docType); setSearchDocumentModel(bareDoc); } } } return searchDocumentModel; }
@Override public Object getValue(ELContext context) { ELContext nxcontext = getLocalContext(context); Object res = null; if (originalValueExpression != null) { res = originalValueExpression.getValue(nxcontext); if (res instanceof String) { String expression = (String) res; if (ComponentTagUtils.isValueReference(expression)) { FacesContext faces = FacesContext.getCurrentInstance(); Application app = faces.getApplication(); ExpressionFactory factory = app.getExpressionFactory(); ValueExpression newExpr = factory.createValueExpression(nxcontext, expression, expectedType); try { res = newExpr.getValue(nxcontext); } catch (ELException err) { log.error("Error processing expression " + expression + ": " + err); res = null; } } else { res = expression; } } } return res; }
protected Long resolvePageSize() { if (pageSizeBinding == null) { return null; } FacesContext context = FacesContext.getCurrentInstance(); Object previousSearchDocValue = addSearchDocumentToELContext(context); try { Object value = ComponentTagUtils.resolveElExpression(context, pageSizeBinding); if (value == null) { return null; } if (value instanceof String) { try { return Long.valueOf((String) value); } catch (NumberFormatException e) { log.error( "Error processing expression '" + pageSizeBinding + "', result is not a Long: '" + value + "'"); } } else if (value instanceof Number) { return Long.valueOf(((Number) value).longValue()); } return null; } finally { removeSearchDocumentFromELContext(context, previousSearchDocValue); } }
@Override public String getCacheKey() { FacesContext context = FacesContext.getCurrentInstance(); Object value = ComponentTagUtils.resolveElExpression(context, cacheKey); if (value != null && !(value instanceof String)) { log.error("Error processing expression '" + cacheKey + "', result is not a String: " + value); } return (String) value; }
@SuppressWarnings({"unchecked", "rawtypes"}) protected List<SortInfo> resolveSortInfos() { if (sortInfosBinding == null) { return null; } FacesContext context = FacesContext.getCurrentInstance(); Object previousSearchDocValue = addSearchDocumentToELContext(context); try { Object value = ComponentTagUtils.resolveElExpression(context, sortInfosBinding); if (value != null && !(value instanceof List)) { log.error( "Error processing expression '" + sortInfosBinding + "', result is not a List: '" + value + "'"); } if (value == null) { return null; } List<SortInfo> res = new ArrayList<SortInfo>(); List listValue = (List) value; for (Object listItem : listValue) { if (listItem instanceof SortInfo) { res.add((SortInfo) listItem); } else if (listItem instanceof Map) { // XXX: MapProperty does not implement containsKey, so // resolve // value instead if (listItem instanceof MapProperty) { try { listItem = ((MapProperty) listItem).getValue(); } catch (ClassCastException | PropertyException e) { log.error("Cannot resolve sort info item: " + listItem, e); } } Map map = (Map) listItem; SortInfo sortInfo = SortInfo.asSortInfo(map); if (sortInfo != null) { res.add(sortInfo); } else { log.error("Cannot resolve sort info item: " + listItem); } } else { log.error("Cannot resolve sort info item: " + listItem); } } if (res.isEmpty()) { return null; } return res; } finally { removeSearchDocumentFromELContext(context, previousSearchDocValue); } }
@Override public void setCurrentResultLayoutColumns(final List<String> resultColumns) { if (isBlank(resultColumnsBinding) || !ComponentTagUtils.isStrictValueReference(resultColumnsBinding)) { // set local values currentResultLayoutColumns = resultColumns; } else { resolveWithSearchDocument( new Function<FacesContext, Object>() { @Override public Object apply(FacesContext ctx) { ComponentTagUtils.applyValueExpression(ctx, resultColumnsBinding, resultColumns); return null; } }); } }
@Override public Object[] getQueryParameters() { if (queryParameters == null) { return null; } FacesContext context = FacesContext.getCurrentInstance(); Object previousSearchDocValue = addSearchDocumentToELContext(context); try { Object[] res = new Object[queryParameters.length]; for (int i = 0; i < queryParameters.length; i++) { res[i] = ComponentTagUtils.resolveElExpression(context, queryParameters[i]); } return res; } finally { removeSearchDocumentFromELContext(context, previousSearchDocValue); } }
/** * Returns true if a reference tag attribute should be created for given property value. * * <p>Reference tag attributes are using a non-literal EL expression so that this property value * is not kept (cached) in the component on ajax refresh. * * <p>Of course property values already representing an expression cannot be mapped as is because * they would need to be resolved twice. * * <p>Converters and validators cannot be referenced either because components expect * corresponding value expressions to resolve to a {@link Converter} or {@link Validator} instance * (instead of the converter of validator id). */ public boolean shouldCreateReferenceAttribute(String key, Serializable value) { // FIXME: NXP-7004: make this configurable per widget type and mode or // JSF component if ((value instanceof String) && (ComponentTagUtils.isValueReference((String) value) || "converter".equals(key) || "validator".equals(key) // size is mistaken for the properties map size because // of jboss el resolvers || "size".equals(key) // richfaces calendar does not resolve EL expressions // correctly || "showApplyButton".equals(key) || "defaultTime".equals(key))) { return false; } return true; }
/** * Adds a default disabled "select a value" option if widget is not required. * * @since 6.0 */ protected FaceletHandler getFirstHandler( FaceletContext ctx, FaceletHandlerHelper helper, Widget widget, FaceletHandler nextHandler) { Object doNotDisplay = widget.getProperty(SelectPropertyMappings.notDisplayDefaultOption.name()); if (doNotDisplay != null) { if (Boolean.TRUE.equals(doNotDisplay)) { return null; } if (doNotDisplay instanceof String) { Object res = ComponentTagUtils.resolveElExpression(ctx, (String) doNotDisplay); if ((res instanceof Boolean && Boolean.TRUE.equals(res)) || (res instanceof String && Boolean.parseBoolean((String) res))) { return null; } } } String bundleName = ctx.getFacesContext().getApplication().getMessageBundle(); String localizedExpression = "#{" + bundleName + "['label.vocabulary.selectValue']}"; WidgetSelectOption selectOption = new WidgetSelectOptionImpl("", "", localizedExpression, "", Boolean.FALSE, Boolean.TRUE); return getBareOptionFaceletHandler(ctx, helper, widget, selectOption, nextHandler); }
public void setCurrentResultLayout(final ContentViewLayout layout, boolean resetLayoutColumn) { if (!isBlank(resultLayoutBinding) && ComponentTagUtils.isStrictValueReference(resultLayoutBinding)) { resolveWithSearchDocument( new Function<FacesContext, Object>() { @Override public Object apply(FacesContext ctx) { ComponentTagUtils.applyValueExpression( ctx, resultLayoutBinding, layout == null ? null : layout.getName()); return null; } }); } // still set current result layout value currentResultLayoutSet = true; currentResultLayout = layout; if (resetLayoutColumn) { // reset corresponding columns setCurrentResultLayoutColumns(null); } }