You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Phanidhar Adusumilli <ph...@gmail.com> on 2006/06/16 14:57:37 UTC

Alternative ways for component creation

The class UIComponentTag has a method createComponentInstance. This method
is private. If this method is protected one can override this and provide
alternative creation mechanism.

One example can be, clay api can be used to create a component and its
children from a template. Thus using these templates will make JSP code
simpler.

I would appreciate others opinion on this.

Re: Alternative ways for component creation

Posted by Phanidhar Adusumilli <ph...@gmail.com>.
I agree that facelets can be used. But I have created simple util methods
that use clay api to load a component or a sub tree. I cannot plug this into
Myfaces implementation as createComponentInstance is private. It can be
plugged into sun implementation.

Clay as it is adds a clay component to the tree and while rendering this
component loads the subtree. Hence one cannot use clay as it is for
templating. For example:

The project I am working mostly has panels displaying atleast one list. We
use datatable. All of the datatable attributes are common except for the
bean name. Instead of every jsp containing the list, specify all these
attributes I created a template using clay for datatable with all the
attributes set in some cases using symbols.The intention is to create a
custom tag whose createComponentInstance will create the component from this
template. Similarly the column can be also be templated.

Following are some issues with using clay as it is . Some of them apply to
facelets also.


   1. Clay grafts a sub tree into an existing tree. But this is done by
   adding the clay to main tree and the clay  component adds the sub tree as
   its child.

For example:

When using clay  to load a template, the clay tag is used in jsp.

<clay:clay id="abc" jsfid="templatename">

</clay:clay>

The execution of this tag adds clay component to the view tree and while
rendering, the clay component builds the sub tree from the template and adds
it as a child.

The tree is as follows:

 Viewroot

|__clay

|   |__template contents

|

|__other page component..



   1. It cannot be used to load a template for a container.

For example:

      When using datatable normally the code looks as follows:

<t:datatable attributes…>

  <h:column>

    Column contents

  </h:column>

  <h:column>

    Column contents

  </h:column>

</t:datatable>

The tree is as follows:

Datatable

|__column

|   |__column contents

|

|__column

    |__column contents



 As there are many attributes that need to be definedon the datatable, we
want to create a template. So with clay it will be as follows:



<clay:clay id="mydatalist"   jsfid="mytable">

  <h:column>

    Column contents

  </h:column>

  <h:column>

    Column contents

  </h:column>

</clay:clay>



But what happens is the tree will be as follows:

Clay

|__datatable

|

|__column

|   |__column contents

|

|__column

    |__column contents



The template contents become children of clay as well as the components
inside clay tag body also become its children.



   1. column definition has lots of repetitive code.



For example:

<datatable>

  <column>

      <facet name="header">

        Header contents

      </facet>

      Column contents

  </column>

  <column>

      <facet name="header">

        Header contents

      </facet>

      Column contents

  </column>

  <column>

      <facet name="header">

        Header contents

      </facet>

      Column contents

  </column>

</datatable>



To avoid this we wanted to create template for column.



With the template the code is as follows:

<datatable>

  <clay jsfid="column template"    other parameters…>

  <clay jsfid="column template"    other parameters…>

</datatable>



But based on point 1 above the tree is as follows:



Datatable

|__clay

|   |__column

|

|__clay

    |__column



This tree is fine, but the datatable component according to the spec will
only render a child if it's a column. But in this column is hidden under
clay and hence nothing is rendered.(clay components are immediate children
of datatable)




On 6/16/06, Cagatay Civici <ca...@gmail.com> wrote:
>
> Hi,
>
> For the first thing, FacesContext.getCurrentInstance.getApplication().createComponent(String
> type) method will do the job.
>
> For the second thing, facelets is another solution for templating and
> composition from templates.
>
>
> Cagatay
>
>
> On 6/16/06, Phanidhar Adusumilli <ph...@gmail.com> wrote:
> >
> >  The class UIComponentTag has a method createComponentInstance. This
> > method is private. If this method is protected one can override this and
> > provide alternative creation mechanism.
> >
> > One example can be, clay api can be used to create a component and its
> > children from a template. Thus using these templates will make JSP code
> > simpler.
> >
> > I would appreciate others opinion on this.
> >
>
>

Re: Alternative ways for component creation

Posted by Cagatay Civici <ca...@gmail.com>.
Hi,

For the first thing,
FacesContext.getCurrentInstance.getApplication().createComponent(String
type) method will do the job.

For the second thing, facelets is another solution for templating and
composition from templates.

Cagatay

On 6/16/06, Phanidhar Adusumilli <ph...@gmail.com> wrote:
>
> The class UIComponentTag has a method createComponentInstance. This method
> is private. If this method is protected one can override this and provide
> alternative creation mechanism.
>
> One example can be, clay api can be used to create a component and its
> children from a template. Thus using these templates will make JSP code
> simpler.
>
> I would appreciate others opinion on this.
>