0

嗨,我仍在尝试为 XPages 开发我自己的 java 控件。我想知道如何使用现有控件并在新控件中使用它。

可以说我想开发类似登录弹出控件的东西。我扩展了 UIDialog ,com.ibm.xsp.extlib.component.dialog但我怎么能xp:inputText在它上面添加一个?

好的,在这个例子中,我可以xp:callback在标记部分添加一个方面,control.xsp-config所以我只需要像标准控件一样在其上拖动一些输入字段,但是如果我希望它只是一个可以与更新站点一起部署的控件怎么办.

更新:

好的,尝试了您的解决方案 keithstric。我猜你在你的组件上工作。我为我的组件使用 e 渲染器。如果我使用渲染器添加组件或直接在我的组件中添加组件,那么组件树是否存在差异:

渲染器:

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);
}

或直接:

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);
    }

jsf生命周期有区别吗?

4

1 回答 1

1

首先,为了确保我们都说同一种语言,您所说的“java 控件”实际上是一个“组件”。这样它就不会与自定义控件混淆。

您需要在组件的 encodeBegin 方法中注入任何其他组件,而不是渲染器的 encodeBegin,而是组件的 encodeBegin。为此,您需要一个面板或 div 的某种容器,如果您不需要数据源,我推荐使用 div。然后将您的用户名和密码字段以及您可能想要的任何标签注入 div。根据您想要的复杂程度(即一个表,其中一列用于标签,另一列用于密码),此代码可能会变得相当大。但一个简单的例子是:

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);

您可以在此处找到 IBM 提供的 90% 的组件类以及所有组件属性的细分。我的博客上还有一篇关于组件注入的旧文章,还有一篇关于组件开发的文章。如果 encodeBegin 方法为时已晚并且需要部分刷新才能显示注入的组件,您可能需要添加 FacesComponent 接口并在 initBeforeContents 方法中进行注入。

作为奖励,要触发部分刷新,这需要通过 CSJS 完成。所以看看

((UIViewRootEx2) FacesContext.getCurrentInstance().getViewRoot()).postScript("这里是CSJS代码");

于 2013-04-02T14:23:04.080 回答