Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to program the content of the xhtml page programatically in JSF?  RSS feed

Santhosh Lakshmanan
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to program the below code programatically in JSF? Like custom component is rendering the output of the below code.

<html xmlns=""


<h:selectOneMenu value="#{managedBean.selectedValue}">
<f:selectItems value="#{managedBean.list}" />
<f:ajax event="change" update="output1"></f:ajax>
<h:outputLabel id="output1" value="Output 1"></h:outputLabel>
Tim Holloway
Posts: 18713
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general, I don't recommend doing that. Of all the apps I've worked on in JSF since 2006, only one builds up page components in code and if I had to re-write it, even that one probably wouldn't. It's a powerful feature, but generally speaking, it's better done using fixed elements with some EL-based rendering options or by use of something like a dataTable. For one thing, template elements are easier to understand when reading the app source and can be modified without recompiling code.

The "binding" attribute of JSF elements associates a backing bean's property with its corresponding JSF UIComponent. You can then use that as an anchor point, creating, destroying, and/or updating other elements by walking up and down the UIComponent tree. UIComponents are all JavaBean-style objects (meaning that they have a no-element default constructor), so the basic logic for all dynamic components is the same: instantiate the UIComponent object of your choice, then use its set/get methods to customize it. The next time your View gets rendered, the customizations render along with it. In fact, at that point, there's no distinction, since you're basically doing in miniature what the Component Tree services did for the entire View originally.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!