On 12/3/06, Simon Kitching <[EMAIL PROTECTED]> wrote:

Hi Koshi,

Generally, having the component tree vary dynamically is not done with
JSF. If you want a choice of two different components, then typically
you define both of them in the page, then use the "rendered" property to
ensure that only the one you want is output.

There is certainly no JSF tag in standard JSF or Tomahawk that allows a
random component to be inserted into the tree. I don't initially see why
it wouldn't be possible to do this, but it certainly isn't common JSF
practice AFAIK.


I don't know about your definition of "common", but the fact that you *can*
construct component trees dynamically is one of the most powerful features
of JSF.  Consider, for example, the "shale-sql-browser" example app[1] in
Shale, which performs SQL queries, then looks at the JDBC metadata that is
returned, and builds dynamically the column components inside a table
component.  It's really easy to do (and this is all standard JSF stuff, not
dependent on Shale).


If you *did* want to create such a component, I can imagine one that has
a single child; on encodeBegin it evaluates its value expression, sets
that component as its child then passes on the encodeBegin call. All
other component methods would get delegated down to the child as normal.


It's easier to compose the component tree in an action event handler ...
saves all the extra effort needed to define and register a component.

Regards,

Simon



Craig

[1] http://people.apache.org/builds/shale/nightly/



koshi wrote:
> I have a managed bean with a method that returns a UIComponent,
> sometimes a commandLink or a outputText.
>
> public UIComponent getComponent ()
> {
>        UIComponent link ;
>        if (this.isAction ()) {
>                link = new HtmlCommandLink ();
>                link.setTitle (this.title);
>
>                MethodBinding method = FacesContext.getCurrentInstance
> ().getApplication ().
>                                     createMethodBinding (this.value,
null);
>                link.setAction (method);
>        }
>        else {
>                link = new HtmlOutputText ();
>                link.setValue (this.title);
>        }
>
>         return link;
> }
>
>
> Then, in the view i imagine something like that
> :
>
> <t:component value="#{managedBean.component}" />
>
> is this possible or i have to create a custom component ???
>
>
> thanks in advance, and sorry for my english mistakes.


Reply via email to