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); }