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;
}
}
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");
}
Aggregations