1

我使用 myfaces-api-1.1.5.jar。(可悲的是,不能使用除此之外的任何东西!)

我想在运行时(即动态)从我的支持 bean testBB 创建以下内容。

<t:selectOneMenu 
    value="#{testBB.someVO}"
    converter="someVOConverter"
    valueChangeListener="#{testBB.vcl}"
    onchange="submit();" style="width:170px">

    <f:selectItems value="#{testBB.selectItemList}"/>
</t:selectOneMenu>

到目前为止,我的代码如下:

private UIComponent createComponent(
    String id, String componentType, UIComponent parent) {

    if (componentType == null) {
        throw new NullPointerException("argument 'componentType' is null");
    }

    if (parent == null) {
        throw new NullPointerException("argument 'parent' is null");
    }

    UIComponent newComponent = this.
        getApplication().createComponent(componentType);
    newComponent.setId(id);
    newComponent.setParent(parent);
    parent.getChildren().add(newComponent);
    logger.debug("new Component created.. ");

    return newComponent;
}

private HtmlSelectOneMenu createSelectOneMenu(
    String id, UIComponent parent, String expr) {
    HtmlSelectOneMenu selectOneMenu = 
        (HtmlSelectOneMenu) this.createComponent(id, 
        HtmlSelectOneMenu.COMPONENT_TYPE, parent);
    UISelectItems items = (UISelectItems)this.
        createComponent("selectItem", UISelectItems.COMPONENT_TYPE, selectOneMenu);
    ValueBinding valueBinding = this.getApplication().createValueBinding(expr);
    items.setValueBinding(id, valueBinding);

    return selectOneMenu;
}

我称之为:

this.createSelectOneMenu("someId", "somePanelGrid", "#{testBB.selectItemList}");

我尝试了 Google 并搜索了 StackOverflow,但找不到特定于 MyFaces 和 JSF 1.1 的任何内容。

所有帮助将不胜感激。

4

0 回答 0