public void render(FacesContext context) throws FacesException { if (context.getResponseComplete()) return; Application app = context.getApplication(); ViewHandler view = app.getViewHandler(); beforePhase(context, PhaseId.RENDER_RESPONSE); try { if (log.isLoggable(Level.FINER)) log.finer(context.getViewRoot() + " before render view"); view.renderView(context, context.getViewRoot()); } catch (java.io.IOException e) { if (sendError(context, "renderView", e)) return; throw new FacesException(e); } catch (RuntimeException e) { if (sendError(context, "renderView", e)) return; throw e; } finally { afterPhase(context, PhaseId.RENDER_RESPONSE); logMessages(context); } }
public static void refresh() { FacesContext context = FacesContext.getCurrentInstance(); Application application = context.getApplication(); ViewHandler viewHandler = application.getViewHandler(); UIViewRoot viewRoot = viewHandler.createView(context, context.getViewRoot().getViewId()); context.setViewRoot(viewRoot); }
public void execute(FacesContext facesContext) throws FacesException { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Entering RenderResponsePhase"); } if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("About to render view " + facesContext.getViewRoot().getViewId()); } // For requests intended to produce a partial response, we need prohibit // writing any content outside of the view itself (f:view). PartialViewContext partialViewContext = facesContext.getPartialViewContext(); if (partialViewContext.isAjaxRequest()) { OnOffResponseWrapper onOffResponse = new OnOffResponseWrapper(facesContext); onOffResponse.setEnabled(false); } try { ViewHandler vh = facesContext.getApplication().getViewHandler(); ViewDeclarationLanguage vdl = vh.getViewDeclarationLanguage(facesContext, facesContext.getViewRoot().getViewId()); if (vdl != null) { vdl.buildView(facesContext, facesContext.getViewRoot()); } boolean viewIdsUnchanged; do { String beforePublishViewId = facesContext.getViewRoot().getViewId(); // the before render event on the view root is a special case to keep door open for // navigation // this must be called *after* PDL.buildView() and before VH.renderView() facesContext .getApplication() .publishEvent(facesContext, PreRenderViewEvent.class, facesContext.getViewRoot()); String afterPublishViewId = facesContext.getViewRoot().getViewId(); viewIdsUnchanged = beforePublishViewId == null && afterPublishViewId == null || (beforePublishViewId != null && afterPublishViewId != null) && beforePublishViewId.equals(afterPublishViewId); } while (!viewIdsUnchanged); // render the view vh.renderView(facesContext, facesContext.getViewRoot()); } catch (IOException e) { throw new FacesException(e.getMessage(), e); } if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.log( Level.FINEST, "+=+=+=+=+=+= View structure printout for " + facesContext.getViewRoot().getViewId()); DebugUtil.printTree(facesContext.getViewRoot(), LOGGER, Level.FINEST); } if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Exiting RenderResponsePhase"); } }
/** Reload the current active page. */ public static void reloadPage() { FacesContext context = FacesContext.getCurrentInstance(); String viewId = context.getViewRoot().getViewId(); ViewHandler handler = context.getApplication().getViewHandler(); UIViewRoot root = handler.createView(context, viewId); root.setViewId(viewId); context.setViewRoot(root); }
public static String getAjaxActionPath() { ViewHandler viewHandler = FacesUtils.context().getApplication().getViewHandler(); String viewId = FacesUtils.context().getViewRoot().getViewId(); String queryString = FacesUtils.getRequest().getQueryString(); queryString = Strings.ifEmpty(queryString, ""); if (Strings.isEmpty(queryString)) { queryString = ""; } else { queryString = "?" + queryString; } return viewHandler.getActionURL(FacesUtils.context(), viewId) + queryString; }
/** * Determine the next view based on the current view (<code>from-view-id</code> stored in <code> * FacesContext</code>), <code>fromAction</code> and <code>outcome</code>. * * @param context The <code>FacesContext</code> * @param fromAction the action reference string * @param outcome the outcome string */ public void handleNavigation(FacesContext context, String fromAction, String outcome) { if (context == null) { String message = MessageUtils.getExceptionMessageString( MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "context"); throw new NullPointerException(message); } if (outcome == null) { return; // Explicitly remain on the current view } CaseStruct caseStruct = getViewId(context, fromAction, outcome); ExternalContext extContext = context.getExternalContext(); if (caseStruct != null) { ViewHandler viewHandler = Util.getViewHandler(context); assert (null != viewHandler); if (caseStruct.navCase.isRedirect()) { // perform a 302 redirect. String newPath = viewHandler.getActionURL(context, caseStruct.viewId); try { if (logger.isLoggable(Level.FINE)) { logger.fine( "Redirecting to path " + newPath + " for outcome " + outcome + "and viewId " + caseStruct.viewId); } // encode the redirect to ensure session state // is maintained extContext.redirect(extContext.encodeActionURL(newPath)); } catch (java.io.IOException ioe) { if (logger.isLoggable(Level.SEVERE)) { logger.log(Level.SEVERE, "jsf.redirect_failed_error", newPath); } throw new FacesException(ioe.getMessage(), ioe); } context.responseComplete(); if (logger.isLoggable(Level.FINE)) { logger.fine("Response complete for " + caseStruct.viewId); } } else { UIViewRoot newRoot = viewHandler.createView(context, caseStruct.viewId); context.setViewRoot(newRoot); if (logger.isLoggable(Level.FINE)) { logger.fine("Set new view in FacesContext for " + caseStruct.viewId); } } } }
/** * Do not call the default implementation of {@link * javax.faces.application.ViewHandler#initView(javax.faces.context.FacesContext)} if the {@link * javax.faces.context.ExternalContext#getRequestCharacterEncoding()} returns a <code>non-null * </code> result. * * @see javax.faces.application.ViewHandler#initView(javax.faces.context.FacesContext) */ @Override public void initView(FacesContext context) throws FacesException { if (context.getExternalContext().getRequestCharacterEncoding() == null) { super.initView(context); } }
/** * Jsf dispatch page. * * @param fctx the faces context * @param page the pge */ private void jsfDispatchPage(FacesContext fctx, String page) { LifecycleFactory lf = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); Lifecycle lifecycle = lf.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE); ViewHandler vh = fctx.getApplication().getViewHandler(); fctx.getViewRoot().setRenderKitId(vh.calculateRenderKitId(fctx)); fctx.setViewRoot(vh.createView(fctx, page)); // view rendering try { lifecycle.render(fctx); } catch (Exception e) { LOG.log(Level.INFO, "Error while rendering page. Attempting again" + page, e); lifecycle.render(fctx); } finally { fctx.release(); } }
public UIViewRoot restoreView(FacesContext arg0, String arg1) { UIViewRoot root = m_wrapped.restoreView(arg0, arg1); if (root != null) { // restore messages MessageSaver.restoreMessages(arg0); } return root; }
/** @see javax.faces.context.FacesContext#isPostback() */ @Override public boolean isPostback() { assertNotReleased(); Boolean postback = (Boolean) this.getAttributes().get(POST_BACK_MARKER); if (postback == null) { RenderKit rk = this.getRenderKit(); if (rk != null) { postback = rk.getResponseStateManager().isPostback(this); } else { // ViewRoot hasn't been set yet, so calculate the RK ViewHandler vh = this.getApplication().getViewHandler(); String rkId = vh.calculateRenderKitId(this); postback = RenderKitUtils.getResponseStateManager(this, rkId).isPostback(this); } this.getAttributes().put(POST_BACK_MARKER, postback); } return postback; }
public void renderView(FacesContext context, UIViewRoot viewRoot) throws IOException, FacesException { String viewId = viewRoot.getViewId(); if (!context.getResponseComplete() && isMapped(viewId)) { NavigationHandler nh = context.getApplication().getNavigationHandler(); ViewHandler vh = context.getApplication().getViewHandler(); String action = (String) context.getExternalContext().getRequestParameterMap().get("action"); String outcome = (String) context.getExternalContext().getRequestParameterMap().get("outcome"); if (action != null) { String method = extractMethodName(action); MethodBinding mb = context.getApplication().createMethodBinding("#{" + action + "}", new Class[0]); outcome = mb.invoke(context, new Object[0]).toString(); nh.handleNavigation(context, method, outcome); if (!context.getResponseComplete() && context.getViewRoot().equals(viewRoot)) { throw new FacesException( "No navigation rules from viewId=" + viewId + ", action=" + action + ", outcome=" + outcome + " found."); } } else { nh.handleNavigation(context, null, outcome); if (!context.getResponseComplete() && context.getViewRoot().equals(viewRoot)) { throw new FacesException( "No navigation rules from viewId=" + viewId + ", outcome=" + outcome + " found."); } } if (!context.getResponseComplete()) { vh.renderView(context, context.getViewRoot()); } ; } else { viewHandler.renderView(context, viewRoot); } }
@Override public void beforePhase(PhaseEvent event) { FacesContext facesContext = event.getFacesContext(); ExternalContext externalContext = facesContext.getExternalContext(); HttpSession httpSession = (HttpSession) externalContext.getSession(false); boolean newSession = (httpSession == null) || (httpSession.isNew()); boolean postBack = !externalContext.getRequestParameterMap().isEmpty(); boolean timedOut = postBack && newSession; if (timedOut) { Application application = facesContext.getApplication(); ViewHandler viewHandler = application.getViewHandler(); UIViewRoot view = viewHandler.createView(facesContext, "/main.xhtml"); facesContext.setViewRoot(view); facesContext.renderResponse(); try { viewHandler.renderView(facesContext, view); facesContext.responseComplete(); } catch (Exception e) { throw new FacesException("Session timed out", e); } } }
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); } }
// executa antes de qualquer renderizar ao usuário public void beforePhase(PhaseEvent event) { FacesContext context = FacesContext.getCurrentInstance(); String viewId = context.getViewRoot().getViewId(); System.out.println("View ID:" + viewId); // verifica as páginas que não possuem acesso externo if (viewId.equals("/admin/formCategoria.xhtml") || viewId.equals("/admin/formProduto.xhtml") || viewId.equals("/admin/home.xhtml") || viewId.equals("/admin/mostrarCategorias.xhtml") || viewId.equals("/admin/mostrarProdutos.xhtml") || viewId.equals("/admin/mostrarCompras.xhtml")) { // recupera os dados que estão em // sessão em adminController Application app = context.getApplication(); AdminController adminEmSessao = (AdminController) app.evaluateExpressionGet(context, "#{adminController}", AdminController.class); // se não houver administrador logado if (adminEmSessao.getAdmin().getId() == null) { // armazena a página ao qual o usuário está // tentando entrar em sessão // através da classe AdminController adminEmSessao.setOriginalViewId(viewId); // em seguida, cria a árvore de componentes // para a página admin.jsf // que exigirá o login e senha ViewHandler viewHandler = app.getViewHandler(); UIViewRoot viewRoot = viewHandler.createView(context, "/admin/admin.xhtml"); context.setViewRoot(viewRoot); } } }
public void renderView(FacesContext context, UIViewRoot root) throws IOException, FacesException { // SAK-20286 start // Get the request HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest(); String requestURI = req.getRequestURI(); // Make the attribute name unique to the request String attrName = "sakai.jsf.tool.URL.loopDetect.viewId-" + requestURI; // Try to fetch the attribute Object attribute = req.getAttribute(attrName); // If the attribute is null, this is the first request for this view if (attribute == null) { req.setAttribute(attrName, "true"); } else if ("true".equals(attribute)) { // A looping request is detected. HttpServletResponse res = (HttpServletResponse) context.getExternalContext().getResponse(); // Send a 404 res.sendError(404, "File not found: " + requestURI); } // SAK-20286 end m_wrapped.renderView(context, root); }
public String getActionURL(FacesContext context, String viewId) { HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest(); if (req.getAttribute(URL_EXT) == null) { // If the request didn't go through JsfTool (the JSF is accessed directly from its webapp, // not as a Sakai tool), then don't do Sakai's special action URL handling. return m_wrapped.getActionURL(context, viewId); } // get the path that got us here (from the tool's point of view) String path = viewId; // modify the path to remove things that were added by Sakai navigation to get here (prefix // path, suffix extension) String prefix = (String) req.getAttribute(URL_PATH); if ((prefix != null) && path.startsWith(prefix)) path = path.substring(prefix.length()); Object extensions = req.getAttribute(URL_EXT); String[] exts = extensions instanceof String ? new String[] {(String) extensions} : (String[]) extensions; for (String ext : exts) { if ((ext != null) && path.endsWith(ext)) path = path.substring(0, path.length() - ext.length()); } // make sure the URL processing uses the Sakai, not Native the request object so we can get at // the URL information setup by the invoker req.removeAttribute(Tool.NATIVE_URL); // form our return URL String rv = Web.returnUrl(req, path); // restore (if needed) req.setAttribute(Tool.NATIVE_URL, Tool.NATIVE_URL); M_log.debug("action url for view: " + viewId + " = " + rv); return rv; }
public String getResourceURL(FacesContext context, String strUID) { return viewHandler.getResourceURL(context, strUID); }
public String getActionURL(FacesContext context, String strUID) { return viewHandler.getActionURL(context, strUID); }
public UIViewRoot createView(FacesContext context, String strUID) { UIViewRoot ret = viewHandler.createView(context, strUID); return ret; }
public String calculateRenderKitId(FacesContext context) { return viewHandler.calculateRenderKitId(context); }
public Locale calculateLocale(FacesContext context) { return viewHandler.calculateLocale(context); }
public String calculateRenderKitId(FacesContext arg0) { return m_wrapped.calculateRenderKitId(arg0); }
protected void execute(String renderRedirectViewId) throws BridgeException, IOException { init(renderRequest, renderResponse, Bridge.PortletPhase.RENDER_PHASE); // If the portlet mode has not changed, then restore the faces view root and messages that would // have been saved during the ACTION_PHASE of the portlet lifecycle. Section 5.4.1 requires that // the // BridgeRequestScope must not be restored if there is a change in portlet modes detected. boolean facesLifecycleExecuted = bridgeRequestScope.isFacesLifecycleExecuted(); bridgeRequestScope.restoreState(facesContext); if (bridgeRequestScope.isPortletModeChanged()) { bridgeRequestScopeCache.remove(bridgeRequestScope.getId()); } // If a render-redirect URL was specified, then it is necessary to create a new view from the // URL and place it // in the FacesContext. if (renderRedirectViewId != null) { renderRequest.setAttribute(BridgeExt.RENDER_REDIRECT_AFTER_DISPATCH, Boolean.TRUE); ViewHandler viewHandler = facesContext.getApplication().getViewHandler(); UIViewRoot uiViewRoot = viewHandler.createView(facesContext, renderRedirectViewId); facesContext.setViewRoot(uiViewRoot); logger.debug("Performed render-redirect to viewId=[{0}]", renderRedirectViewId); } // NOTE: PROPOSE-FOR-BRIDGE3-API Actually, the proposal would be to REMOVE // Bridge.IS_POSTBACK_ATTRIBUTE from the Bridge API, because JSF 2.0 introduced the // FacesContext#isPostBack() method. // http://javaserverfaces.java.net/nonav/docs/2.0/javadocs/javax/faces/context/FacesContext.html#isPostback() if (bridgeRequestScope.getBeganInPhase() == Bridge.PortletPhase.ACTION_PHASE) { ExternalContext externalContext = facesContext.getExternalContext(); externalContext.getRequestMap().put(Bridge.IS_POSTBACK_ATTRIBUTE, Boolean.TRUE); } logger.debug( "portletName=[{0}] facesLifecycleExecuted=[{1}]", portletName, facesLifecycleExecuted); // If the JSF lifecycle executed back in the ACTION_PHASE of the portlet lifecycle, then if (facesLifecycleExecuted) { // TCK TestPage054: prpUpdatedFromActionTest PhaseEvent restoreViewPhaseEvent = new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, facesLifecycle); PhaseListener[] phaseListeners = facesLifecycle.getPhaseListeners(); for (PhaseListener phaseListener : phaseListeners) { if (phaseListener instanceof IPCPhaseListener) { phaseListener.afterPhase(restoreViewPhaseEvent); break; } } } // Otherwise, in accordance with Section 5.2.6 of the Spec, execute the JSF lifecycle so that // ONLY the // RESTORE_VIEW phase executes. Note that this is accomplished by the // RenderRequestPhaseListener. else { try { ExternalContext externalContext = facesContext.getExternalContext(); String viewId = getFacesViewId(externalContext); logger.debug("Executing Faces lifecycle for viewId=[{0}]", viewId); } catch (BridgeException e) { logger.error("Unable to get viewId due to {0}", e.getClass().getSimpleName()); throw e; } // Attach the JSF 2.2 client window to the JSF lifecycle so that Faces Flows can be utilized. attachClientWindowToLifecycle(facesContext, facesLifecycle); // Execute the JSF lifecycle. facesLifecycle.execute(facesContext); } // If there were any "handled" exceptions queued, then throw a BridgeException. Throwable handledException = getJSF2HandledException(facesContext); if (handledException != null) { throw new BridgeException(handledException); } // Otherwise, if there were any "unhandled" exceptions queued, then throw a BridgeException. Throwable unhandledException = getJSF2UnhandledException(facesContext); if (unhandledException != null) { throw new BridgeException(unhandledException); } // Otherwise, if the PortletMode has changed, and a navigation-rule hasn't yet fired (which // could have happened // in the EVENT_PHASE), then switch to the appropriate PortletMode and navigate to the current // viewId in the // UIViewRoot. if (bridgeRequestScope.isPortletModeChanged() && !bridgeRequestScope.isNavigationOccurred()) { BridgeNavigationHandler bridgeNavigationHandler = getBridgeNavigationHandler(facesContext); PortletMode fromPortletMode = bridgeRequestScope.getPortletMode(); PortletMode toPortletMode = renderRequest.getPortletMode(); bridgeNavigationHandler.handleNavigation(facesContext, fromPortletMode, toPortletMode); } // Determines whether or not lifecycle incongruities should be managed. boolean manageIncongruities = PortletConfigParam.ManageIncongruities.getBooleanValue(portletConfig); // Now that we're executing the RENDER_PHASE of the Portlet lifecycle, before the JSF // RENDER_RESPONSE phase is executed, we have to fix some incongruities between the Portlet // lifecycle and the JSF lifecycle that may have occurred during the ACTION_PHASE of the Portlet // lifecycle. if (manageIncongruities) { incongruityContext.makeCongruous(facesContext); } // Execute the RENDER_RESPONSE phase of the faces lifecycle. logger.debug("Executing Faces render"); facesLifecycle.render(facesContext); // Set the view history according to Section 5.4.3 of the Bridge Spec. setViewHistory(facesContext.getViewRoot().getViewId()); // Spec 6.6 (Namespacing) indicateNamespacingToConsumers(facesContext.getViewRoot(), renderResponse); // If a render-redirect occurred, then ExternalContext externalContext = facesContext.getExternalContext(); Writer writer = getResponseOutputWriter(externalContext); Map<String, Object> requestMap = externalContext.getRequestMap(); Boolean renderRedirect = (Boolean) requestMap.remove(BridgeExt.RENDER_REDIRECT); if ((renderRedirect != null) && renderRedirect) { // Cleanup the old FacesContext since a new one will be created in the recursive method call // below. facesContext.responseComplete(); facesContext.release(); // If the render-redirect standard feature is enabled in web.xml or portlet.xml, then the // ResponseOutputWriter has buffered up markup that must be discarded. This is because we // don't want the // markup from the original Faces view to be included with the markup of Faces view found in // the // redirect URL. if (writer instanceof RenderRedirectWriter) { RenderRedirectWriter responseOutputWriter = (RenderRedirectWriter) writer; responseOutputWriter.discard(); } // Recursively call this method with the render-redirect URL so that the RENDER_RESPONSE phase // of the // JSF lifecycle will be re-executed according to the new Faces viewId found in the redirect // URL. renderRedirectViewId = (String) requestMap.remove(BridgeExt.RENDER_REDIRECT_VIEW_ID); execute(renderRedirectViewId); } // Otherwise, else { // In the case that a render-redirect took place, need to render the buffered markup to the // response. if (writer instanceof RenderRedirectWriter) { RenderRedirectWriter responseOutputWriter = (RenderRedirectWriter) writer; responseOutputWriter.render(); } } }
/** * PRECONDITION: the necessary factories have been installed in the ServletContext attr set. * * <p> * * <p>POSTCONDITION: The facesContext has been initialized with a tree. */ public void execute(FacesContext facesContext) throws FacesException { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Entering RestoreViewPhase"); } if (null == facesContext) { throw new FacesException( MessageUtils.getExceptionMessageString(MessageUtils.NULL_CONTEXT_ERROR_MESSAGE_ID)); } // If an app had explicitely set the tree in the context, use that; // UIViewRoot viewRoot = facesContext.getViewRoot(); if (viewRoot != null) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Found a pre created view in FacesContext"); } facesContext.getViewRoot().setLocale(facesContext.getExternalContext().getRequestLocale()); // do per-component actions UIViewRoot root = facesContext.getViewRoot(); final PostRestoreStateEvent event = new PostRestoreStateEvent(root); try { root.visitTree( VisitContext.createVisitContext(facesContext), new VisitCallback() { public VisitResult visit(VisitContext context, UIComponent target) { event.setComponent(target); target.processEvent(event); return VisitResult.ACCEPT; } }); } catch (AbortProcessingException e) { facesContext .getApplication() .publishEvent( ExceptionQueuedEvent.class, new ExceptionQueuedEventContext(facesContext, e)); } if (!facesContext.isPostback()) { facesContext.renderResponse(); } return; } // Reconstitute or create the request tree Map requestMap = facesContext.getExternalContext().getRequestMap(); String viewId = (String) requestMap.get("javax.servlet.include.path_info"); if (viewId == null) { viewId = facesContext.getExternalContext().getRequestPathInfo(); } // It could be that this request was mapped using // a prefix mapping in which case there would be no // path_info. Query the servlet path. if (viewId == null) { viewId = (String) requestMap.get("javax.servlet.include.servlet_path"); } if (viewId == null) { viewId = facesContext.getExternalContext().getRequestServletPath(); } if (viewId == null) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning("viewId is null"); } throw new FacesException( MessageUtils.getExceptionMessageString(MessageUtils.NULL_REQUEST_VIEW_ERROR_MESSAGE_ID)); } ViewHandler viewHandler = Util.getViewHandler(facesContext); boolean isPostBack = (facesContext.isPostback() && !isErrorPage(facesContext)); if (isPostBack) { // try to restore the view viewRoot = viewHandler.restoreView(facesContext, viewId); if (viewRoot == null) { if (is11CompatEnabled(facesContext)) { // 1.1 -> create a new view and flag that the response should // be immediately rendered if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Postback: recreating a view for " + viewId); } viewRoot = viewHandler.createView(facesContext, viewId); facesContext.renderResponse(); } else { Object[] params = {viewId}; throw new ViewExpiredException( MessageUtils.getExceptionMessageString( MessageUtils.RESTORE_VIEW_ERROR_MESSAGE_ID, params), viewId); } } facesContext.setViewRoot(viewRoot); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Postback: restored view for " + viewId); } } else { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("New request: creating a view for " + viewId); } ViewDeclarationLanguage vdl = facesContext .getApplication() .getViewHandler() .getViewDeclarationLanguage(facesContext, viewId); if (vdl != null) { // If we have one, get the ViewMetadata... ViewMetadata metadata = vdl.getViewMetadata(facesContext, viewId); if (metadata != null) { // perhaps it's not supported // and use it to create the ViewRoot. This will have, at most // the UIViewRoot and its metadata facet. viewRoot = metadata.createMetadataView(facesContext); // Only skip to render response if there are no view parameters Collection<UIViewParameter> params = ViewMetadata.getViewParameters(viewRoot); if (params.isEmpty()) { facesContext.renderResponse(); } } } else { facesContext.renderResponse(); } if (null == viewRoot) { viewRoot = (Util.getViewHandler(facesContext)).createView(facesContext, viewId); } facesContext.setViewRoot(viewRoot); assert (null != viewRoot); facesContext.getApplication().publishEvent(PostAddToViewEvent.class, viewRoot); } if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Exiting RestoreViewPhase"); } }
public void writeState(FacesContext arg0) throws IOException { m_wrapped.writeState(arg0); }
public UIViewRoot restoreView(FacesContext context, String viewId) { UIViewRoot ret = viewHandler.restoreView(context, viewId); return ret; }
public String getResourceURL(FacesContext arg0, String arg1) { return m_wrapped.getResourceURL(arg0, arg1); }
public void writeState(FacesContext context) throws IOException { viewHandler.writeState(context); }
private String processException(Exception exp, int flag) { String message = ""; String type = ""; Date requestDate = null; Date reviewDate = null; switch (flag) { case 0: LoanProfile loanProfile = ((DuplicateLoanProfileException) exp).getLoanProfile(); type = loanProfile.getProfileState().getCode(); requestDate = loanProfile.getRequestDate(); reviewDate = loanProfile.getReviewDate(); break; case 1: ExchangeProfile exchangeProfile = ((DuplicateExchangeProfileException) exp).getExchangeProfile(); type = exchangeProfile.getProfileState().getCode(); requestDate = exchangeProfile.getRequestDate(); reviewDate = exchangeProfile.getReviewDate(); break; case 2: ProberProfile proberProfile = ((DuplicateProberProfileException) exp).getProberProfile(); type = proberProfile.getProfileState().getCode(); requestDate = proberProfile.getRequestDate(); reviewDate = proberProfile.getReviewDate(); break; } if (type.equalsIgnoreCase(ProfileState.NEW_REQUEST_STATE)) { message = JsfUtils.getStringFromBundle("yourRequestForUnit") + " " + JsfUtils.getStringFromBundle(this.selectedUnitOrLib.getName()) + JsfUtils.getStringFromBundle("andMembershipAt") + " " + JsfUtils.getStringFromBundle( UserManagementDataMap.convertRequestType(this.selectedRequestType)) + JsfUtils.getStringFromBundle("inDate") + " " + String.valueOf(requestDate) + JsfUtils.getStringFromBundle("isRegisteredAndCurrentlyIsUnderProcessing"); } else if (type.equalsIgnoreCase(ProfileState.CONFIRMED_REQUEST_STATE)) { message = JsfUtils.getStringFromBundle("yourRequestForUnit") + " " + JsfUtils.getStringFromBundle(this.selectedUnitOrLib.getName()) + JsfUtils.getStringFromBundle("andMembershipAt") + " " + JsfUtils.getStringFromBundle( UserManagementDataMap.convertRequestType(this.selectedRequestType)) + JsfUtils.getStringFromBundle("inDate") + " " + String.valueOf(requestDate) + JsfUtils.getStringFromBundle("isRegisteredAndInDate") + " " + String.valueOf(reviewDate) + JsfUtils.getStringFromBundle("havebeenRejected") + JsfUtils.getStringFromBundle("wouldYouLikeToSubmitANewRequest"); } else if (type.equalsIgnoreCase(ProfileState.REJECTED_REQUEST_STATE)) { message = JsfUtils.getStringFromBundle("yourRequestForUnit") + " " + JsfUtils.getStringFromBundle(this.selectedUnitOrLib.getName()) + JsfUtils.getStringFromBundle("andMembershipAt") + " " + JsfUtils.getStringFromBundle( UserManagementDataMap.convertRequestType(this.selectedRequestType)) + JsfUtils.getStringFromBundle("inDate") + " " + String.valueOf(requestDate) + JsfUtils.getStringFromBundle("isConfirmed"); } else assert true : "Invalid Profile State!!!"; FacesContext context = FacesContext.getCurrentInstance(); ViewHandler viewHandler = context.getApplication().getViewHandler(); UIViewRoot dialog = viewHandler.createView(context, "/usermanagement/generalPages/showMessagePage.jspx"); Map properties = new HashMap(); properties.put("width", new Integer(300)); properties.put("height", new Integer(400)); Map params = new HashMap(); params.put(UserManagementConstants.DIALOG_MESSAGE, message); RequestContext requestContext = RequestContext.getCurrentInstance(); requestContext.launchDialog(dialog, params, null, true, properties); return ""; }
@Override public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException { ResponseWriter responseWriter = facesContext.getResponseWriter(); InputFile inputFile = (InputFile) uiComponent; JavaScriptFragment alloyNamespace = new JavaScriptFragment("A"); // Determine the valid content-types and maximum file size from the validator (if specified). JavaScriptFragment contentTypes = new JavaScriptFragment("[]"); String validContentTypes = inputFile.getContentTypes(); if (validContentTypes != null) { contentTypes = toJavaScriptArray(validContentTypes.split(",")); } String clientId = inputFile.getClientId(facesContext); Long maxFileSize = inputFile.getMaxFileSize(); if (maxFileSize == null) { maxFileSize = Long.MAX_VALUE; } // If the component should render the upload progress table, then initialize the YUI progress // uploader widget. if (inputFile.isShowProgress()) { String clientVarName = getClientVarName(facesContext, inputFile); String clientKey = inputFile.getClientKey(); if (clientKey == null) { clientKey = clientVarName; } UIViewRoot viewRoot = facesContext.getViewRoot(); Locale locale = viewRoot.getLocale(); String formClientId = getParentFormClientId(inputFile); Application application = facesContext.getApplication(); ViewHandler viewHandler = application.getViewHandler(); String actionURL = viewHandler.getActionURL(facesContext, viewRoot.getViewId()); String partialActionURL = facesContext.getExternalContext().encodePartialActionURL(actionURL); String namingContainerId = ""; if (viewRoot instanceof NamingContainer) { namingContainerId = viewRoot.getContainerClientId(facesContext); } AjaxParameters ajaxParameters = new AjaxParameters(inputFile, clientId, formClientId); String execute = ajaxParameters.getExecute(); String render = ajaxParameters.getRender(); String notStartedMessage = getMessageContext().getMessage(locale, "not-started"); JavaScriptFragment clientComponent = new JavaScriptFragment("Liferay.component('" + clientKey + "')"); encodeFunctionCall( responseWriter, "LFAI.initProgressUploader", alloyNamespace, clientComponent, contentTypes, clientId, formClientId, namingContainerId, inputFile.isAuto(), execute, render, partialActionURL, maxFileSize, notStartedMessage); } // Otherwise, if the component should render the upload preview table, then format the // preview-uploader.js // template and write it to the response. else if (inputFile.isShowPreview()) { encodeFunctionCall( responseWriter, "LFAI.initPreviewUploader", alloyNamespace, contentTypes, clientId, maxFileSize); } }