0

How can I dynamically add UIComponent into JSF view from managed bean without using JavaScript?

What I want is to simply display additional elements on the page when the response return like inputText when a button is fire.

How can I do this programmatically from JSF manage bean?

Tot Zam
  • 8,406
  • 10
  • 51
  • 76
Ellie Fabrero
  • 791
  • 2
  • 16
  • 41

1 Answers1

1

You should not add the component dynamically. Simply add it where it belongs, but render it conditionally using the rendered-attribute.

<ui:inputText value="#{yourBean.text}" rendered="#{yourBean.isRendered}" />

You can now use the boolean property isRendered in your backing-bean to determine if the inputText should be rendered or not. A component that has rendered="false" will not appear in the final component-tree, and thus not generate any html-output or other overhead.

Björn Pollex
  • 75,346
  • 28
  • 201
  • 283
  • i'm just experimenting. i know that it is not a good solution to render it from the backing bean. But for example i want to add component when just needed,how am i going to achieve that? – Ellie Fabrero Oct 13 '11 at 09:37