Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamically Adding Components

 
Andrew Rigsby
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to add components to the JSF tree at runtime within an event listener but the added components aren't displayed. My code is as follows:

*** jsp page ***
<h:form id="jsfForm">
<h:commandButton type="submit" value="Submit" immediate="true" action="#{actionBean.processAction}">
</h:commandButton>
</h:form>

*** actionBean.processAction implementation ***
FacesContext fContext = FacesContext.getCurrentInstance();
Application app = fContext.getApplication();
UIViewRoot view = fContext.getViewRoot();

UIComponent form = view.findComponent("jsfForm");
HtmlOutputText newComponent = (HtmlOutputText) app.createComponent("javax.faces.HtmlOutputText");
newComponent.setId(view.createUniqueId());
newComponent.setRendered(true);
newComponent.setValue("Text");
form.getChildren().add(newComponent);

return "success";

Could anyone suggest why the added HtmlOutputText component isn't displayed?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic