1 28 29 package javax.faces.component.html; 30 31 import java.util.*; 32 33 import javax.el.*; 34 35 import javax.faces.*; 36 import javax.faces.application.*; 37 import javax.faces.context.*; 38 import javax.faces.convert.*; 39 40 final class Util 41 { 42 static Object eval(ValueExpression expr) 43 { 44 try { 45 return expr.getValue(currentELContext()); 46 } catch (ELException e) { 47 throw new FacesException(e); 48 } 49 } 50 51 static boolean evalBoolean(ValueExpression expr) 52 { 53 try { 54 return (Boolean ) expr.getValue(currentELContext()); 55 } catch (ELException e) { 56 throw new FacesException(e); 57 } 58 } 59 60 static int evalInt(ValueExpression expr) 61 { 62 try { 63 return (Integer ) expr.getValue(currentELContext()); 64 } catch (ELException e) { 65 throw new FacesException(e); 66 } 67 } 68 69 static String evalString(ValueExpression expr) 70 { 71 try { 72 return (String ) expr.getValue(currentELContext()); 73 } catch (ELException e) { 74 throw new FacesException(e); 75 } 76 } 77 78 static String save(ValueExpression expr, 79 FacesContext context) 80 { 81 if (expr != null) 82 return expr.getExpressionString(); 83 else 84 return null; 85 } 86 87 static ValueExpression restore(Object value, 88 Class type, 89 FacesContext context) 90 { 91 if (value == null) 92 return null; 93 94 String expr = (String ) value; 95 96 Application app = context.getApplication(); 97 ExpressionFactory factory = app.getExpressionFactory(); 98 99 return factory.createValueExpression(context.getELContext(), 100 expr, 101 type); 102 } 103 104 static ELContext currentELContext() 105 { 106 FacesContext facesContext = FacesContext.getCurrentInstance(); 107 108 if (facesContext != null) 109 return facesContext.getELContext(); 110 else 111 return null; 112 } 113 } 114 | Popular Tags |