myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From delbd <>
Subject Re: Custom component with childrens
Date Thu, 13 Jul 2006 18:58:28 GMT
Mike Kienenberger a écrit :

> Composite components are hard to do in standard JSF.
> There's a year-old example where I did something like this at the
> following URL.  I remember having similar issues and fixing them.
> Composite components are a lot easier if you add facelets into the mix
> as it can all be done in templating code.
> You might also be able to use a jsp:include if your composition is
> simple enough.
No, my composition will not be simple in the end  and i need to provide
a simple to use taglib. (with elements like '<mylib:myComponent
value=.... id=..../>'
Thanks for you example, it seems you are going a similar way to mine,
thought your check to know if you need to generate childrens seems
cleaner than mine. I will study it further at work tomorrow ^^.

If i might ask an additionnal question, my component will be a composite
component containing fields but also actions. I need somehow to be able
to know on which bean the action will be invoked. I thought about doing
it this way: action="#{theBean.theAction()}". The problem for my
composite component is that "theBean" is the result of value field of my
component tag. So i don't really know how my 'createChildrens()' method
is supposed to initialize  the action parameter of HtmlCommandButton. I
tried to set an intermediate bean in the request attributes and
reference it in action, but, while it works for input fields value, this
intermediate field is not available at action method evaluation time.
Have you experience with composite component containg actions?

Thanks for your time,
Delbecq David

> On 7/13/06, David Delbecq <> wrote:
>> Hello all,
>> Starting to learn JSF, i tried to create my custom UI component. Because
>> it will be made of several fields and button, i decided to extends
>> HTMLPanelGrid. The constructor creates the various components part of
>> the Panel. After getting "funny" errors in console, i worked on a step
>> by step and noticed in restore view, myfaces does inject childs in my
>> component (so the number of child is double: those created at
>> intanciation of my component and those saved from previous instance and
>> injected as part of restore view).
>> My question is, considering the way i do it for now (which is bad ;) ),
>> what is the best way to avoid this restore view problem. How can my
>> component know if it is in a state where it need to create itself it's
>> children or in a state where the controller will restore the children
>> tree itself?
>> Thank for help.
>> public class HTMLAddressComponent extends HtmlPanelGrid implements
>>         NamingContainer {
>> .....
>>     public HTMLAddressComponent(){
>>         street = new HtmlInputText();
>>         number = new HtmlInputText();
>>         town = new HtmlInputText();
>>         postCode = new HtmlInputText();
>>         command = new HtmlCommandButton();
>>         command.setValue("enable/disable");
>>         street.setId("street");
>>         number.setId("number");
>>         town.setId("town");
>>         postCode.setId("postCode");
>>         command.setId("command");
>>         List childs = getChildren();
>>         HtmlPanelGroup group = new HtmlPanelGroup();
>>         List l = group.getChildren();
>>         l.add(getText("Street: "));
>>         l.add(street);
>>         l.add(getText("Number: "));
>>         l.add(number);
>>         childs.add(group);
>>         group = new HtmlPanelGroup();
>>         l = group.getChildren();
>>         l.add(getText("postcode: "));
>>         l.add(postCode);
>>         l.add(getText("Town: "));
>>         l.add(town);
>>         childs.add(group);
>>         childs.add(command);
>>     }
>>     private UIComponent getText(String value){
>>         HtmlOutputText text = new HtmlOutputText();
>>         text.setValue(value);
>>         return text;
>>     }

View raw message