aspose file tools*
The moose likes JSF and the fly likes Dynamically Adding Components Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Dynamically Adding Components" Watch "Dynamically Adding Components" New topic
Author

Dynamically Adding Components

Andrew Rigsby
Greenhorn

Joined: Oct 05, 2006
Posts: 15
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamically Adding Components