You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Ionut S <si...@yahoo.com> on 2006/06/07 08:45:30 UTC

creating a custom component by aggregation

Hi,
I was wondering if somebody had any success in writing a custom component that aggregates other existing components ? 

For example, creating a component that extends UIPanel and adding to its children 2 existing components (a label and a combo box, let's say)..

Thank you !

 __________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: creating a custom component by aggregation

Posted by Andrew Robinson <an...@gmail.com>.
I've done it without facelets, but it was tricky. I had to create the
components in the constructor, and set their parent attribute, but not
add them to the children list. Then I had to maintain their state
myself in the restoreState and saveState functions.

The only side affect it had was that parent components wanting to
"surf" the component tree would not find my inner components as I
never added them to the children list.

If I had the time I could have found out where the components were
getting added back to the parent during the restore view phase, but I
didn't bother since I got it working the above way.

Something like:

public class MyCompositeComponent extends UIComponentBase {
...
private UICommand myInner;

public MyCompositeComponent() {
  myInner = (UICommand)getFacesContext().getApplication().createComponent(
    UICommand.COMPONENT_TYPE;
  myInner.setParent(this);
  myInner.setId(...);
}

public void restoreState(FacesContext context, Object state) {
  Object[] array = (Object[])state;
  super.restoreState(context, array[0]);
  myInner.restoreState(context, array[1]);
}

public Object saveState(FacesContext context) {
  return new Object[] {
    super.saveState(context),
    myInner.saveState(context)
  };
}

On 6/7/06, Ionut S <si...@yahoo.com> wrote:
> I would accept your suggestion right away, but we really need to have a JSF
> component in order to add it to the tree component dynamically. Is this
> possible with facelets ?
>
>
>
> Murray Brandon <mu...@hotmagna.com> wrote:
>
>  With Facelets templating over the top of JSF it's dead easy - you just
> include some xhtml that has any number of components inside it:
>
>
>
>
> value="#{selectedPerson.telephoneNo}"/>
>
>
>
>
> We use it for all our widget controls on this project even if its a 1:1
> correllation, that way we can chop and change which JSF components we
> use at the end of the day.
> The only trick is for small sets of components you don't display/not
> display using tags, but use of the rendered=" property on the
>
> components instead.
> It works.
>
> Regards, Murray
>
> Ionut S wrote:
> > Hi,
> > I was wondering if somebody had any success in writing a custom
> > component that aggregates other existing components ?
> >
> > For example, creating a component that extends UIPanel and adding to
> > its children 2 existing components (a label and a combo box, let's say)..
> >
> > Thank you !
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam protection around
> > http://mail.yahoo.com
> >
>
>
>
>
>
>  __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com

Re: creating a custom component by aggregation

Posted by Ionut S <si...@yahoo.com>.
I would accept your suggestion right away, but we really need to have a JSF component in order to add it to the tree component dynamically. Is this possible with facelets ?


Murray Brandon <mu...@hotmagna.com> wrote: With Facelets templating over the top of JSF it's dead easy - you just 
include some xhtml that has any number of components inside it:

                
                    
                    
value="#{selectedPerson.telephoneNo}"/>
                    
                

We use it for all our widget controls on this project even if its a 1:1 
correllation, that way we can chop and change which JSF components we 
use at the end of the day.
The only trick is for small sets of components you don't display/not 
display using  tags, but use of the rendered=" property on the 
components instead.
It works.

Regards, Murray

Ionut S wrote:
> Hi,
> I was wondering if somebody had any success in writing a custom 
> component that aggregates other existing components ?
>
> For example, creating a component that extends UIPanel and adding to 
> its children 2 existing components (a label and a combo box, let's say)..
>
> Thank you !
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>



 __________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: creating a custom component by aggregation

Posted by Murray Brandon <mu...@hotmagna.com>.
With Facelets templating over the top of JSF it's dead easy - you just 
include some xhtml that has any number of components inside it:

                <ui:include src="#{config.urlControls}text.xhtml">
                    <ui:param name="label" value="Telephone:"/>
                    <ui:param name="property" 
value="#{selectedPerson.telephoneNo}"/>
                    <ui:param name="rendered" value="true"/>
                </ui:include>

We use it for all our widget controls on this project even if its a 1:1 
correllation, that way we can chop and change which JSF components we 
use at the end of the day.
The only trick is for small sets of components you don't display/not 
display using <c:if> tags, but use of the rendered=" property on the 
components instead.
It works.

Regards, Murray

Ionut S wrote:
> Hi,
> I was wondering if somebody had any success in writing a custom 
> component that aggregates other existing components ?
>
> For example, creating a component that extends UIPanel and adding to 
> its children 2 existing components (a label and a combo box, let's say)..
>
> Thank you !
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>