protected void handleRedirect(FacesContext context, Throwable rootCause, ExceptionInfo info, boolean responseResetted) throws IOException { ExternalContext externalContext = context.getExternalContext(); externalContext.getSessionMap().put(ExceptionInfo.ATTRIBUTE_NAME, info); String url = externalContext.getRequestContextPath() + errorPage; 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"); externalContext.setResponseContentType("text/xml"); writer.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); writer.startElement("partial-response", null); writer.startElement("redirect", null); writer.writeAttribute("url", url, null); writer.endElement("redirect"); if (externalContext.isResponseCommitted() && !context.getPartialViewContext().isAjaxRequest()) { PartialResponseWriter writer = context.getPartialViewContext().getPartialResponseWriter(); writer.startElement("script", null); writer.write("window.location.href = '" + url + "';"); writer.endElement("script"); writer.getWrapped().endDocument();
Object resetValuesObject = context.getExternalContext().getRequestParameterMap().get(Constants.RequestParams.RESET_VALUES_PARAM); boolean resetValues = (null != resetValuesObject && "true".equals(resetValuesObject)); ResetInputContextCallback contextCallback = null; for (String renderId : context.getPartialViewContext().getRenderIds()) { if (LangUtils.isValueBlank(renderId) || renderId.trim().equals(SearchExpressionConstants.NONE_KEYWORD)) { continue; context.getViewRoot().visitTree(visitContext, ResetInputVisitCallback.INSTANCE); context.getViewRoot().invokeOnComponent(context, renderId, contextCallback);
@Override public boolean isPartialRequest() { return getWrapped().isPartialRequest() || FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().containsKey("javax.faces.partial.execute"); }
@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); }
@Override protected void doDecode(FacesContext context, UIComponent component) { super.doDecode(context, component); Map<String, String> params = context.getExternalContext().getRequestParameterMap(); if (params.get(component.getClientId(context)) != null) { PartialViewContext pvc = context.getPartialViewContext(); pvc.getRenderIds().add( component.getClientId(context) + MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR + AbstractProgressBar.STATE_META_COMPONENT_ID); } }
protected void handleAjaxException(FacesContext context, Throwable rootCause, ExceptionInfo info) throws Exception { ExternalContext externalContext = context.getExternalContext(); PartialResponseWriter writer = context.getPartialViewContext().getPartialResponseWriter(); if (context.getCurrentPhaseId().equals(PhaseId.RENDER_RESPONSE)) { if (!externalContext.isResponseCommitted()) { writer.flush(); writer.endCDATA(); writer.endInsert(); writer.endUpdate(); writer.endError(); writer.getWrapped().endElement("changes"); writer.getWrapped().endElement("partial-response"); String characterEncoding = externalContext.getResponseCharacterEncoding(); externalContext.responseReset(); externalContext.setResponseCharacterEncoding(characterEncoding); component.encodeAll(context); writer.endCDATA();
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 protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent component) throws IOException { AbstractPanelMenuItem menuItem = (AbstractPanelMenuItem) component; encodeHeaderGroupEnd(writer, context, menuItem, getCssClass(menuItem, "")); super.doEncodeEnd(writer, context, component); Map<String, String> requestMap = context.getExternalContext().getRequestParameterMap(); if (requestMap.get(component.getClientId(context)) != null) { if (context.getPartialViewContext().isPartialRequest()) { addOnCompleteParam(context, component.getClientId(context)); } } }
@Override public boolean isAjaxRequest() { return getWrapped().isAjaxRequest() || FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().containsKey("javax.faces.partial.ajax"); }
@Override public void encodeMetaComponent(FacesContext context, UIComponent component, String metaComponentId) throws IOException { if (AbstractTabPanel.HEADER_META_COMPONENT.equals(metaComponentId)) { AbstractTabPanel panel = (AbstractTabPanel) component; PartialResponseWriter w = context.getPartialViewContext().getPartialResponseWriter(); String id = component.getClientId() + AbstractTabPanel.HEADER_META_COMPONENT; w.startUpdate(id); writeTabsLine(w, context, panel); w.endUpdate(); } else { super.encodeMetaComponent(context, component, metaComponentId); } }
FacesContext context = FacesContext.getCurrentInstance(); PrimeApplicationContext applicationContext = PrimeApplicationContext.getCurrentInstance(context); try { UIViewRoot viewRoot = context.getViewRoot(); if (viewRoot != null) { String parameterNamespace = viewRoot.getContainerClientId(context); if ((parameterNamespace != null) && (parameterNamespace.length() > 0)) { if (context.isPostback() && !context.getPartialViewContext().isRenderAll() && !applicationContext.getEnvironment().isAtLeastJsf23()) { List<ResourceUtils.ResourceInfo> initialResources = DynamicResourcesPhaseListener.getInitialResources(context); ResourceUtils.ResourceInfo resourceInfo = newResources.get(i); if (!updateStarted) { ((PartialResponseWriter) getWrapped()).startUpdate("javax.faces.Resource"); updateStarted = true; resourceInfo.getResource().encodeAll(context); ((PartialResponseWriter) getWrapped()).endUpdate();
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); } } }
@Override public void handle() throws FacesException { FacesContext context = FacesContext.getCurrentInstance(); if (context == null || context.getResponseComplete()) { return; if (context.getApplication().getProjectStage() == ProjectStage.Development) { rootCause.printStackTrace(); if (context.getPartialViewContext().isAjaxRequest()) { handleAjaxException(context, rootCause, info);
@Override public Collection<String> getRenderIds() { List<String> ids = new ArrayList<String>(getWrapped().getRenderIds()); RequestContext requestContext = RequestContext.getCurrentInstance(); Collection<String> autoUpdateIds = (Collection<String>) FacesContext.getCurrentInstance().getViewRoot().getViewMap().get(Constants.AUTO_UPDATE); if(requestContext != null) { ids.addAll(requestContext.getPartialUpdateTargets()); } if(autoUpdateIds != null) { ids.addAll(autoUpdateIds); } return ids; }
public void end(ResponseWriter writer, FacesContext context, UIComponent component, Object[] params) throws IOException { writer.endElement(HtmlConstants.TH_ELEM); writer.endElement(HtmlConstants.TR_ELEMENT); writer.endElement(HtmlConstants.THEAD_ELEMENT); boolean partial = (Boolean) (Boolean) params[0]; if (partial) { context.getPartialViewContext().getPartialResponseWriter().endUpdate(); } } };
public void encode(ResponseWriter writer, FacesContext context) throws IOException { writer.startElement("span", this); writer.writeAttribute("id", "dynamic-code-compat", null); if (!context.getPartialViewContext().isPartialRequest()) { writer.startElement("script", this); writer.writeAttribute("type", "text/javascript", null); writer.write(JavascriptContext.getJavascriptCalls(context)); writer.endElement("script"); } writer.endElement("span"); } };
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; }
@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 processPartial(PhaseId phaseId) { if (phaseId == PhaseId.RENDER_RESPONSE) { FacesContext context = FacesContext.getCurrentInstance(); resetValues(context); } getWrapped().processPartial(phaseId); }
/** * 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); } } }