Esempio n. 1
0
 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);
   }
 }
Esempio n. 2
0
 @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;
 }
Esempio n. 3
0
 @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;
 }
Esempio n. 4
0
 @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);
   }
 }
Esempio n. 5
0
 @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);
   }
 }
 /**
  * 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);
 }