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 restoreView(FacesContext context) throws FacesException { Application app = context.getApplication(); if (app instanceof ApplicationImpl) ((ApplicationImpl) app).initRequest(); ViewHandler view = app.getViewHandler(); view.initView(context); UIViewRoot viewRoot = context.getViewRoot(); if (viewRoot != null) { ExternalContext extContext = context.getExternalContext(); viewRoot.setLocale(extContext.getRequestLocale()); doSetBindings(context.getELContext(), viewRoot); return; } String viewId = calculateViewId(context); String renderKitId = view.calculateRenderKitId(context); RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY); RenderKit renderKit = renderKitFactory.getRenderKit(context, renderKitId); ResponseStateManager stateManager = renderKit.getResponseStateManager(); if (stateManager.isPostback(context)) { viewRoot = view.restoreView(context, viewId); if (viewRoot != null) { doSetBindings(context.getELContext(), viewRoot); } else { // XXX: backward compat issues with ViewHandler and StateManager // throw new ViewExpiredException(L.l("{0} is an expired view", viewId)); context.renderResponse(); viewRoot = view.createView(context, viewId); context.setViewRoot(viewRoot); } context.setViewRoot(viewRoot); } else { context.renderResponse(); viewRoot = view.createView(context, viewId); context.setViewRoot(viewRoot); } }
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 ValueExpression restore(Object value, Class type, FacesContext context) { if (value == null) return null; String expr = (String) value; Application app = context.getApplication(); ExpressionFactory factory = app.getExpressionFactory(); return factory.createValueExpression(context.getELContext(), expr, type); }
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); } }
static ValueExpression restoreWithType(Object value, FacesContext context) { if (value == null) return null; Object[] state = (Object[]) value; String expr = (String) state[0]; Class type = (Class) state[1]; Application app = context.getApplication(); ExpressionFactory factory = app.getExpressionFactory(); return factory.createValueExpression(context.getELContext(), expr, type); }