public void updateModel(FacesContext facesContext) { if (facesContext == null) { throw new NullPointerException(); } if (!isValid() || !isLocalValueSet()) { return; } ValueExpression ve = getValueExpression("value"); if (ve == null) { return; } Throwable caught = null; FacesMessage message = null; try { ve.setValue(facesContext.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 (messageStr == null) { message = ServiceTracker.getService(MessageFactory.class) .createMessage( facesContext, FacesMessage.SEVERITY_ERROR, FacesMessages.UIINPUT_UPDATE, MessageUtil.getLabel(facesContext, this)); } else { message = new FacesMessage(FacesMessage.SEVERITY_ERROR, messageStr, messageStr); } setValid(false); } catch (Exception e) { caught = e; // message = MessageFactory.getMessage(facesContext, UPDATE_MESSAGE_ID, // MessageFactory.getHeader(facesContext, this)); setValid(false); } if (caught != null) { assert message != null; @SuppressWarnings({"ThrowableInstanceNeverThrown"}) UpdateModelException toQueue = new UpdateModelException(message, caught); ExceptionQueuedEventContext eventContext = new ExceptionQueuedEventContext(facesContext, toQueue, this, PhaseId.UPDATE_MODEL_VALUES); facesContext .getApplication() .publishEvent(facesContext, ExceptionQueuedEvent.class, eventContext); } }
protected Converter createConverter() throws JspException { FacesContext context = FacesContext.getCurrentInstance(); ELContext elctx = context.getELContext(); if (binding != null) { Converter boundConverter = (NumberConverter) binding.getValue(elctx); if (boundConverter != null) return boundConverter; } NumberConverter converter = new NumberConverter(); if (currencyCode != null) converter.setCurrencyCode((String) currencyCode.getValue(elctx)); if (currencySymbol != null) converter.setCurrencySymbol((String) currencySymbol.getValue(elctx)); if (groupingUsed != null) converter.setGroupingUsed((Boolean) groupingUsed.getValue(elctx)); if (integerOnly != null) converter.setIntegerOnly((Boolean) integerOnly.getValue(elctx)); if (maxFractionDigits != null) converter.setMaxFractionDigits((Integer) maxFractionDigits.getValue(elctx)); if (minFractionDigits != null) converter.setMinFractionDigits((Integer) minFractionDigits.getValue(elctx)); if (minIntegerDigits != null) converter.setMinIntegerDigits((Integer) minIntegerDigits.getValue(elctx)); if (pattern != null) converter.setPattern((String) pattern.getValue(elctx)); if (type != null) converter.setType((String) type.getValue(elctx)); Locale loc = null; if (locale != null) loc = FacesUtils.getLocaleFromExpression(context, locale); if (loc == null) loc = context.getViewRoot().getLocale(); converter.setLocale(loc); if (binding != null) binding.setValue(elctx, converter); return converter; }
public static UIComponent addPersistent( FacesContext context, ServletRequest req, UIComponent parent, ValueExpression binding, Class childClass) throws Exception { if (context == null) context = FacesContext.getCurrentInstance(); if (parent == null) { UIComponentClassicTagBase parentTag = (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent"); parent = parentTag.getComponentInstance(); BodyContent body = parentTag.getBodyContent(); addVerbatim(parent, body); } UIComponent child = null; if (binding != null) child = (UIComponent) binding.getValue(context.getELContext()); if (child == null) { child = (UIComponent) childClass.newInstance(); // jsf/3251 if (binding != null) binding.setValue(context.getELContext(), child); } if (parent != null) parent.getChildren().add(child); return child; }
@Override public void apply(FaceletContext ctx, UIComponent component) throws IOException, FacesException, FaceletException, ELException { AutoCompleteSelectItemsBean bean = new AutoCompleteSelectItemsBean(); if (unlessAttribute != null) { if (ObjectExtractor.extractBoolean( getValueExpression(unlessAttribute, ctx, Object.class), ctx)) { return; } } bean.setColumn( ObjectExtractor.extractString(getValueExpression(columnAttribute, ctx, String.class), ctx)); bean.setJndi( ObjectExtractor.extractString(getValueExpression(jndiAttribute, ctx, String.class), ctx)); bean.setLabel( ObjectExtractor.extractString(getValueExpression(labelAttribute, ctx, String.class), ctx)); bean.setTable( ObjectExtractor.extractString(getValueExpression(tableAttribute, ctx, String.class), ctx)); if (keyAttribute != null) bean.setKey( ObjectExtractor.extractString(getValueExpression(keyAttribute, ctx, String.class), ctx)); if (likeAttribute != null) bean.setLike( ObjectExtractor.extractBoolean( getValueExpression(likeAttribute, ctx, Object.class), ctx)); ValueExpression beanExpression = getValueExpression(beanAttribute, ctx, AutoCompleteSelectItemsBean.class); beanExpression.setValue(ctx, bean); }
public static UIComponent addFacet( FacesContext context, ServletRequest req, UIComponent parent, String facetName, ValueExpression binding, Class childClass) throws Exception { if (context == null) context = FacesContext.getCurrentInstance(); if (parent == null) { UIComponentClassicTagBase parentTag = (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent"); parent = parentTag.getComponentInstance(); } UIComponent child = null; if (binding != null) child = (UIComponent) binding.getValue(context.getELContext()); if (child == null) child = (UIComponent) childClass.newInstance(); if (parent != null) parent.getFacets().put(facetName, child); if (binding != null) binding.setValue(context.getELContext(), child); return child; }
public void apply(FaceletContext context, UIComponent parent) throws IOException, FacesException, ELException { if (parent == null || !(parent instanceof EditableValueHolder)) throw new TagException(tag, "Parent not an instance of EditableValueHolder: " + parent); if (parent.getParent() == null) { EditableValueHolder editableValueHolder = (EditableValueHolder) parent; ValueExpression valueExpression = null; Validator validator = null; if (binding != null) { valueExpression = binding.getValueExpression(context, javax.faces.validator.Validator.class); validator = (Validator) valueExpression.getValue(context); } if (validator == null) { validator = createValidator(context); if (valueExpression != null) valueExpression.setValue(context, validator); } if (validator == null) throw new TagException(tag, "No Validator was created"); if (nextHandler instanceof CompositeFaceletHandler) { addParameters(context, (CompositeFaceletHandler) nextHandler); } else if (nextHandler instanceof MessageParameterTagHandler) { addParameter(context, (MessageParameterTagHandler) nextHandler); } setAttributes(context, validator); editableValueHolder.addValidator(validator); } }
public void processEvent(FacesEvent event) throws AbortProcessingException { FacesContext faces = FacesContext.getCurrentInstance(); if (faces == null) { return; } L instance = null; if (this.binding != null) { instance = (L) binding.getValue(faces.getELContext()); } if (instance == null && this.type != null) { try { instance = (L) TagHandlerUtils.loadClass(this.type, Object.class).newInstance(); } catch (Exception e) { throw new AbortProcessingException("Couldn't Lazily instantiate EventListener", e); } if (this.binding != null) { binding.setValue(faces.getELContext(), instance); } } if (instance != null) { event.processListener(instance); } }
public UIComponent createComponent(FaceletContext ctx) { FacesContext context = ctx.getFacesContext(); UIComponent cc; // we have to handle the binding here, as Application doesn't // expose a method to do so with Resource. if (binding != null) { ValueExpression ve = binding.getValueExpression(ctx, UIComponent.class); cc = (UIComponent) ve.getValue(ctx); if (cc != null && !UIComponent.isCompositeComponent(cc)) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log(Level.SEVERE, "jsf.compcomp.binding.eval.non.compcomp", binding.toString()); } cc = null; } if (cc == null) { cc = context.getApplication().createComponent(context, ccResource); ve.setValue(ctx, cc); } } else { cc = context.getApplication().createComponent(context, ccResource); } setCompositeComponent(context, cc); return cc; }
public void applyAttachedObject(FacesContext context, UIComponent parent) { FaceletContext ctx = (FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY); // cast to a ValueHolder ValueHolder vh = (ValueHolder) parent; ValueExpression ve = null; Converter c = null; if (this.binding != null) { ve = this.binding.getValueExpression(ctx, Converter.class); c = (Converter) ve.getValue(ctx); } if (c == null) { c = this.createConverter(ctx); if (ve != null) { ve.setValue(ctx, c); } } if (c == null) { throw new TagException(this.tag, "No Converter was created"); } this.setAttributes(ctx, c); vh.setConverter(c); Object lv = vh.getLocalValue(); FacesContext faces = ctx.getFacesContext(); if (lv instanceof String) { vh.setValue(c.getAsObject(faces, parent, (String) lv)); } }
private void updateStateHelper(final String propertyName, final Object value) { this.getStateHelper().put(propertyName, value); final ValueExpression ve = this.getValueExpression(propertyName); if (ve != null) { ve.setValue(this.getFacesContext().getELContext(), value); } }
private void doSetBindings(ELContext elContext, UIComponent component) { if (component == null) return; ValueExpression binding = component.getValueExpression("binding"); if (binding != null) binding.setValue(elContext, component); Iterator<UIComponent> iter = component.getFacetsAndChildren(); while (iter.hasNext()) doSetBindings(elContext, iter.next()); }
/** * @param expressao * @param obj * @param clazz */ public void setAtributo(String expressao, Object obj, Class clazz) { FacesContext current = FacesContext.getCurrentInstance(); Application app = current.getApplication(); ExpressionFactory fac = app.getExpressionFactory(); ValueExpression ve = fac.createValueExpression(current.getELContext(), expressao, clazz); ve.setValue(current.getELContext(), obj); }
@Override public void processUpdates(FacesContext context) { super.processUpdates(context); if (!isRendered() || !isValid()) { return; } javax.el.ValueExpression ve = getValueExpression(SELECTED_LABEL_ATTR); if (ve != null && !ve.isReadOnly(context.getELContext())) { ve.setValue(context.getELContext(), getSelectedIndex()); setSelectedIndex(null); } }
@Override public void processUpdates(FacesContext context) { beforeUpdateValuesPhase = false; super.processUpdates(context); if (incomingGroupingRules != null) { acceptNewGroupingRules(incomingGroupingRules); incomingGroupingRules = null; } if (groupingRules != null && ValueBindings.set(this, "groupingRules", groupingRules)) groupingRules = null; ValueExpression expansionStateExpression = getValueExpression("expansionState"); if (expansionStateExpression != null) expansionStateExpression.setValue(context.getELContext(), expansionState); }
public void processAction(ActionEvent e) throws AbortProcessingException { FacesContext facesContext = FacesContext.getCurrentInstance(); ELContext elContext = facesContext.getELContext(); try { Object value = source.getValue(elContext); if (value != null) { ExpressionFactory factory = facesContext.getApplication().getExpressionFactory(); value = factory.coerceToType(value, target.getType(elContext)); } target.setValue(elContext, value); } catch (ELException ele) { throw new AbortProcessingException(ele); } }
@Override public void submitValue(String expression, Object value) throws UnsupportedEvaluationException { FacesContext facesContext = getFacesContext(); ELContext elContext = facesContext.getELContext(); ValueExpression valueExpression = getValueExpression(facesContext, expression); Class<?> referencedType = valueExpression.getType(elContext); // the value that will be injected Object toInject = null; // the expression is referencing an array if (referencedType.isArray()) { // ensure the value that will be injected is an array if (value != null && !value.getClass().isArray()) { toInject = new Object[] {value}; } else { toInject = value; } } // expression is not referencing an array else { // if value to inject is an array, just use the first element if (value != null && value.getClass().isArray()) { Object[] valueAsArray = (Object[]) value; if (valueAsArray.length > 0) { toInject = valueAsArray[0]; } else { toInject = null; } } // simple case: neither the expression is referencing an array nor the value is one else { toInject = value; } } // set the value Object coercedValue = facesContext.getApplication().getExpressionFactory().coerceToType(toInject, referencedType); valueExpression.setValue(elContext, coercedValue); }
@Override public void setValue(EvaluationContext ctx, Object value) throws ELException { VariableMapper varMapper = ctx.getVariableMapper(); if (varMapper != null) { ValueExpression expr = varMapper.resolveVariable(this.image); if (expr != null) { expr.setValue(ctx.getELContext(), value); return; } } ctx.setPropertyResolved(false); ctx.getELResolver().setValue(ctx, null, this.image, value); if (!ctx.isPropertyResolved()) { throw new PropertyNotFoundException( MessageFactory.get("error.resolver.unhandled.null", this.image)); } }
public ValueReference getReference(ELContext elContext) { InterceptingResolver resolver = new InterceptingResolver(elContext.getELResolver()); try { expression.setValue(decorateELContext(elContext, resolver), null); } catch (ELException ele) { return null; } ValueReference reference = resolver.getValueReference(); if (reference != null) { Object base = reference.getBase(); if (base instanceof CompositeComponentExpressionHolder) { ValueExpression ve = ((CompositeComponentExpressionHolder) base).getExpression(reference.getProperty()); if (ve != null) { this.expression = ve; reference = getReference(elContext); } } } return reference; }
public void processAction(ActionEvent event) throws AbortProcessingException { final FacesContext facesContext = FacesContext.getCurrentInstance(); final ELContext elContext = facesContext.getELContext(); final Object value = valueExpression.getValue(elContext); final int size; if (value == null) { size = 0; } else if (value instanceof Collection) { final Collection collection = (Collection) value; size = collection.size(); } else if (value instanceof Map) { final Map map = (Map) value; size = map.size(); } else { throw new FacesException( "Attempted to apply paging to an object that is not a Collection or a Map"); } final Object pageValue = pageExpression == null ? null : pageExpression.getValue(elContext); final int pageParameter = pageValue == null ? 1 : pageValue instanceof Number ? ((Number) pageValue).intValue() : Integer.parseInt(pageValue.toString()); final Object pageSizeValue = pageSizeExpression == null ? null : pageSizeExpression.getValue(elContext); final int pageSize = pageSizeValue == null ? 10 : pageSizeValue instanceof Number ? ((Number) pageSizeValue).intValue() : Integer.parseInt(pageSizeValue.toString()); final int totalPages = (size + pageSize - 1) / pageSize; final int page = pageParameter < 1 ? 1 : pageParameter > totalPages ? totalPages : pageParameter; final int thisPageCount = page == totalPages ? ((size - 1) % pageSize) + 1 : pageSize; final int first = (page - 1) * pageSize; targetExpression.setValue( elContext, new Bean(page, totalPages, pageSize, thisPageCount, first, size)); }
@Test public void shouldPropagateDownstreamMessageOnPipelineFutureSuccess() throws Exception { final ChannelBuffer[] expectedArr = new ChannelBuffer[3]; expectedArr[0] = wrappedBuffer(new byte[] {0x01, 0x02, 0x03}); expectedArr[1] = copiedBuffer("Hello, world", UTF_8); expectedArr[2] = wrappedBuffer(new byte[] {0x01, 0x02, 0x03}); final ChannelBuffer expected = masker.applyMask(wrappedBuffer(expectedArr)); context.checking( new Expectations() { { oneOf(upstream) .handleUpstream( with(any(ChannelHandlerContext.class)), with(any(PreparationEvent.class))); oneOf(upstream) .handleUpstream( with(any(ChannelHandlerContext.class)), with(channelState(OPEN, TRUE))); oneOf(downstream) .handleDownstream(with(any(ChannelHandlerContext.class)), with(message(expected))); oneOf(upstream) .handleUpstream( with(any(ChannelHandlerContext.class)), with(any(WriteCompletionEvent.class))); } }); expression.setValue(environment, new byte[] {0x01, 0x02, 0x03}); channelFactory.newChannel(pipeline); ChannelFuture executionFuture = execution.getHandlerFuture(); executionFuture.setSuccess(); ChannelFuture handlerFuture = handler.getHandlerFuture(); handlerFuture.sync(); context.assertIsSatisfied(); }
/** * Factory method for creating the varius JSF listener instances that may be referenced by <code> * type</code> or <code>binding</code>. * * <p>If <code>binding</code> is not <code>null</code> and the evaluation result is not <code>null * </code> return that instance. Otherwise try to instantiate an instances based on <code>type * </code>. * * @param type the <code>Listener</code> type * @param binding a <code>ValueExpression</code> which resolves to a <code>Listener</code> * instance * @return a <code>Listener</code> instance based off the provided <code>type</code> and <binding> */ public static Object getListenerInstance(ValueExpression type, ValueExpression binding) { FacesContext faces = FacesContext.getCurrentInstance(); Object instance = null; if (faces == null) { return null; } if (binding != null) { instance = binding.getValue(faces.getELContext()); } if (instance == null && type != null) { try { instance = ReflectionUtils.newInstance(((String) type.getValue(faces.getELContext()))); } catch (Exception e) { throw new AbortProcessingException(e.getMessage(), e); } if (binding != null) { binding.setValue(faces.getELContext(), instance); } } return instance; }
@Test public void shouldNotPropagateDownstreamMessageOnPipelineFutureFailure() throws Exception { context.checking( new Expectations() { { oneOf(upstream) .handleUpstream( with(any(ChannelHandlerContext.class)), with(any(PreparationEvent.class))); oneOf(upstream) .handleUpstream( with(any(ChannelHandlerContext.class)), with(channelState(OPEN, TRUE))); } }); expression.setValue(environment, new byte[] {0x01, 0x02, 0x03}); channelFactory.newChannel(pipeline); ChannelFuture executionFuture = execution.getHandlerFuture(); executionFuture.setFailure(new ChannelException("pipeline already failed")); ChannelFuture handlerFuture = handler.getHandlerFuture(); assertFalse(handlerFuture.isDone()); context.assertIsSatisfied(); }
private void updateModel(int newPage) { FacesContext facesContext = getFacesContext(); UIComponent dataTable = getDataTable(); if (isRendered(dataTable)) { dataTable.getAttributes().put("first", (newPage - 1) * getRows(dataTable)); } Map<String, Object> attributes = dataTable.getAttributes(); attributes.put(dataTable.getClientId(facesContext) + SCROLLER_STATE_ATTRIBUTE, newPage); ValueExpression ve = getValueExpression("page"); if (ve != null) { try { ve.setValue(facesContext.getELContext(), newPage); attributes.remove(dataTable.getClientId(facesContext) + 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 = ServiceTracker.getService(MessageFactory.class) .createMessage( facesContext, FacesMessages.UIINPUT_UPDATE, MessageUtil.getLabel(facesContext, this)); } else { message = new FacesMessage(FacesMessage.SEVERITY_ERROR, messageStr, messageStr); } facesContext.getExternalContext().log(message.getSummary(), result); facesContext.addMessage(getClientId(facesContext), message); facesContext.renderResponse(); } catch (IllegalArgumentException e) { FacesMessage message = ServiceTracker.getService(MessageFactory.class) .createMessage( facesContext, FacesMessages.UIINPUT_UPDATE, MessageUtil.getLabel(facesContext, this)); facesContext.getExternalContext().log(message.getSummary(), e); facesContext.addMessage(getClientId(facesContext), message); facesContext.renderResponse(); } catch (Exception e) { FacesMessage message = ServiceTracker.getService(MessageFactory.class) .createMessage( facesContext, FacesMessages.UIINPUT_UPDATE, MessageUtil.getLabel(facesContext, this)); facesContext.getExternalContext().log(message.getSummary(), e); facesContext.addMessage(getClientId(facesContext), message); facesContext.renderResponse(); } } }
private void setVarParameter(ValueExpression parameterExpression, Object value) { if (parameterExpression == null) return; parameterExpression.setValue(getFacesContext().getELContext(), value); }