myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Kienenberger" <mkien...@gmail.com>
Subject Re: Custom component with childrens
Date Thu, 13 Jul 2006 18:25:46 GMT
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.

http://issues.apache.org/jira/secure/attachment/12311217/RowAndColumnRelationshipComponent.zip

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.

On 7/13/06, David Delbecq <delbd@oma.be> 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;
>     }
>
>
>

Mime
View raw message