public static UIComponent addPersistent( FacesContext context, ServletRequest req, UIComponent parent, ValueExpression binding, Class childClass) throws Exception { if (context == null) context = FacesContext.getCurrentInstance(); if (parent == null) { UIComponentClassicTagBase parentTag = (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent"); parent = parentTag.getComponentInstance(); BodyContent body = parentTag.getBodyContent(); addVerbatim(parent, body); } UIComponent child = null; if (binding != null) child = (UIComponent) binding.getValue(context.getELContext()); if (child == null) { child = (UIComponent) childClass.newInstance(); // jsf/3251 if (binding != null) binding.setValue(context.getELContext(), child); } if (parent != null) parent.getChildren().add(child); return child; }
public static UIComponent addFacet( FacesContext context, ServletRequest req, UIComponent parent, String facetName, ValueExpression binding, Class childClass) throws Exception { if (context == null) context = FacesContext.getCurrentInstance(); if (parent == null) { UIComponentClassicTagBase parentTag = (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent"); parent = parentTag.getComponentInstance(); } UIComponent child = null; if (binding != null) child = (UIComponent) binding.getValue(context.getELContext()); if (child == null) child = (UIComponent) childClass.newInstance(); if (parent != null) parent.getFacets().put(facetName, child); if (binding != null) binding.setValue(context.getELContext(), child); return child; }
private void doSetBindings(ELContext elContext, UIComponent component) { if (component == null) return; ValueExpression binding = component.getValueExpression("binding"); if (binding != null) binding.setValue(elContext, component); Iterator<UIComponent> iter = component.getFacetsAndChildren(); while (iter.hasNext()) doSetBindings(elContext, iter.next()); }
static final String evalString(ValueExpression expr, FacesContext context) { try { return (String) expr.getValue(context.getELContext()); } catch (ELException e) { throw new FacesException(e); } }
static final int evalInt(ValueExpression expr, FacesContext context) { try { return (Integer) expr.getValue(context.getELContext()); } catch (ELException e) { throw new FacesException(e); } }
static final boolean evalBoolean(ValueExpression expr, FacesContext context) { try { Object value = expr.getValue(context.getELContext()); if (value == null) return false; else if (value instanceof Boolean) return ((Boolean) value).booleanValue(); else if (value instanceof String) return "true".equalsIgnoreCase((String) value); else return false; } catch (ELException e) { throw new FacesException(e); } }
/** Sets the value expression with the given name. */ @Override public void setValueExpression(String name, ValueExpression expr) { PropEnum prop = _propMap.get(name); if (prop != null) { switch (prop) { case DIR: if (expr != null && expr.isLiteralText()) { _dir = Util.evalString(expr); return; } else _dirExpr = expr; break; case ESCAPE: if (expr != null && expr.isLiteralText()) { _escape = Util.evalBoolean(expr); return; } else _escapeExpr = expr; break; case LANG: if (expr != null && expr.isLiteralText()) { _lang = Util.evalString(expr); return; } else _langExpr = expr; break; case STYLE: if (expr != null && expr.isLiteralText()) { _style = Util.evalString(expr); return; } else _styleExpr = expr; break; case STYLE_CLASS: if (expr != null && expr.isLiteralText()) { _styleClass = Util.evalString(expr); return; } else _styleClassExpr = expr; break; case TITLE: if (expr != null && expr.isLiteralText()) { _title = Util.evalString(expr); return; } else _titleExpr = expr; break; } } super.setValueExpression(name, expr); }
/** Sets the value expression with the given name. */ @Override public void setValueExpression(String name, ValueExpression expr) { PropEnum prop = _propMap.get(name); if (prop != null) { switch (prop) { case DIR: if (expr != null && expr.isLiteralText()) { _dir = Util.evalString(expr); return; } else _dirExpr = expr; break; case ERROR_CLASS: if (expr != null && expr.isLiteralText()) { _errorClass = Util.evalString(expr); return; } else _errorClassExpr = expr; break; case ERROR_STYLE: if (expr != null && expr.isLiteralText()) { _errorStyle = Util.evalString(expr); return; } else _errorStyleExpr = expr; break; case FATAL_CLASS: if (expr != null && expr.isLiteralText()) { _fatalClass = Util.evalString(expr); return; } else _fatalClassExpr = expr; break; case FATAL_STYLE: if (expr != null && expr.isLiteralText()) { _fatalStyle = Util.evalString(expr); return; } else _fatalStyleExpr = expr; break; case INFO_CLASS: if (expr != null && expr.isLiteralText()) { _infoClass = Util.evalString(expr); return; } else _infoClassExpr = expr; break; case INFO_STYLE: if (expr != null && expr.isLiteralText()) { _infoStyle = Util.evalString(expr); return; } else _infoStyleExpr = expr; break; case LANG: if (expr != null && expr.isLiteralText()) { _lang = Util.evalString(expr); return; } else _langExpr = expr; break; case STYLE: if (expr != null && expr.isLiteralText()) { _style = Util.evalString(expr); return; } else _styleExpr = expr; break; case STYLE_CLASS: if (expr != null && expr.isLiteralText()) { _styleClass = Util.evalString(expr); return; } else _styleClassExpr = expr; break; case TITLE: if (expr != null && expr.isLiteralText()) { _title = Util.evalString(expr); return; } else _titleExpr = expr; break; case TOOLTIP: if (expr != null && expr.isLiteralText()) { _tooltip = Util.evalBoolean(expr); return; } else _tooltipExpr = expr; break; case WARN_CLASS: if (expr != null && expr.isLiteralText()) { _warnClass = Util.evalString(expr); return; } else _warnClassExpr = expr; break; case WARN_STYLE: if (expr != null && expr.isLiteralText()) { _warnStyle = Util.evalString(expr); return; } else _warnStyleExpr = expr; break; } } super.setValueExpression(name, expr); }
private void printComponentTree( PrintWriter out, String errorId, FacesContext context, UIComponent comp, int depth) { for (int i = 0; i < depth; i++) out.print(' '); boolean isError = false; if (errorId != null && errorId.equals(comp.getClientId(context))) { isError = true; out.print("<span style='color:red'>"); } out.print("<" + comp.getClass().getSimpleName()); if (comp.getId() != null) out.print(" id=\"" + comp.getId() + "\""); for (Method method : comp.getClass().getMethods()) { if (!method.getName().startsWith("get") && !method.getName().startsWith("is")) continue; else if (method.getParameterTypes().length != 0) continue; String name; if (method.getName().startsWith("get")) name = method.getName().substring(3); else if (method.getName().startsWith("is")) name = method.getName().substring(2); else continue; // XXX: getURL name = Character.toLowerCase(name.charAt(0)) + name.substring(1); ValueExpression expr = comp.getValueExpression(name); Class type = method.getReturnType(); if (expr != null) { out.print(" " + name + "=\"" + expr.getExpressionString() + "\""); } else if (method.getDeclaringClass().equals(UIComponent.class) || method.getDeclaringClass().equals(UIComponentBase.class)) { } else if (name.equals("family")) { } else if (String.class.equals(type)) { try { Object value = method.invoke(comp); if (value != null) out.print(" " + name + "=\"" + value + "\""); } catch (Exception e) { } } } int facetCount = comp.getFacetCount(); int childCount = comp.getChildCount(); if (facetCount == 0 && childCount == 0) { out.print("/>"); if (isError) out.print("</span>"); out.println(); return; } out.println(">"); if (isError) out.print("</span>"); for (int i = 0; i < childCount; i++) { printComponentTree(out, errorId, context, comp.getChildren().get(i), depth + 1); } for (int i = 0; i < depth; i++) out.print(' '); if (isError) out.print("<span style='color:red'>"); out.println("</" + comp.getClass().getSimpleName() + ">"); if (isError) out.print("</span>"); }
static Object saveWithType(ValueExpression expr, FacesContext context) { if (expr != null) { return new Object[] {expr.getExpressionString(), expr.getExpectedType()}; } else return null; }
static String save(ValueExpression expr, FacesContext context) { if (expr != null) return expr.getExpressionString(); else return null; }