Search in sources :

Example 6 with ClientWindow

use of javax.faces.lifecycle.ClientWindow in project primefaces by primefaces.

the class PrimeClientWindowLifecycle method attachWindow.

@Override
public void attachWindow(FacesContext facesContext) {
    ClientWindow clientWindow = facesContext.getExternalContext().getClientWindow();
    if (clientWindow == null) {
        clientWindow = new PrimeClientWindow();
    }
    try {
        clientWindow.decode(facesContext);
        facesContext.getExternalContext().setClientWindow(clientWindow);
    } catch (RuntimeException e) {
        facesContext.getExternalContext().setClientWindow(null);
        throw e;
    }
}
Also used : ClientWindow(javax.faces.lifecycle.ClientWindow)

Example 7 with ClientWindow

use of javax.faces.lifecycle.ClientWindow in project primefaces by primefaces.

the class HeadRenderer method encodeSettingScripts.

protected void encodeSettingScripts(FacesContext context, PrimeApplicationContext applicationContext, PrimeRequestContext requestContext, ResponseWriter writer, boolean csvEnabled) throws IOException {
    ProjectStage projectStage = context.getApplication().getProjectStage();
    writer.startElement("script", null);
    writer.writeAttribute("type", "text/javascript", null);
    writer.write("if(window.PrimeFaces){");
    writer.write("PrimeFaces.settings.locale='" + LocaleUtils.getCurrentLocale(context) + "';");
    writer.write("PrimeFaces.settings.viewId='" + context.getViewRoot().getViewId() + "';");
    writer.write("PrimeFaces.settings.contextPath='" + context.getExternalContext().getRequestContextPath() + "';");
    writer.write("PrimeFaces.settings.cookiesSecure=" + (requestContext.isSecure() && applicationContext.getConfig().isCookiesSecure()) + ";");
    if (applicationContext.getConfig().getCookiesSameSite() != null) {
        writer.write("PrimeFaces.settings.cookiesSameSite='" + applicationContext.getConfig().getCookiesSameSite() + "';");
    }
    if (csvEnabled) {
        writer.write("PrimeFaces.settings.validateEmptyFields=" + applicationContext.getConfig().isValidateEmptyFields() + ";");
        writer.write("PrimeFaces.settings.considerEmptyStringNull=" + applicationContext.getConfig().isInterpretEmptyStringAsNull() + ";");
    }
    if (applicationContext.getConfig().isLegacyWidgetNamespace()) {
        writer.write("PrimeFaces.settings.legacyWidgetNamespace=true;");
    }
    if (applicationContext.getConfig().isEarlyPostParamEvaluation()) {
        writer.write("PrimeFaces.settings.earlyPostParamEvaluation=true;");
    }
    if (applicationContext.getConfig().isPartialSubmitEnabled()) {
        writer.write("PrimeFaces.settings.partialSubmit=true;");
    }
    if (projectStage != ProjectStage.Production) {
        writer.write("PrimeFaces.settings.projectStage='" + projectStage.toString() + "';");
    }
    if (applicationContext.getEnvironment().isAtLeastJsf22()) {
        if (context.getExternalContext().getClientWindow() != null) {
            ClientWindow clientWindow = context.getExternalContext().getClientWindow();
            if (clientWindow instanceof PrimeClientWindow) {
                boolean initialRedirect = false;
                Object cookie = PrimeClientWindowUtils.getInitialRedirectCookie(context, clientWindow.getId());
                if (cookie instanceof Cookie) {
                    Cookie servletCookie = (Cookie) cookie;
                    initialRedirect = true;
                    // expire/remove cookie
                    servletCookie.setMaxAge(0);
                    ((HttpServletResponse) context.getExternalContext().getResponse()).addCookie(servletCookie);
                }
                writer.write(String.format("PrimeFaces.clientwindow.init('%s', %s);", PrimeClientWindowUtils.secureWindowId(clientWindow.getId()), initialRedirect));
            }
        }
    }
    writer.write("}");
    writer.endElement("script");
}
Also used : Cookie(javax.servlet.http.Cookie) ClientWindow(javax.faces.lifecycle.ClientWindow) PrimeClientWindow(org.primefaces.clientwindow.PrimeClientWindow) ProjectStage(javax.faces.application.ProjectStage) HttpServletResponse(javax.servlet.http.HttpServletResponse) PrimeClientWindow(org.primefaces.clientwindow.PrimeClientWindow)

Aggregations

ClientWindow (javax.faces.lifecycle.ClientWindow)7 BridgeTest (com.liferay.faces.bridge.tck.annotation.BridgeTest)1 FacesException (javax.faces.FacesException)1 FacesMessage (javax.faces.application.FacesMessage)1 NavigationCase (javax.faces.application.NavigationCase)1 ProjectStage (javax.faces.application.ProjectStage)1 ExternalContext (javax.faces.context.ExternalContext)1 FacesContext (javax.faces.context.FacesContext)1 Cookie (javax.servlet.http.Cookie)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 PrimeClientWindow (org.primefaces.clientwindow.PrimeClientWindow)1