• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Santhosh Lakshmanan
Greenhorn
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="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">

<h:head>
<title>AjaxBehavior</title>
</h:head>

<h:form>
<h:selectOneMenu value="#{managedBean.selectedValue}">
<f:selectItems value="#{managedBean.list}" />
<f:ajax event="change" update="output1"></f:ajax>
</h:selectOneMenu>
<br/>
<h:outputLabel id="output1" value="Output 1"></h:outputLabel>
</h:form>
</html>
 
Tim Holloway
Bartender
Posts: 18531
61
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!