I see, sorry I wasn't paying attention to your constructor.


Try creating your components with something like this...


...
...

        street = createHtmlInputText("street");
        number = createHtmlInputText("number");
        town = createHtmlInputText("town");
        postCode = createHtmlInputText("postCode");
        command = createHtmlCommandButton("command");

...
...
}

protected HtmlInputText createHtmlInputText(String id) {
Application application = FacesContext.getCurrentInstance ().getApplication();

        HtmlInputText intput =
(HtmlInputText)application.createComponent (HtmlInputText.COMPONENT_TYPE);
        input.setId(id);
        return input;
}
protected HtmlInputText createHtmlCommandButton(String id) {
Application application = FacesContext.getCurrentInstance ().getApplication();
...
...




The problem is in how you are creating new components. It isn't enough just to do new HtmlXXX(), you must create them with the createComponent method. There's a few things going on under the covers with respect to how JSF deals with components. You might also think about getting a good book or referencing a tutorial while building your app. There's a lot more to JSF than meets the eye.


--
James Mitchell




On Jul 13, 2006, at 2:44 PM, delbd wrote:

No, am creating a JSF component on it's own (with it's own tag), like this
<mytaglib:mycomponent id="someId" value="#{myBean}"/>


James Mitchell a écrit :

Assuming you are using JSP, how are using this on your page?  With
your own taglib or binding to an existing instance?  If you are
simply binding a standard HtmlPanelGrid and then declaring child
components, you will need to bind any nested components as well.


--
James Mitchell




On Jul 13, 2006, at 10:01 AM, 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;
    }






Reply via email to