我使用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的内容。
非常感谢所有帮助。