/** * Shortcut for {@link PartialViewContext#isAjaxRequest()}. * * @return <code>true</code> if the current request is a AJAX request. */ public boolean isAjaxRequest() { return getFacesContext().getPartialViewContext().isAjaxRequest(); }
protected boolean isGetLifecycleInfoRequest(FacesContext facesContext) { if (!facesContext.getPartialViewContext().isAjaxRequest()) { return false; } String source = facesContext.getExternalContext().getRequestParameterMap().get(Constants.RequestParams.PARTIAL_SOURCE_PARAM); if (LangUtils.isValueBlank(source)) { return false; } return facesContext.getExternalContext().getRequestParameterMap().containsKey(source + "_getlifecycleinfo"); } }
@Override public void beforePhase(PhaseEvent event) { FacesContext context = event.getFacesContext(); if (!context.isPostback() || PrimeRequestContext.getCurrentInstance(context).isIgnoreAutoUpdate()) { return; } List<String> clientIds = AutoUpdateListener.getAutoUpdateComponentClientIds(context); if (clientIds != null && !clientIds.isEmpty()) { for (int i = 0; i < clientIds.size(); i++) { String clientId = clientIds.get(i); if (!context.getPartialViewContext().getRenderIds().contains(clientId)) { context.getPartialViewContext().getRenderIds().add(clientId); } } } }
/** * Updates all components with the given expressions or clientIds. * * @param expressions a list of expressions or clientIds. */ public void update(Collection<String> expressions) { if (expressions == null || expressions.isEmpty()) { return; } FacesContext facesContext = getFacesContext(); for (String expression : expressions) { if (LangUtils.isValueBlank(expression)) { continue; } try { String clientId = SearchExpressionFacade.resolveClientId(facesContext, facesContext.getViewRoot(), expression); facesContext.getPartialViewContext().getRenderIds().add(clientId); } catch (ComponentNotFoundException e) { LOGGER.log(Level.WARNING, "PrimeFaces.current().ajax().update() called but component can't be resolved!" + "Expression will just be added to the renderIds.", e); facesContext.getPartialViewContext().getRenderIds().add(expression); } } }
ResetInputContextCallback contextCallback = null; for (String renderId : context.getPartialViewContext().getRenderIds()) { if (LangUtils.isValueBlank(renderId) || renderId.trim().equals(SearchExpressionConstants.NONE_KEYWORD)) { continue;
if (context.getPartialViewContext().isAjaxRequest()) { PrimeFaces.current().executeScript("if (document.getElementById('g-recaptcha-response')) { " + "try { grecaptcha.reset(); } catch (error) { PrimeFaces.error(error); } }");
if (context.getPartialViewContext().isAjaxRequest()) { handleAjaxException(context, rootCause, info);
@Override public void encodeEnd(FacesContext context, UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); encodeResources(context); if (!context.getPartialViewContext().isAjaxRequest()) { encodeOnloadScripts(writer); } writer.endElement("body"); }
@Override public void afterPhase(PhaseEvent event) { FacesContext context = event.getFacesContext(); // we only need to collect resources on ajax requests // for non ajax, the head will always be rendered again if (context.getViewRoot() == null || !context.getPartialViewContext().isAjaxRequest()) { return; } // we can also skip non-postback ajax requests, which occurs e.g. without a form if (!context.isPostback()) { return; } // skip update=@all as the head, with all resources, will already be rendered if (context.getPartialViewContext().isRenderAll()) { return; } // JSF 2.3 contains a own dynamic resource handling if (PrimeApplicationContext.getCurrentInstance(context).getEnvironment().isAtLeastJsf23()) { return; } // collect all current resources before new components can be added to the view in later phases List<ResourceUtils.ResourceInfo> initialResources = ResourceUtils.getComponentResources(context); putInitialResources(context, initialResources); }
&& !context.getPartialViewContext().isRenderAll() && !applicationContext.getEnvironment().isAtLeastJsf23()) { List<ResourceUtils.ResourceInfo> initialResources = DynamicResourcesPhaseListener.getInitialResources(context);
public WidgetBuilder init(String widgetClass, String widgetVar, String id) throws IOException { this.renderScriptBlock(id); // AJAX case: since jQuery 3 document ready ($(function() {})) are executed async // this would mean that our oncomplete handlers are probably called before the scripts in the update nodes // or // we can also skip it when MOVE_SCRIPTS_TO_BOTTOM is enabled as the scripts are already executed when everything is ready if ((context.isPostback() && context.getPartialViewContext().isAjaxRequest()) || configuration.isMoveScriptsToBottom()) { this.init(widgetClass, widgetVar, id, false); } else { context.getResponseWriter().write("$(function(){"); this.init(widgetClass, widgetVar, id, true); } return this; }
if (responseResetted && context.getPartialViewContext().isAjaxRequest()) { PartialResponseWriter writer = context.getPartialViewContext().getPartialResponseWriter(); externalContext.addResponseHeader("Content-Type", "text/xml; charset=" + externalContext.getResponseCharacterEncoding()); externalContext.addResponseHeader("Cache-Control", "no-cache"); if (externalContext.isResponseCommitted() && !context.getPartialViewContext().isAjaxRequest()) { PartialResponseWriter writer = context.getPartialViewContext().getPartialResponseWriter(); writer.startElement("script", null); writer.write("window.location.href = '" + url + "';");
protected void handleAjaxException(FacesContext context, Throwable rootCause, ExceptionInfo info) throws Exception { ExternalContext externalContext = context.getExternalContext(); PartialResponseWriter writer = context.getPartialViewContext().getPartialResponseWriter();
/** * <p>The default behavior of this method is to * call {@link FacesContext#getPartialViewContext()} ()} * on the wrapped {@link FacesContext} object.</p> * * @see javax.faces.context.FacesContext#getPartialViewContext() */ @Override public PartialViewContext getPartialViewContext() { return getWrapped().getPartialViewContext(); }
/** * <p>The default behavior of this method is to * call {@link FacesContext#getPartialViewContext()} ()} * on the wrapped {@link FacesContext} object.</p> * * @see javax.faces.context.FacesContext#getPartialViewContext() */ @Override public PartialViewContext getPartialViewContext() { return getWrapped().getPartialViewContext(); }
@Override public PartialViewContext getPartialViewContext() { return getWrapped().getPartialViewContext(); }
@Override public ExceptionHandler getWrapped() { FacesContext fc = FacesContext.getCurrentInstance(); if (null != fc && fc.getPartialViewContext().isAjaxRequest()) { return ajaxExceptionHandlerImpl; } return exceptionHandlerImpl; }
private void updateRenderTargets(FacesContext ctx, String newId) { if (ctx.getViewRoot() == null || !ctx.getViewRoot().getViewId().equals(newId)) { PartialViewContext pctx = ctx.getPartialViewContext(); if (!pctx.isRenderAll()) { pctx.setRenderAll(true); } } }
/** * Shortcut for {@link PartialViewContext#isAjaxRequest()}. * * @return <code>true</code> if the current request is a AJAX request. */ public boolean isAjaxRequest() { return getFacesContext().getPartialViewContext().isAjaxRequest(); }
private void processPartialExecute(UIViewRoot viewRoot, PhaseId phaseId) { PartialViewContext pvc = _facesContext.getPartialViewContext(); Collection<String> executeIds = pvc.getExecuteIds(); if (executeIds == null || executeIds.isEmpty()) { return; } VisitContext visitCtx = getVisitContextFactory().getVisitContext(_facesContext, executeIds, PARTIAL_EXECUTE_HINTS); viewRoot.visitTree(visitCtx, new PhaseAwareVisitCallback(_facesContext, phaseId)); }