Java Code Examples for javax.faces.event.PhaseEvent#getFacesContext()

The following examples show how to use javax.faces.event.PhaseEvent#getFacesContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CachePhaseListener.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void beforePhase(PhaseEvent phaseEvent) {
    FacesContext facesContext = phaseEvent.getFacesContext();
    HttpServletResponse response =
            (HttpServletResponse) facesContext.getExternalContext().getResponse();

    response.addHeader("Pragma", "no-cache");
    response.addHeader("Cache-Control", "no-cache");
    response.addHeader("Cache-Control", "no-store");
    response.addHeader("Cache-Control", "must-revalidate");
    response.addHeader("Expires", "Wed, 1 Jan 2008 05:00:00 GMT");     //in the past
    response.setContentType("text/html; charset=UTF-8");       
}
 
Example 2
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase has just
 * been completed.
 */
public void afterPhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES ||
			event.getPhaseId() == PhaseId.PROCESS_VALIDATIONS ||
			event.getPhaseId() == PhaseId.UPDATE_MODEL_VALUES || 
			event.getPhaseId() == PhaseId.INVOKE_APPLICATION) {

		FacesContext facesContext = event.getFacesContext();
		saveMessages(facesContext);
	}

}
 
Example 3
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase of the
 * request processing lifecycle is about to begin.
 */
public void beforePhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
		FacesContext facesContext = event.getFacesContext();
		restoreMessages(facesContext);
	}
}
 
Example 4
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase has just
 * been completed.
 */
public void afterPhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES ||
			event.getPhaseId() == PhaseId.PROCESS_VALIDATIONS ||
			event.getPhaseId() == PhaseId.UPDATE_MODEL_VALUES || 
			event.getPhaseId() == PhaseId.INVOKE_APPLICATION) {

		FacesContext facesContext = event.getFacesContext();
		saveMessages(facesContext);
	}

}
 
Example 5
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase of the
 * request processing lifecycle is about to begin.
 */
public void beforePhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
		FacesContext facesContext = event.getFacesContext();
		restoreMessages(facesContext);
	}
}
 
Example 6
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase has just
 * been completed.
 */
public void afterPhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES ||
			event.getPhaseId() == PhaseId.PROCESS_VALIDATIONS ||
			event.getPhaseId() == PhaseId.UPDATE_MODEL_VALUES || 
			event.getPhaseId() == PhaseId.INVOKE_APPLICATION) {

		FacesContext facesContext = event.getFacesContext();
		saveMessages(facesContext);
	}

}
 
Example 7
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase of the
 * request processing lifecycle is about to begin.
 */
public void beforePhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
		FacesContext facesContext = event.getFacesContext();
		restoreMessages(facesContext);
	}
}
 
Example 8
Source File: NoCachePhaseListener.java    From development with Apache License 2.0 5 votes vote down vote up
@Override
public void beforePhase(PhaseEvent phaseEvent) {
    FacesContext facesContext = phaseEvent.getFacesContext();
    HttpServletResponse response = (HttpServletResponse) facesContext
            .getExternalContext().getResponse();
    response.addHeader("Pragma", "no-cache");
    response.addHeader("Cache-Control", "no-cache,no-store,must-revalidate");
    response.addHeader("Expires", "0");

}
 
Example 9
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase of the
 * request processing lifecycle is about to begin.
 */
public void beforePhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
		FacesContext facesContext = event.getFacesContext();
		restoreMessages(facesContext);
	}
}
 
Example 10
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase has just
 * been completed.
 */
public void afterPhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES ||
			event.getPhaseId() == PhaseId.PROCESS_VALIDATIONS ||
			event.getPhaseId() == PhaseId.UPDATE_MODEL_VALUES || 
			event.getPhaseId() == PhaseId.INVOKE_APPLICATION) {

		FacesContext facesContext = event.getFacesContext();
		saveMessages(facesContext);
	}

}
 
Example 11
Source File: MessageHandler.java    From development with Apache License 2.0 5 votes vote down vote up
/**
 * in RENDER_RESPONSE restore facesMessages
 */
public void beforePhase(PhaseEvent event) {
    if (event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
        FacesContext facesContext = event.getFacesContext();
        restoreMessages(facesContext);
    }
}
 
Example 12
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase has just
 * been completed.
 */
public void afterPhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES ||
			event.getPhaseId() == PhaseId.PROCESS_VALIDATIONS ||
			event.getPhaseId() == PhaseId.UPDATE_MODEL_VALUES || 
			event.getPhaseId() == PhaseId.INVOKE_APPLICATION) {

		FacesContext facesContext = event.getFacesContext();
		saveMessages(facesContext);
	}

}
 
Example 13
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase of the
 * request processing lifecycle is about to begin.
 */
public void beforePhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
		FacesContext facesContext = event.getFacesContext();
		restoreMessages(facesContext);
	}
}
 
Example 14
Source File: NoCachePhaseListener.java    From development with Apache License 2.0 5 votes vote down vote up
@Override
public void beforePhase(PhaseEvent phaseEvent) {
    FacesContext facesContext = phaseEvent.getFacesContext();
    HttpServletResponse response = (HttpServletResponse) facesContext
            .getExternalContext().getResponse();
    response.addHeader("Pragma", "no-cache");
    response.addHeader("Cache-Control", "no-cache,no-store,must-revalidate");
    response.addHeader("Expires", "0");

}
 
Example 15
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase of the
 * request processing lifecycle is about to begin.
 */
public void beforePhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
		FacesContext facesContext = event.getFacesContext();
		restoreMessages(facesContext);
	}
}
 
Example 16
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase has just
 * been completed.
 */
public void afterPhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES ||
			event.getPhaseId() == PhaseId.PROCESS_VALIDATIONS ||
			event.getPhaseId() == PhaseId.UPDATE_MODEL_VALUES || 
			event.getPhaseId() == PhaseId.INVOKE_APPLICATION) {

		FacesContext facesContext = event.getFacesContext();
		saveMessages(facesContext);
	}

}
 
Example 17
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase of the
 * request processing lifecycle is about to begin.
 */
public void beforePhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
		FacesContext facesContext = event.getFacesContext();
		restoreMessages(facesContext);
	}
}
 
Example 18
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase has just
 * been completed.
 */
public void afterPhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES ||
			event.getPhaseId() == PhaseId.PROCESS_VALIDATIONS ||
			event.getPhaseId() == PhaseId.UPDATE_MODEL_VALUES || 
			event.getPhaseId() == PhaseId.INVOKE_APPLICATION) {

		FacesContext facesContext = event.getFacesContext();
		saveMessages(facesContext);
	}

}
 
Example 19
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase has just
 * been completed.
 */
public void afterPhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES ||
			event.getPhaseId() == PhaseId.PROCESS_VALIDATIONS ||
			event.getPhaseId() == PhaseId.UPDATE_MODEL_VALUES || 
			event.getPhaseId() == PhaseId.INVOKE_APPLICATION) {

		FacesContext facesContext = event.getFacesContext();
		saveMessages(facesContext);
	}

}
 
Example 20
Source File: MessageListener.java    From development with Apache License 2.0 4 votes vote down vote up
public void beforePhase(PhaseEvent event) {
    FacesContext fc = event.getFacesContext();
    ServletRequest request = (ServletRequest) fc.getExternalContext()
            .getRequest();
    UIViewRoot root = fc.getViewRoot();
    resetColor(root.getChildren());
    List<String> additionalErrorElements = new ArrayList<String>();
    Set<String> sectionsToExpand = new HashSet<String>();
    Iterator<String> clientIds = fc.getClientIdsWithMessages();
    while (clientIds.hasNext()) {
        String clientId = clientIds.next();
        if (canIgnoreClientId(clientId)) {
            // skip, since it is not associated with a specific field
            continue;
        }
        if (request.getAttribute(ATTRIBUTE_FIRST_ERROR_ELEMENT) == null) {
            // set focus to first component only
            request.setAttribute(ATTRIBUTE_FIRST_ERROR_ELEMENT, clientId);
        }
        UIComponent uiComponent = root.findComponent(clientId);
        String sectionId = null;
        if (uiComponent != null) {
            sectionId = getSectionId(uiComponent);
            uiComponent.getAttributes().put(ATTRIBUTE_STYLE, STYLE_ERROR);
            Object object = uiComponent.getAttributes().get("connectedTo");
            if (object != null) {
                UIComponent connected = root.findComponent(object
                        .toString());
                if (connected != null) {
                    connected.getAttributes().put(ATTRIBUTE_STYLE,
                            STYLE_ERROR);
                }
            }
            if (uiComponent instanceof UISelectBoolean) {
                uiComponent.getAttributes().put(ATTRIBUTE_STYLE,
                        STYLE_CHECKBOX_ERROR);
            } else if (uiComponent instanceof UICalendar) {
                additionalErrorElements.add(clientId + "InputDate");
            } else {
                uiComponent.getAttributes().put(ATTRIBUTE_STYLE,
                        STYLE_ERROR);
            }
        } else {
            sectionId = getTableSectionId(clientId, root);
            // if the element is part of a data table we must change the
            // style from javascript
            additionalErrorElements.add(clientId);
        }
        if (sectionId != null) {
            sectionsToExpand.add(sectionId);
        }
    }
    request.setAttribute(ATTRIBUTE_ADDITIONAL_ERROR_ELEMENTS,
            additionalErrorElements);
    if (!sectionsToExpand.isEmpty()) {
        request.setAttribute(OpenStateBean.SECTIONS_TO_EXPAND,
                sectionsToExpand);
    }
    if (request.getAttribute(ATTRIBUTE_FIRST_ERROR_ELEMENT) != null) {
        JSFUtils.addMessage(null, FacesMessage.SEVERITY_ERROR,
                BaseBean.ERROR_TEXT_FIELDS, null);
    }

    if (request.getAttribute(FILEUPLOAD_EXCEPTION) != null) {
        // The upload of one or a bunch of files failed because either one
        // of the files exceeds the value of "uploadMaxFileSize" or the size
        // of all files exceeds the value of "uploadMaxSize". If
        // "uploadMaxSize" if not set => uploadMaxSize = uploadMaxFileSize

        Integer maxSize = (Integer) request
                .getAttribute(FILEUPLOAD_MAX_SIZE);

        if (maxSize == null) {
            // The attribute indicating the maximum allowed size was not set
            JSFUtils.addMessage(null, FacesMessage.SEVERITY_ERROR,
                    BaseBean.ERROR_UPLOAD_SIZE_LIMIT_EXCEEDED, null);
        } else {
            // Calculate a more handy megabyte value and bring it to a nice
            // format
            Locale viewLocale = JSFUtils.getViewLocale();
            DecimalFormat df = (DecimalFormat) DecimalFormat
                    .getInstance(viewLocale);
            df.applyPattern("#0.00");

            double maxValueMb = maxSize.intValue() / (1024.0 * 1024.0);

            JSFUtils.addMessage(null, FacesMessage.SEVERITY_ERROR,
                    BaseBean.ERROR_UPLOAD_SIZE_LIMIT_EXCEEDED_KNOWNMAX,
                    new Object[] { df.format(maxValueMb) });
        }
    }
}