예제 #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));
   }
 }
 protected void resetComponent(UIComponent comp, boolean recursive) {
   if (comp == null) {
     return;
   }
   if (comp instanceof ResettableComponent) {
     ((ResettableComponent) comp).resetCachedModel();
   } else {
     if (comp instanceof EditableValueHolder) {
       // reset submitted value
       ((EditableValueHolder) comp).setSubmittedValue(null);
     }
     if (comp instanceof ValueHolder) {
       // reset local value, only if there's a value expression
       // binding
       ValueExpression ve = comp.getValueExpression("value");
       if (ve != null) {
         ValueHolder vo = (ValueHolder) comp;
         vo.setValue(null);
         if (comp instanceof EditableValueHolder) {
           ((EditableValueHolder) comp).setLocalValueSet(false);
         }
       }
     }
   }
   if (recursive) {
     List<UIComponent> children = comp.getChildren();
     if (children != null && !children.isEmpty()) {
       for (UIComponent child : children) {
         resetComponent(child, recursive);
       }
     }
   }
 }