Expanding Rich tree nodes programmatically

Posted on 9 CommentsPosted in Uncategorized

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 […]

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

Posted on Leave a commentPosted in java

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 […]

Preventing ViewExpiredException in JSF

Posted on 35 CommentsPosted in Uncategorized

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; […]

Use argument in EL expression

Posted on Leave a commentPosted in java

There is couple ways about doing that, you could use JBoss EL expression implementation they support method calls with parameters check out Seam, or use similar approach as @digitaljoel suggested. This is what I created for that purpose, you can call static and static methods, not a great solution but it does the job. <c:if […]

Display all managed-beans in JSF at runtime

Posted on Leave a commentPosted in Uncategorized

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 […]

Serving resources using Resource PhaseListener

Posted on 1 CommentPosted in Uncategorized

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; […]