How to build a control programatically?

Posted by W_K on Stack Overflow See other posts from Stack Overflow or by W_K
Published on 2012-06-08T11:48:55Z Indexed on 2012/06/09 10:40 UTC
Read the original article Hit count: 220

Filed under:
|

I have custom control written in Java. For the sake of simplicity lets assume that it looks like this:

public class HelloworldControl extends UIComponentBase {
    @Override
    public void decode(FacesContext context) {
        String cid = this.getClientId(context);
        ...
        super.decode(context);
    }

    @Override
    public void encodeBegin(FacesContext context) throws IOException {
        ResponseWriter writer = context.getResponseWriter();
        writer.writeText("Hello world!", this);
        // I want a view!!
    }

    @Override
    public void encodeEnd(FacesContext context) throws IOException {
         ResponseWriter writer = context.getResponseWriter();
         ...
    }

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

    public Object saveState(FacesContext context) {
        Object values[] = ...
    }
}

I would like to add programatically child control to it. For example I would like a child view control to render a view just under the Hellow world text.

How can i do this? What is the standard procedure to build dynamically a control?

To put it simply - I want programatically build a hierarchy of standard components and I want to attach it to my control.

© Stack Overflow or respective owner

Related posts about xpages

Related posts about lotus-domino