1 5 package org.exoplatform.faces; 6 import javax.faces.application.Application; 7 import javax.faces.component.UIComponent; 8 import javax.faces.context.ExternalContext; 9 import javax.faces.context.FacesContext; 10 import javax.faces.el.ValueBinding; 11 import javax.portlet.PortletPreferences; 12 import javax.portlet.PortletRequest; 13 import javax.servlet.ServletContext ; 14 22 public class FacesUtil { 23 24 static public PortletPreferences getPortletPreferences() { 25 PortletRequest request = 26 (PortletRequest) FacesContext.getCurrentInstance(). 27 getExternalContext().getRequest() ; 28 return request.getPreferences() ; 29 } 30 31 static public String getApplicationRealPath(String s) { 32 FacesContext context = FacesContext.getCurrentInstance() ; 33 ExternalContext econtext = context.getExternalContext() ; 34 ServletContext scontext = (ServletContext ) econtext.getContext() ; 35 return scontext.getRealPath(s) ; 36 } 37 38 static public ServletContext getServletContext() { 39 FacesContext context = FacesContext.getCurrentInstance() ; 40 ExternalContext econtext = context.getExternalContext() ; 41 return (ServletContext ) econtext.getContext() ; 42 } 43 44 public static boolean isValueReference(String elexpr) { 46 return (elexpr != null && elexpr.startsWith("#{") && elexpr.endsWith("}")); 47 } 48 49 public static void createValueBinding(FacesContext context, 51 UIComponent uiComp, String key, 52 String elexpr) { 53 if (isValueReference(elexpr)) { 54 Application app = context.getApplication(); 55 if (uiComp.getValueBinding(key) == null) { 56 uiComp.setValueBinding(key, app.createValueBinding(elexpr)); 57 } 58 } 59 } 60 61 public static boolean updateBoundValueBinding(FacesContext context, 63 UIComponent uiComp, String key, 64 Object value) { 65 boolean b = false; 66 ValueBinding vb = uiComp.getValueBinding(key); 67 if (vb != null) { 69 vb.setValue(context, value); 70 b = true; 71 } 72 return b; 73 } 74 75 public static Object resolveBoundValueBinding(FacesContext context, 77 UIComponent uiComp, String key) { 78 Object value = null; 79 ValueBinding vb = uiComp.getValueBinding(key); if (vb != null) 81 value = vb.getValue(context); 82 return value; 83 } 84 } | Popular Tags |