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

jackyluck 2007-12-06 03:30:28
我想在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";
}
...全文
100 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧