All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jakarta.faces.context.PartialResponseWriter Maven / Gradle / Ivy

/*
 * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0, which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * This Source Code may also be made available under the following Secondary
 * Licenses when the conditions for such availability set forth in the
 * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
 * version 2 with the GNU Classpath Exception, which is available at
 * https://www.gnu.org/software/classpath/license.html.
 *
 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
 */

package jakarta.faces.context;

import java.io.IOException;
import java.util.Map;

import jakarta.faces.component.NamingContainer;
import jakarta.faces.component.UIViewRoot;
import jakarta.faces.render.ResponseStateManager;

/**
 * 

* PartialResponseWriter decorates an existing ResponseWriter to support the generation of * a partial response suitable for Ajax operations. In addition to the markup generation methods inherited from * jakarta.faces.context.ResponseWriter, this class provides methods for constructing the standard partial * response elements. *

* * @since 2.0 */ public class PartialResponseWriter extends ResponseWriterWrapper { // True when we need to close a changes tag // private boolean inChanges = false; // True when we need to close a before insert tag // private boolean inInsertBefore = false; // True when we need to close afer insert tag // private boolean inInsertAfter = false; // True when we need to close an update tag // private boolean inUpdate = false; /** *

* Reserved ID value to indicate entire ViewRoot. *

* * @since 2.0 */ public static final String RENDER_ALL_MARKER = "jakarta.faces.ViewRoot"; /** *

* Reserved ID value to indicate serialized ViewState. *

* * @since 2.0 */ public static final String VIEW_STATE_MARKER = ResponseStateManager.VIEW_STATE_PARAM; /** *

* Create a PartialResponseWriter. *

* * @param writer The writer to wrap. * @since 2.0 */ public PartialResponseWriter(ResponseWriter writer) { super(writer); } /** *

* Write the start of a partial response. *

*

* If {@link UIViewRoot} is an instance of {@link NamingContainer}, then write * {@link UIViewRoot#getContainerClientId(FacesContext)} as value of the id attribute of the root element. *

* * @throws IOException if an input/output error occurs * @since 2.0 */ @Override public void startDocument() throws IOException { ResponseWriter writer = getWrapped(); String encoding = writer.getCharacterEncoding(); if (encoding == null) { encoding = "utf-8"; } writer.writePreamble("\n"); writer.startElement("partial-response", null); FacesContext ctx = FacesContext.getCurrentInstance(); if (null != ctx && ctx.getViewRoot() instanceof NamingContainer) { String id = ctx.getViewRoot().getContainerClientId(ctx); writer.writeAttribute("id", id, "id"); } } /** *

* Write the end of a partial response. *

* * @throws IOException if an input/output error occurs * @since 2.0 */ @Override public void endDocument() throws IOException { endChangesIfNecessary(); ResponseWriter writer = getWrapped(); /* * Because during a