File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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?
 
 
subject: Dynamically Adding Components
 
Similar Threads
JSF
call a action method with h:commandButton
How to add new text boxes and check boxes dynamically when clicking on button in JSF
selectOneMenu ValueChangeListener not Firing
dynamic panel grid binding