@Override protected ConfirmBehavior createBehavior(FaceletContext ctx, String eventName, UIComponent parent) { Application application = ctx.getFacesContext().getApplication(); ConfirmBehavior behavior = (ConfirmBehavior) application.createBehavior(ConfirmBehavior.BEHAVIOR_ID); setBehaviorAttribute(ctx, behavior, this.header, ConfirmBehavior.PropertyKeys.header.getExpectedType()); setBehaviorAttribute(ctx, behavior, this.message, ConfirmBehavior.PropertyKeys.message.getExpectedType()); setBehaviorAttribute(ctx, behavior, this.icon, ConfirmBehavior.PropertyKeys.icon.getExpectedType()); setBehaviorAttribute(ctx, behavior, this.disabled, ConfirmBehavior.PropertyKeys.disabled.getExpectedType()); setBehaviorAttribute(ctx, behavior, this.beforeShow, ConfirmBehavior.PropertyKeys.beforeShow.getExpectedType()); setBehaviorAttribute(ctx, behavior, this.escape, ConfirmBehavior.PropertyKeys.escape.getExpectedType()); return behavior; }
@Override public void apply(FaceletContext ctx, UIComponent parent) throws IOException { FacesContext facesContext = FacesContext.getCurrentInstance(); Class<?> type = getClassFromAttribute(typeTagAttribute, ctx); Map<String, Object> constants = getConstants(facesContext, type); // Create alias/var expression String var; if (varTagAttribute == null) { var = type.getSimpleName(); // fall back to class name } else { var = varTagAttribute.getValue(ctx); } ctx.setAttribute(var, constants); }
public static void includeCompositeComponent(UIComponent parent, String libraryName, String resourceName, String id) { // Prepare. FacesContext context = FacesContext.getCurrentInstance(); Application application = context.getApplication(); FaceletContext faceletContext = (FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY); // This basically creates <ui:component> based on <composite:interface>. Resource resource = application.getResourceHandler().createResource(resourceName, libraryName); UIComponent composite = application.createComponent(context, resource); composite.setId(id); // Mandatory for the case composite is part of UIForm! Otherwise JSF can't find inputs. // This basically creates <composite:implementation>. UIComponent implementation = application.createComponent(UIPanel.COMPONENT_TYPE); implementation.setRendererType("javax.faces.Group"); composite.getFacets().put(UIComponent.COMPOSITE_FACET_NAME, implementation); // Now include the composite component file in the given parent. parent.getChildren().add(composite); parent.pushComponentToEL(context, composite); // This makes #{cc} available. try { faceletContext.includeFacelet(implementation, resource.getURL()); } catch (IOException e) { throw new FacesException(e); } finally { parent.popComponentFromEL(context); } }
private void applyCompositeComponent(FaceletContext ctx, UIComponent c) throws IOException { FacesContext facesContext = ctx.getFacesContext(); VariableMapper orig = ctx.getVariableMapper(); if (ComponentHandler.isNew(c)) { facetComponent = (UIPanel) facesContext.getApplication().createComponent("javax.faces.Panel"); facetComponent.setRendererType("javax.faces.Group"); c.getFacets().put(UIComponent.COMPOSITE_FACET_NAME, facetComponent); c.getFacets().get(UIComponent.COMPOSITE_FACET_NAME); ctx.setVariableMapper(wrapper); ctx.includeFacelet(facetComponent, ccResource.getURL()); } finally { ctx.setVariableMapper(orig);
/** * Uses the specified "converterId" to pull an instance from the Application * * @see javax.faces.application.Application#createComponent(java.lang.String) */ protected Converter createConverter(FaceletContext ctx) throws FacesException, ELException, FaceletException { return ctx.getFacesContext().getApplication().createConverter( this.converterId.getValue(ctx)); }
/** * Template method for creating a Validator instance * * @param ctx * FaceletContext to use * @return a new Validator instance */ private Validator createValidator(FaceletContext ctx) { String id = owner.getValidatorId(ctx); if (id == null) { throw new TagException( owner.getTag(), "A validator id was not specified. Typically the validator id is set in the constructor ValidateHandler(ValidatorConfig)"); } return ctx.getFacesContext().getApplication().createValidator(id); }
/** * Create a Converter instance * * @param ctx * FaceletContext to use * @return Converter instance, cannot be null */ private Converter createConverter(FaceletContext ctx) { if (owner.getConverterId(ctx) == null) { throw new TagException( owner.getTag(), "Default behavior invoked of requiring a converter-id passed in the constructor, must override ConvertHandler(ConverterConfig)"); } return ctx.getFacesContext().getApplication().createConverter(owner.getConverterId(ctx)); }
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()) + '\''); }
public void apply(FaceletContext ctx, UIComponent parent) throws IOException { if (ComponentHandler.isNew(parent)) { Class<? extends SystemEvent> eventClass = getEventClass(ctx); UIViewRoot viewRoot = ctx.getFacesContext().getViewRoot(); // ensure that f:event can be used anywhere on the page for preRenderView, // not just as a direct child of the viewRoot if (null != viewRoot && PreRenderViewEvent.class == eventClass && parent != viewRoot) { parent = viewRoot; } if (eventClass != null) { parent.subscribeToEvent(eventClass, new DeclarativeSystemEventListener( listener.getMethodExpression(ctx, Object.class, new Class[] { ComponentSystemEvent.class }), listener.getMethodExpression(ctx, Object.class, new Class[] { }))); } } }
protected Behavior createBehavior(FaceletContext ctx) { if (_delegate.getBehaviorId() == null) { throw new TagException( _delegate.getTag(), "No behavior id defined"); } return ctx.getFacesContext().getApplication().createBehavior(_delegate.getBehaviorId()); }
protected MethodBinding getMethodBinding(FaceletContext ctx) { MethodExpression expression = this.attribute.getMethodExpression(ctx, null, signature); Application application = ctx.getFacesContext().getApplication(); return application.createMethodBinding(expression.getExpressionString(), signature); // TODO // expression.getExpressionString() // ??? } }
private void setConverter( final FaceletContext faceletContext, final UIComponent parent, final String nameValue, final ValueExpression expression) { if (expression.isLiteralText()) { final Converter converter = faceletContext.getFacesContext().getApplication().createConverter(expression.getExpressionString()); ((ValueHolder) parent).setConverter(converter); } else { parent.setValueExpression(nameValue, expression); } } }
@Override protected AjaxBehavior createBehavior(FaceletContext ctx, String eventName, UIComponent parent) { Application application = ctx.getFacesContext().getApplication(); AjaxBehavior behavior = (AjaxBehavior) application.createBehavior(AjaxBehavior.BEHAVIOR_ID); this.listener.getMethodExpression(ctx, Void.class, EMPTY_PARAMS), this.listener.getMethodExpression(ctx, Void.class, ARG_PARAMS))); this.listener.getMethodExpression(ctx, Void.class, EMPTY_PARAMS), this.listener.getMethodExpression(ctx, Void.class, ARG_PARAMS), this.listener.getMethodExpression(ctx, Void.class, new Class[]{eventMappingClass})));
protected Class<? extends SystemEvent> getEventClass(FaceletContext ctx) { String eventType = (String) this.type.getValueExpression(ctx, String.class).getValue(ctx); if (eventType == null) { throw new FacesException("Attribute 'type' can not be null"); } return ApplicationAssociate.getInstance(ctx.getFacesContext().getExternalContext()) .getNamedEventManager().getNamedEvent(eventType); }
public void include() throws IOException { FacesContext facesContext = FacesContext.getCurrentInstance(); FaceletContext faceletContext = (FaceletContext) facesContext.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY); faceletContext.includeFacelet(facesContext.getViewRoot().findComponent("foo"), "include.xhtml"); }
public void apply(FaceletContext ctx, UIComponent parent) throws IOException { // only process if it's been created if (parent == null || !ComponentHandler.isNew(parent)) { return; } if (isEventSource(parent)) { applyAttachedObject(ctx.getFacesContext(), parent); } else if (UIComponent.isCompositeComponent(parent)) { // Allow the composite component to know about the target component. TagHandlerUtils.getOrCreateRetargetableHandlersList(parent).add(this); } else { throw new TagException(this.tag, "Parent does not match event source requirements: " + parent); } }
protected void doNewComponentActions(FaceletContext ctx, String id, UIComponent c) { if (log.isLoggable(Level.FINE)) { log.fine(owner.getTag() + " Component["+id+"] Created: " + c.getClass().getName()); } // If this is NOT a composite component... if (null == createCompositeComponentDelegate) { // set the attributes and properties into the UIComponent instance. owner.setAttributes(ctx, c); } // otherwise, allow the composite component code to do it. // mark it owned by a facelet instance c.getAttributes().put(ComponentSupport.MARK_CREATED, id); if (ctx.getFacesContext().isProjectStage(ProjectStage.Development)) { // inject the location into the component c.getAttributes().put(UIComponent.VIEW_LOCATION_KEY, owner.getTag().getLocation()); } }
public void apply(FaceletContext ctx, UIComponent parent) throws IOException { String nameStr = this.name.getValue(ctx); ValueExpression valueVE = this.value.getValueExpression(ctx, Object.class); ctx.getVariableMapper().setVariable(nameStr, valueVE); }
/** * Specialized implementation to prevent caching of the MetaRuleset when * ProjectStage is Development. */ @Override public void setAttributes(FaceletContext ctx, Object instance) { if (instance != null) { if (ctx.getFacesContext().isProjectStage(ProjectStage.Development)) { Metadata meta = createMetaRuleset(instance.getClass()).finish(); meta.applyMetadata(ctx, instance); } else { super.setAttributes(ctx, instance); } } }
protected void addComponentToView(FaceletContext ctx, UIComponent parent, UIComponent c, boolean componentFound) { FacesContext context = ctx.getFacesContext(); boolean suppressEvents = ComponentSupport.suppressViewModificationEvents(context); boolean compcomp = UIComponent.isCompositeComponent(c); if (suppressEvents && componentFound && !compcomp) { context.setProcessingEvents(false); } ComponentSupport.addComponent(ctx, parent, c); if (suppressEvents && componentFound && !compcomp) { context.setProcessingEvents(true); } }