@Override public void apply(FaceletContext faceletContext, UIComponent parent) throws IOException { if (!ComponentHandler.isNew(parent)) { return; if (UIComponent.isCompositeComponent(parent)) { boolean tagApplied = false; if (parent instanceof ClientBehaviorHolder) { BeanInfo componentBeanInfo = (BeanInfo) parent.getAttributes().get(UIComponent.BEANINFO_KEY); if (null == componentBeanInfo) { throw new TagException(tag, "Composite component does not have BeanInfo attribute"); throw new TagException(tag, "Composite component BeanInfo does not have BeanDescriptor"); throw new TagException(tag, "Composite component does not support behavior events"); FacesContext context = FacesContext.getCurrentInstance(); PrimeEnvironment environment = PrimeApplicationContext.getCurrentInstance(context).getEnvironment(); if (environment.isMojarra()) { throw new TagException(tag, "Composite component does not support event " + eventName); throw new TagException(this.tag, "Unable to attach behavior to non-ClientBehaviorHolder parent");
public void applyAttachedObject(FacesContext context, UIComponent parent) { FaceletContext ctx = (FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY); // cast to the ClientBehaviorHolder. ClientBehaviorHolder behaviorHolder = (ClientBehaviorHolder) parent; ValueExpression bindingExpr=null; Behavior behavior=null; if (null != owner.getBinding()){ bindingExpr = owner.getBinding().getValueExpression(ctx, Behavior.class); behavior = (Behavior) bindingExpr.getValue(ctx); } if (null == behavior){ if (null != owner.getBehaviorId()){ behavior = ctx.getFacesContext().getApplication().createBehavior(owner.getBehaviorId()); if (null == behavior){ throw new TagException(owner.getTag(), "No Faces behavior defined for Id "+owner.getBehaviorId()); } if (null != bindingExpr){ bindingExpr.setValue(ctx, behavior); } } else { throw new TagException(owner.getTag(),"No behaviorId defined"); } } owner.setAttributes(ctx, behavior); if (behavior instanceof ClientBehavior) { behaviorHolder.addClientBehavior(getEventName(behaviorHolder), (ClientBehavior)behavior); } }
public void apply(FaceletContext ctx, UIComponent parent) throws IOException { assert(ctx.getFacesContext().getAttributes().containsKey(FaceletViewHandlingStrategy.IS_BUILDING_METADATA)); (null == (parent = parent.getParent())) || !(ComponentHandler.isNew(parent))) { return; parent.getAttributes().get(UIComponent.BEANINFO_KEY); if (null == componentBeanInfo) { throw new TagException(this.tag, "Error: I have an EditableValueHolder tag, but no enclosing composite component"); throw new TagException(this.tag, "Error: I have an EditableValueHolder tag, but no enclosing composite component"); targetList.add(target); ValueExpression ve = name.getValueExpression(ctx, String.class); String strValue = (String) ve.getValue(ctx); if (null != strValue) { target.setName(strValue); ve = targets.getValueExpression(ctx, String.class); target.setTargetsList(ve);
/** * Create a Converter instance * * @param ctx * FaceletContext to use * @return Converter instance, cannot be null */ protected Converter createConverter(FaceletContext ctx) { if (this.converterId == null) { throw new TagException( this.tag, "Default behavior invoked of requiring a converter-id passed in the constructor, must override ConvertHandler(ConverterConfig)"); } return ctx.getFacesContext().getApplication().createConverter(this.converterId); }
throws IOException, ELException { if (parent instanceof ValueHolder) { if (ComponentHandler.isNew(parent)) { final ValueHolder valueHolder = (ValueHolder) parent; Converter converter = null; ValueExpression valueExpression = null; if (binding != null) { valueExpression = binding.getValueExpression(faceletContext, Converter.class); converter = (Converter) valueExpression.getValue(faceletContext); converter = FacesContext.getCurrentInstance().getApplication().createConverter( (String) converterId.getValueExpression(faceletContext, String.class).getValue(faceletContext)); } catch (final Exception e) { throw new TagAttributeException(tag, converterId, e.getCause()); valueExpression.setValue(faceletContext, converter); throw new TagException(tag, "Parent is not of type ValueHolder, type is: " + parent);
public UIComponent createComponent(FaceletContext ctx) FacesContext facesContext = ctx.getFacesContext(); UIComponent component = facesContext.getApplication().createComponent(facesContext, _resource); if (!facesContext.isProjectStage(ProjectStage.Production)) BeanInfo beanInfo = (BeanInfo) component.getAttributes().get(UIComponent.BEANINFO_KEY); for (PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) if (ve != null) Object value = ve.getValue (facesContext.getELContext()); Boolean required = null; if (value instanceof Boolean) throw new TagException(this.tag, "Attribute '" + propertyDescriptor.getName() + "' is required");
private void throwRequiredException(FaceletContext ctx, String facetName, UIComponent compositeParent) { throw new TagException(tag, "Unable to find facet named '" + facetName + "' in parent composite component with id '" + compositeParent .getClientId(ctx.getFacesContext()) + '\''); }
@Override public void onComponentPopulated(FaceletContext ctx, UIComponent c, UIComponent parent) { if (!((AbstractFaceletContext)ctx).isBuildingCompositeComponentMetadata()) { UIComponent parentCompositeComponent = FaceletCompositionContext.getCurrentInstance(ctx).getCompositeComponentFromStack(); String facetName = _name.getValue(ctx); if (_required != null && _required.getBoolean(ctx) && parentCompositeComponent.getFacet(facetName) == null) { throw new TagException(this.tag, "Cannot find facet with name "+facetName+" in composite component " +parentCompositeComponent.getClientId(ctx.getFacesContext())); } c.getAttributes().put(UIComponent.FACETS_KEY, facetName); } } }
(null == (parent = parent.getParent())) || !(ComponentHandler.isNew(parent))) { return; Map<String, Object> componentAttrs = parent.getAttributes(); ValueExpression ve = name.getValueExpression(ctx, String.class); String strValue = (String) ve.getValue(ctx); BeanDescriptor componentBeanDescriptor = componentBeanInfo.getBeanDescriptor(); propertyDescriptor = new PropertyDescriptor(strValue, null, null); } catch (IntrospectionException ex) { throw new TagException(tag, "Unable to create property descriptor for facet" + strValue, ex); String attributeName = tagAttribute.getLocalName(); PropertyHandler handler = ATTRIBUTE_MANAGER.getHandler(ctx, attributeName); if (handler != null) {
private void checkFacetRequired(FaceletContext ctx, String name) { AbstractFaceletContext actx = (AbstractFaceletContext) ctx; FaceletCompositionContext fcc = actx.getFaceletCompositionContext(); UIComponent innerCompositeComponent = fcc.getCompositeComponentFromStack(); CompositeComponentBeanInfo beanInfo = (CompositeComponentBeanInfo) innerCompositeComponent.getAttributes() .get(UIComponent.BEANINFO_KEY); BeanDescriptor beanDescriptor = beanInfo.getBeanDescriptor(); Map<String, PropertyDescriptor> insertFacetPropertyDescriptorMap = (Map<String, PropertyDescriptor>) beanDescriptor.getValue(InsertFacetHandler.INSERT_FACET_KEYS); if (insertFacetPropertyDescriptorMap != null && insertFacetPropertyDescriptorMap.containsKey(name)) { ValueExpression requiredExpr = (ValueExpression) insertFacetPropertyDescriptorMap.get(name).getValue("required"); if (requiredExpr != null && Boolean.TRUE.equals(requiredExpr.getValue(ctx.getFacesContext().getELContext()))) { //Insert facet associated is required, but it was not applied. throw new TagException(this.tag, "Cannot find facet with name '"+name+"' in composite component"); } } }
public void apply(FaceletContext ctx, UIComponent parent) throws IOException { if (parent == null) { throw new TagException(this.tag, "Parent UIComponent was null"); } // only process if the parent is new to the tree if (parent.getParent() == null) { String n = getAttributeName(ctx); if (!parent.getAttributes().containsKey(n)) { if (this.value.isLiteral()) { parent.getAttributes().put(n, this.value.getValue()); } else { parent.setValueExpression(n, this.value.getValueExpression(ctx, Object.class)); } } } }
public void apply(FaceletContext ctx, UIComponent parent) throws IOException { if (parent == null) { throw new TagException(this.tag, "Parent UIComponent was null"); } // only process if the parent is new to the tree if (parent.getParent() == null) { Map<String,Object> passThroughAttrs = parent.getPassThroughAttributes(true); String attrName; Object attrValue; attrName = this.name.getValue(ctx); attrValue = (this.value.isLiteral()) ? this.value.getValue(ctx) : this.value.getValueExpression(ctx, Object.class); passThroughAttrs.put(attrName, attrValue); } }
public void apply(FaceletContext ctx, UIComponent parent) throws IOException { if (null == parent || !(ComponentHandler.isNew(parent))) { return; } if (parent instanceof ActionSource) { applyAttachedObject(ctx.getFacesContext(), parent); } else if (UIComponent.isCompositeComponent(parent)) { if (null == getFor()) { // PENDING(): I18N throw new TagException(this.tag, "actionListener tags nested within composite components must have a non-null \"for\" attribute"); } // Allow the composite component to know about the target // component. CompositeComponentTagHandler.getAttachedObjectHandlers(parent) .add(this); } else { throw new TagException(this.tag, "Parent is not of type ActionSource, type is: " + parent); } }
public void apply(FaceletContext ctx, UIComponent parent) throws IOException { if (parent == null) { throw new TagException(this.tag, "Parent UIComponent was null"); } // only process if the parent is new to the tree if (parent.getParent() == null) { Map<String, Object> componentPassThroughAttrs = parent.getPassThroughAttributes(true); Map<String, Object> tagPassThroughAttrs = (Map<String, Object>) this.value.getObject(ctx, Map.class); for (Map.Entry<String, Object> cur : tagPassThroughAttrs.entrySet()) { componentPassThroughAttrs.put(cur.getKey(), cur.getValue()); } } }
/** * See taglib documentation. */ public void apply(FaceletContext ctx, UIComponent parent) throws IOException { // only process if it's been created if (parent == null || !(ComponentHandler.isNew(parent))) { return; } if (parent instanceof EditableValueHolder) { applyAttachedObject(ctx.getFacesContext(), parent); } else if (parent.getAttributes().containsKey(Resource.COMPONENT_RESOURCE_KEY)) { // Allow the composite component to know about the target // component. CompositeComponentTagHandler.getAttachedObjectHandlers(parent).add(this); } else { throw new TagException(this.tag, "Parent is not of type EditableValueHolder, type is: " + parent); } }
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException, ELException { if (parent == null) { throw new TagException(this.tag, "Parent UIComponent was null"); } parent.getAttributes().put(KEY, this.name.getValue(ctx)); try { this.nextHandler.apply(ctx, parent); } finally { parent.getAttributes().remove(KEY); } }
@Override public void onComponentPopulated(FaceletContext ctx, UIComponent c, UIComponent parent) { if (!((AbstractFaceletContext)ctx).isBuildingCompositeComponentMetadata()) { UIComponent parentCompositeComponent = FaceletCompositionContext.getCurrentInstance(ctx).getCompositeComponentFromStack(); String facetName = _name.getValue(ctx); if (_required != null && _required.getBoolean(ctx) && parentCompositeComponent.getFacet(facetName) == null) { throw new TagException(this.tag, "Cannot find facet with name '"+facetName+"' in composite component"); } c.getAttributes().put(UIComponent.FACETS_KEY, facetName); } } }
public BehaviorHandler(BehaviorConfig config) { super(config); this.behaviorId = config.getBehaviorId(); this.event = this.getAttribute("event"); if (null != event && !event.isLiteral()){ throw new TagException(this.tag, "The 'event' attribute for behavior tag must be a literal"); } }
@Override public void apply(final FaceletContext faceletContext, final UIComponent parent) throws ELException { if (parent == null) { throw new TagException(tag, "Parent UIComponent was null"); } if (ComponentHandler.isNew(parent)) { final Object attributeName = name.isLiteral() ? (Object) name.getValue(faceletContext) : name.getValueExpression(faceletContext, Object.class); final Object attributeValue = value.isLiteral() ? (Object) value.getValue(faceletContext) : value.getValueExpression(faceletContext, Object.class); ComponentUtils.putDataAttribute(parent, attributeName, attributeValue); } } }
private String getEventName(ClientBehaviorHolder holder){ String eventName; if (null != owner.getEvent()){ eventName = owner.getEvent().getValue(); } else { eventName = holder.getDefaultEventName(); } if (null == eventName){ throw new TagException(owner.getTag(), "The event name is not defined"); } return eventName; }