0

Hi i am still trying to develope my own java controls for XPages. I wanted to knwo how i can use an existing control and use it in my new control.

Lets say i want to develope something like a login popup control. I Extended the UIDialog from com.ibm.xsp.extlib.component.dialog but how can i add a xp:inputText on it?

Ok, in this example i could add a xp:callback facet to the markup section in the control.xsp-config so i just need to drag some input fields on it like a standard control but what if i want it to be just one control wich i can deploy with the update site.

Update:

ok tried it out your solution keithstric. I guess you work direkt on your component. I use e renderer for my component. So is there a difference in the Component tree if i add the component with a renderer or direct in my component:

Renderer:

public class MyRenderer extends Renderer {

public void encodeBegin(FacesContext context, UIComponent component)throws IOException {
    ResponseWriter w = context.getResponseWriter();
    NewComponentXY comp = new ComponentXY();
    component.getChildren().add(comp);
}

or direct:

public class MyComponent extends UIComponentBase {

    public void encodeBegin(FacesContext context, UIComponent component)throws IOException {
        ResponseWriter w = context.getResponseWriter();
        NewComponentXY comp = new ComponentXY();
        this.getChildren().add(comp);
    }

Is there a difference in the jsf lifecycle?

Michael Saiz
  • 1,640
  • 12
  • 20
  • I haven't worked with IBM stuff. Are this JSF tools based on JSF 2 or JSF 1.2? – Luiggi Mendoza Apr 02 '13 at 13:25
  • Hmm.. XPages are based on JSF 1.x but maby i should remove the JSF Tag from the question – Michael Saiz Apr 02 '13 at 13:33
  • @maple_shaft Ahhhm i think you got something wrong i am developing in Lotus Notes XPages.. so i have to use the IBM Components, besides i took the jsf tag away but -Luiggi Mendoza addet them again- because this question is direkted more to XPages developers then jsf develpers... – Michael Saiz Apr 02 '13 at 14:05
  • @LuiggiMendoza XPages are build on JSF Technologie, but i think no pure JSF devoloper can answer this for me so i removed the jsf tag, thanks for your help but plz dont add the tag again. – Michael Saiz Apr 02 '13 at 14:08
  • @MichaelSaiz I retagged as JSF since you use JSF components. But well, hope that somebody could help you. – Luiggi Mendoza Apr 02 '13 at 14:09
  • @LuiggiMendoza jep i know, as i said it is based on JSF but i was wrong to tag it as jsf question... now it is ranked down...and i am still waiting and googeling for an answer. – Michael Saiz Apr 02 '13 at 14:12
  • I've upvoted your question. Happy now? :) – Luiggi Mendoza Apr 02 '13 at 14:13
  • Jup THX, but i think i still need an answer maby i should work it over again ^^ – Michael Saiz Apr 02 '13 at 14:15
  • @maple_shaft The XPage framework is based primarily on JSF 1.2, but supports much of the 2.0 specification, including view and application scope, ubiquitous Ajax integration... and composite controls. There's no flash scope, and it's not annotation-driven. Other than that, there's not much defined in JSF 2 that XPage developers are missing. In fact, most Domino developers are not Java developers. XPage applications are defined as XML files; with very few exceptions, only ISVs (and IBM itself) write components, so the vast majority of XPage developers couldn't care less about annotations. – Tim Tripcony Apr 15 '13 at 14:54
  • @TimTripcony Thank you for the information, I was unaware that IBM decided to rewrite JSF 2.0 in a vendor locked-in way. – maple_shaft Apr 15 '13 at 15:52

1 Answers1

1

First, to ensure we're all speaking the same language, what you're referring to as a "java control", that is actually a "component". This way it doesn't get confused with a custom control.

You'll need to inject any additional components in the encodeBegin method of the component, not the renderer's encodeBegin but the component's encodeBegin. To do this, you'll need a container of some sort either a panel or a div, if you don't need a data source I recommend a div. Then inject your username and password fields and any labels you might want into the div. Depending on how complex you want to be (i.e. a table with a column for the label and another column for the password) this code could get rather large. But a simple example would be:

XspDiv cont = new XspDiv();
cont.setId("loginFormContainer");
cont.setStyleClass("loginFormContainer");
XspInputText userName = new XspInputText();
userName.setId("userNameInputId");
Attr placeHolderAttr = new Attr();
placeHolderAttr.setComponent(userName);
placeHolderAttr.setName("placeholder");
placeHolderAttr.setValue("Enter your Username");
userName.addAttr(attr);

XspInputText password = new XspInputText();
password.setId("passwordInputId");
password.setPassword(true);
//NOTE: I can't get the placeholder attr to work on a password field but
//you can try as your mileage may vary

cont.getChildren().add(userName);
cont.getChildren().add(password);
this.getChildren().add(cont);

You can find 90% of the component classes available from IBM here along with a breakdown of all the component's properties. There is also an old article on my blog here about component injection and another on component development here. If the encodeBegin method is too late and requiring a partial refresh for the injected components to appear, you may want to add the FacesComponent interface and do the injection in the initBeforeContents method.

As a bonus, to fire a partial refresh, this will need to be done via CSJS. So take a look at

((UIViewRootEx2) FacesContext.getCurrentInstance().getViewRoot()).postScript("CSJS Code here");

keithstric
  • 1,053
  • 1
  • 11
  • 21