jsf

Expanding Rich tree nodes programmatically

I have found two different methods for expanding nodes in Rich tree  from code, they both take  advantage of component binding and component state. Tree Setup <rich:tree value="#{ourbean.sampleTree}" binding="#{ourbean.sampleTreeBinding}"   var="node" nodeFace="simple" id="someid" > <rich:treeNode type="simple" > <h:outputText value="#{node}"/> </rich:treeNode> </rich:tree><rich:tree value="#{ourbean.sampleTree}" binding="#{ourbean.sampleTreeBinding}" var="node" nodeFace="simple" id="someid" > <rich:treeNode type="simple" > <h:outputText value="#{node}"/> </rich:treeNode> </rich:tree> Only thing to …

Expanding Rich tree nodes programmatically Read More »

How to read the files placed in WEB-INF from JSF

Reading files from WEB-INF in JSF This no different than reading files from a Servlet except it involves a extra step of getting ServletContext from FacesContext FacesContext context = FacesContext.getCurrentInstance(); ExternalContext externalContext = context.getExternalContext(); ServletContext sc = (ServletContext)externalContext.getContext(); String sc.getRealPath("/WEB-INF/somefile.xml");FacesContext context = FacesContext.getCurrentInstance(); ExternalContext externalContext = context.getExternalContext(); ServletContext sc = (ServletContext)externalContext.getContext(); String sc.getRealPath("/WEB-INF/somefile.xml"); Here we …

How to read the files placed in WEB-INF from JSF Read More »

Preventing ViewExpiredException in JSF

When our page is idle for x amount of time the view will expire and throw javax.faces.application.ViewExpiredException to prevent this from happening one solution is to create CustomViewHandler that extends ViewHandler and override restoreView method all the other methods are being delegated to the Parent import java.io.IOException; import javax.faces.FacesException; import javax.faces.application.ViewHandler; import javax.faces.component.UIViewRoot; import javax.faces.context.FacesContext; …

Preventing ViewExpiredException in JSF Read More »

Display all managed-beans in JSF at runtime

Sometimes we like to see whats going on under the hood of jsf application (Checkout my JSFConsole). One such task is being able to display all the registered managed-beans during runtime. Here we can see all registered beans, including implicit object(cookie,header,param etc…) Result a4j a4jSkin ajaxContext ajaxHandler application applicationScope beeHive — My Managed bean cookie …

Display all managed-beans in JSF at runtime Read More »

Serving resources using Resource PhaseListener

PhaseListener designed to serve resources like css, javascript, images, pdf etc.. from jar file ResourcePhaseListener.java All required files can be downloaded here. package com.gregbugaj.jsfdump.console;   import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.Map;   import javax.activation.MimetypesFileTypeMap; import javax.faces.context.FacesContext; import javax.faces.event.PhaseEvent; import javax.faces.event.PhaseId; import javax.faces.event.PhaseListener; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse;   import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; …

Serving resources using Resource PhaseListener Read More »