public static void encodeFormSubmissionAjaxInactivityTimeout(FacesContext context) { ExternalContext externalContext = context.getExternalContext(); String paramStr = externalContext.getInitParameter(SUBMISSION_AJAX_INACTIVITY_TIMEOUT_CONTEXT_PARAM); long inactivityTimeout = DEFAULT_SUBMISSION_AJAX_INACTIVITY_TIMEOUT; if (paramStr != null) { try { final long parameterValue = Long.parseLong(paramStr); inactivityTimeout = Math.abs(parameterValue); } catch (NumberFormatException e) { externalContext.log( "Invalid value specified for context parameter named " + SUBMISSION_AJAX_INACTIVITY_TIMEOUT_CONTEXT_PARAM + ": it must be a number"); } } final ScriptBuilder script = new ScriptBuilder("O$.setSubmissionAjaxInactivityTimeout(" + inactivityTimeout + ");"); Rendering.appendOnLoadScript(context, script); }
private void processSessionExpirationUnderPortletsMyFaces( FacesContext context, UIViewRoot root, ExternalContext externalContext, Object session) { Object requestObject = context.getExternalContext().getRequest(); HttpServletRequest catalinaServletRequest = null; try { Class jbossRenderRequestClass = Class.forName("org.jboss.portlet.JBossRenderRequest"); Class abstractRequestContextClass = Class.forName("org.jboss.portal.portlet.impl.spi.AbstractRequestContext"); Class requestObjectClass = requestObject.getClass(); if (jbossRenderRequestClass.isAssignableFrom(requestObjectClass)) { Field requestContextField = requestObject .getClass() .getSuperclass() .getSuperclass() .getDeclaredField("requestContext"); requestContextField.setAccessible(true); Object requestContext = requestContextField.get(requestObject); Class requestContextClass = requestContext.getClass(); if (abstractRequestContextClass.isAssignableFrom(requestContextClass)) { Field reqField = requestContextClass.getDeclaredField("req"); reqField.setAccessible(true); Object req = reqField.get(requestContext); if (req instanceof HttpServletRequest) { catalinaServletRequest = (HttpServletRequest) req; } } } } catch (ClassNotFoundException e) { externalContext.log(e.getMessage()); } catch (NoSuchFieldException e) { externalContext.log(e.getMessage()); } catch (IllegalAccessException e) { externalContext.log(e.getMessage()); } if (AjaxUtil.isPortletRenderRequest(context) && !AjaxUtil.isAjaxRequest(context) && catalinaServletRequest != null && catalinaServletRequest.getParameterMap().size() > 0) { if (isNewSession(session)) { addAjaxRequestMarkerUnderPortlets(context, root); addSessionExpirationFlagUnderPortlets(context, root); } } if (Environment.isLiferay(context.getExternalContext().getRequestMap())) { if (context .getExternalContext() .getSessionMap() .containsKey(AjaxViewHandler.SESSION_EXPIRATION_PROCESSING)) { addAjaxRequestMarkerUnderPortlets(context, root); addSessionExpirationFlagUnderPortlets(context, root); context .getExternalContext() .getSessionMap() .remove(AjaxViewHandler.SESSION_EXPIRATION_PROCESSING); } } }
@Override public void renderView(FacesContext context, UIViewRoot root) throws IOException, FacesException { Components.runScheduledActions(); if (!context.getResponseComplete()) { ExternalContext externalContext = context.getExternalContext(); Object session = externalContext.getSession(false); Map<String, Object> requestMap = externalContext.getRequestMap(); if (externalContext.getSessionMap().containsKey(ERROR_OCCURRED_UNDER_PORTLETS)) { processExceptionUnderPortlets(context); return; } if (AjaxUtil.isPortletRequest(context) && Environment.isMyFaces() && isNewSession(externalContext.getSession(false))) { processSessionExpirationUnderPortletsMyFaces(context, root, externalContext, session); } if (AjaxUtil.isPortletRequest(context) && Environment.isRI() && isNewSession(externalContext.getSession(false))) { processSessionExpirationUnderPortletsRI(context, root, externalContext); } boolean ajaxRequest = AjaxUtil.isAjaxRequest(context); if (!ajaxRequest && !AjaxUtil.isAjax4jsfRequest()) ValidationSupportResponseWriter.resetBubbleIndex(context); if (ajaxRequest) { updateSessionExpirationFlagUnderPortlets(context, root, externalContext, requestMap); try { // HACK for MyFaces ( <f:view> tag not call renderers ) // ServletResponse response = (ServletResponse) context // .getExternalContext().getResponse(); Object response = externalContext.getResponse(); if (!AjaxUtil.isPortletRequest(context)) { try { response.getClass().getDeclaredMethod("resetResponse").invoke(response); // response.reset(); } catch (Exception e) { // Do nothing - we will use directly and reset // wrapper } } if (requestMap.containsKey(SESSION_EXPIRATION_PROCESSING)) { super.renderView(context, root); // This is done for MyFaces use-case, because MyFaces doesn't call rendering methods for // ViewRoot if (!Environment.isRI()) { root.encodeChildren(context); } Map<String, Object> sessionMap = context.getExternalContext().getSessionMap(); if (sessionMap != null && !sessionMap.containsKey(SESSION_SCOPED_PARAMETER)) { sessionMap.put(SESSION_SCOPED_PARAMETER, Boolean.TRUE.toString()); } return; } if (Environment.isFacelets(context)) { super.renderView(context, root); } else { root.encodeBegin(context); if (root.getRendersChildren()) { root.encodeChildren(context); } root.encodeEnd(context); } } catch (RuntimeException e) { CommonAjaxViewRoot.processExceptionDuringAjax(context, e); externalContext.log(e.getMessage(), e); } catch (Error e) { CommonAjaxViewRoot.processExceptionDuringAjax(context, e); externalContext.log(e.getMessage(), e); } } else { super.renderView(context, root); Map<String, Object> sessionMap = context.getExternalContext().getSessionMap(); if (sessionMap != null && !sessionMap.containsKey(SESSION_SCOPED_PARAMETER)) { sessionMap.put(SESSION_SCOPED_PARAMETER, Boolean.TRUE.toString()); } if (AjaxUtil.isAjax4jsfRequest()) { Resources.processHeadResources(context); } } } }