Ejemplo n.º 1
0
 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));
   }
 }
Ejemplo n.º 2
0
  public void apply(FaceletContext ctx, UIComponent parent)
      throws IOException, FacesException, FaceletException, ELException {

    Util.notNull("parent", parent);
    UIComponent facetComponent = parent.getFacets().get(UIViewRoot.METADATA_FACET_NAME);
    if (facetComponent == null) {
      parent.getAttributes().put(FacetHandler.KEY, UIViewRoot.METADATA_FACET_NAME);
      try {
        this.nextHandler.apply(ctx, parent);
      } finally {
        parent.getAttributes().remove(FacetHandler.KEY);
      }
      facetComponent = parent.getFacets().get(UIViewRoot.METADATA_FACET_NAME);
      if (!(facetComponent instanceof UIPanel)) {
        UIComponent panelGroup =
            ctx.getFacesContext().getApplication().createComponent(UIPanel.COMPONENT_TYPE);
        panelGroup.getAttributes().put(UIComponent.ADDED_BY_PDL_KEY, Boolean.TRUE);
        panelGroup.getChildren().add(facetComponent);
        parent.getFacets().put(UIViewRoot.METADATA_FACET_NAME, panelGroup);
        facetComponent = panelGroup;

        facetComponent.setId(UIViewRoot.METADATA_FACET_NAME);
      }
    }
  }
Ejemplo n.º 3
0
 /**
  * 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);
 }
Ejemplo n.º 4
0
 /**
  * Set Converter instance on parent ValueHolder if it's not being restored.
  *
  * <ol>
  *   <li>Cast to ValueHolder
  *   <li>If "binding" attribute was specified, fetch/create and re-bind to expression.
  *   <li>Otherwise, call {@link #createConverter(FaceletContext) createConverter}.
  *   <li>Call {@link com.sun.faces.facelets.tag.MetaTagHandlerImpl#setAttributes(FaceletContext,
  *       Object) setAttributes} on Converter instance.
  *   <li>Set the Converter on the ValueHolder
  *   <li>If the ValueHolder has a localValue, convert it and set the value
  * </ol>
  *
  * @see ValueHolder
  * @see Converter
  * @see #createConverter(FaceletContext)
  * @see com.sun.faces.facelets.FaceletHandler#apply(com.sun.faces.facelets.FaceletContext,
  *     javax.faces.component.UIComponent)
  */
 public final void apply(FaceletContext ctx, UIComponent parent)
     throws IOException, FacesException, FaceletException, ELException {
   // only process if it's been created
   if (parent == null || !(parent.getParent() == null)) {
     return;
   }
   if (parent instanceof ValueHolder) {
     applyAttachedObject(ctx.getFacesContext(), parent);
   } else if (parent.getAttributes().containsKey(Resource.COMPONENT_RESOURCE_KEY)) {
     if (null == getFor()) {
       // PENDING(): I18N
       throw new TagException(
           this.tag,
           "converter 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 not an instance of ValueHolder: " + parent);
   }
 }