dev@jsftemplating.java.net

Re: Easier Component Development

From: Ken Paulsen <Ken.Paulsen_at_Sun.COM>
Date: Mon, 23 Jul 2007 05:34:38 -0700

Hi Jacob,

Your code is very clean... I like the annotations.  They make it easy to generate taglib files and clean up the boilerplate property methods.

Using JSFTemplating's template syntax, the following "template-based" Renderer does the the same thing (this really works):

UIRepeat.jsf:

<!foreach val : $property{value}>
    <!beforeEncode
        setAttribute(key="$property{var}" value="#{val}");
    />
    <!foreach child : $this{children}>
        <component id="#{child.id}" />
    </foreach>
</foreach>


The component class looks like:

public class UIRepeat extends TemplateComponentBase {
    public () {
        super();
        setRendererType("com.sun.jsftemplating.UIRepeat");
        setLayoutDefinitionKey(LAYOUT_KEY);
    }

    public String getFamily() {
        return "com.sun.jsftemplating.UIRepeat";
    }

    /**
     *  This is the file that declares the layout for the UIRepeat.
     */
    public static final String  LAYOUT_KEY  =   "jsftemplating/UIRepeat.jsf";
}

I think it would be nice to add the properties via your annotations and get real properties.

Ken

Jacob Hookom wrote:
I'm a code jockey-- and a lot of the underlying discussion has always
been, "How do we simplify component development?"  Without starting
another thread of wish lists, it'd be interesting to see other's pseudo
code for something like a UIRepeat or UIData component-- maybe simplify
it and add UIInputText or UICommandButton.

While it's somewhat of an odd request, what's your ideal case for
implementing a UIComponent in pseudo code-- using annotations, hiding
EL, evaluation of children, etc-- again, code examples :-)



For example, I'd like to see UIRepeat look something like this:

// handle everything via bytecode
public class UIRepeat extends UIComponent {

   @Attribute(required=true)
   private Object var;

   @Attribute(required=true)
   private Iterable value;

   @Body
   private UIComponentBody body;

   public UIRepeat(UIComponentModel model) {
       super(model); //neat
   }

   public void onEncode(PhaseContext ctx) throws FacesException {
      for (Object o : this.value) {
         this.var = o; // dynamic assignment
         body.onEncode(ctx);
      }
   }
}