如何在管理bean添加jsf 控件?

jackyluck jackyluck 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我想在JSF的管理bean用代码动态添加jsf控件,请高指导,我试过最终不成功
下面就是我的不成功的代码:
管理bean:
public String show()
{
// ExternalContext context;
//context.setViewRoot(view);
try
{
FacesContext context = FacesContext.getCurrentInstance();
Application app = context.getApplication();

UIViewRoot view = context.getViewRoot();
view.setViewId("/WEB-INF/jsp/index.jsp");
//UIViewRoot view =(UIViewRoot)app.getViewHandler().createView(context,"/WEB-INF/jsp/index.jsp");
//context.setViewRoot(view);

HtmlOutputText outputText1 = (HtmlOutputText)context.getApplication().createComponent(HtmlOutputText.COMPONENT_TYPE);
outputText1.setValue("---the outputText1 value---");
outputText1.setId("inputText1" + 23);
outputText1.setRendered(true);

HtmlInputText inputText1 = (HtmlInputText)context.getApplication().createComponent(HtmlInputText.COMPONENT_TYPE);
inputText1.setValue("---the inputText1 value---");
inputText1.setId("inputText1" + 22);
inputText1.setRendered(true);




UIComponent form1 = (UIComponent) view.getChildren().get(0);


this.getComponent().getChildren().add(outputText1);
this.getComponent().getChildren().add(inputText1);
// form1.getChildren().add(outputText1);
// form1.getChildren().add(inputText1);

view.setParent(component);
// view.setParent(form1);

context.setViewRoot(view);

}
catch(Exception e)
{
this.setMessage(e.toString());
}
return "indexpage";
}
...全文
评论
收藏 已收藏
分享
返回顶部
jackyluck
Java EE 67,535 成员 225,843 内容