use of com.sun.faces.util.MessageUtils.getExceptionMessageString in project mojarra by eclipse-ee4j.
the class ScopedAttributeELResolver method setValue.
@Override
public void setValue(ELContext context, Object base, Object property, Object val) throws ELException {
if (base != null) {
return;
}
if (property == null) {
// ?????
String message = MessageUtils.getExceptionMessageString(MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "base and property");
throw new PropertyNotFoundException(message);
}
context.setPropertyResolved(true);
String attribute = (String) property;
FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
ExternalContext externalContext = facesContext.getExternalContext();
if (externalContext.getRequestMap().get(attribute) != null) {
externalContext.getRequestMap().put(attribute, val);
} else if (facesContext.getViewRoot() != null && facesContext.getViewRoot().getViewMap().get(attribute) != null) {
facesContext.getViewRoot().getViewMap().put(attribute, val);
} else if (externalContext.getSessionMap().get(attribute) != null) {
externalContext.getSessionMap().put(attribute, val);
} else if (externalContext.getApplicationMap().get(attribute) != null) {
externalContext.getApplicationMap().put(attribute, val);
} else {
// if the property doesn't exist in any of the scopes, put it in
// request scope.
externalContext.getRequestMap().put(attribute, val);
}
}
use of com.sun.faces.util.MessageUtils.getExceptionMessageString in project mojarra by eclipse-ee4j.
the class Util method checkIdUniqueness.
/**
* Utility method to validate ID uniqueness for the tree represented by <code>component</code>.
*/
public static void checkIdUniqueness(FacesContext context, UIComponent component, Set<String> componentIds) {
boolean uniquenessCheckDisabled = false;
if (context.isProjectStage(ProjectStage.Production)) {
WebConfiguration config = WebConfiguration.getInstance(context.getExternalContext());
uniquenessCheckDisabled = config.isOptionEnabled(WebConfiguration.BooleanWebContextInitParameter.DisableIdUniquenessCheck);
}
if (!uniquenessCheckDisabled) {
// deal with children/facets that are marked transient.
for (Iterator<UIComponent> kids = component.getFacetsAndChildren(); kids.hasNext(); ) {
UIComponent kid = kids.next();
// check for id uniqueness
String id = kid.getClientId(context);
if (componentIds.add(id)) {
checkIdUniqueness(context, kid, componentIds);
} else {
if (LOGGER.isLoggable(Level.SEVERE)) {
LOGGER.log(Level.SEVERE, "faces.duplicate_component_id_error", id);
FastStringWriter writer = new FastStringWriter(128);
DebugUtil.simplePrintTree(context.getViewRoot(), id, writer);
LOGGER.severe(writer.toString());
}
String message = MessageUtils.getExceptionMessageString(MessageUtils.DUPLICATE_COMPONENT_ID_ERROR_ID, id);
throw new IllegalStateException(message);
}
}
}
}
use of com.sun.faces.util.MessageUtils.getExceptionMessageString in project mojarra by eclipse-ee4j.
the class RestoreViewPhase method execute.
/**
* PRECONDITION: the necessary factories have been installed in the ServletContext attr set.
* <P>
*
* POSTCONDITION: The facesContext has been initialized with a tree.
*/
@Override
public void execute(FacesContext facesContext) throws FacesException {
LOGGER.fine("Entering RestoreViewPhase");
if (facesContext == null) {
throw new FacesException(getExceptionMessageString(NULL_CONTEXT_ERROR_MESSAGE_ID));
}
// If an app had explicitely set the tree in the context, use that;
UIViewRoot viewRoot = facesContext.getViewRoot();
if (viewRoot != null) {
LOGGER.fine("Found a pre created view in FacesContext");
facesContext.getViewRoot().setLocale(facesContext.getExternalContext().getRequestLocale());
// Do per-component actions
deliverPostRestoreStateEvent(facesContext);
if (!facesContext.isPostback()) {
facesContext.renderResponse();
}
return;
}
FacesException thrownException = null;
try {
// Reconstitute or create the request tree
Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
String viewId = (String) requestMap.get("jakarta.servlet.include.path_info");
if (viewId == null) {
viewId = facesContext.getExternalContext().getRequestPathInfo();
}
// path_info. Query the servlet path.
if (viewId == null) {
viewId = (String) requestMap.get("jakarta.servlet.include.servlet_path");
}
if (viewId == null) {
viewId = facesContext.getExternalContext().getRequestServletPath();
}
if (viewId == null) {
throw new FacesException(MessageUtils.getExceptionMessageString(NULL_REQUEST_VIEW_ERROR_MESSAGE_ID));
}
ViewHandler viewHandler = getViewHandler(facesContext);
if (facesContext.isPostback() && !isErrorPage(facesContext)) {
facesContext.setProcessingEvents(false);
// try to restore the view
viewRoot = viewHandler.restoreView(facesContext, viewId);
if (viewRoot == null) {
Object[] params = { viewId };
throw new ViewExpiredException(getExceptionMessageString(RESTORE_VIEW_ERROR_MESSAGE_ID, params), viewId);
}
facesContext.setViewRoot(viewRoot);
facesContext.setProcessingEvents(true);
if (LOGGER.isLoggable(FINE)) {
LOGGER.fine("Postback: restored view for " + viewId);
}
} else {
if (LOGGER.isLoggable(FINE)) {
LOGGER.fine("New request: creating a view for " + viewId);
}
String logicalViewId = viewHandler.deriveLogicalViewId(facesContext, viewId);
ViewDeclarationLanguage vdl = viewHandler.getViewDeclarationLanguage(facesContext, logicalViewId);
maybeTakeProtectedViewAction(facesContext, viewHandler, vdl, logicalViewId);
ViewMetadata metadata = null;
if (vdl != null) {
// If we have one, get the ViewMetadata...
metadata = vdl.getViewMetadata(facesContext, logicalViewId);
if (metadata != null) {
// perhaps it's not supported
// and use it to create the ViewRoot. This will have, at most
// the UIViewRoot and its metadata facet.
viewRoot = metadata.createMetadataView(facesContext);
// Only skip to render response if there is no metadata
if (!hasMetadata(viewRoot)) {
facesContext.renderResponse();
}
}
}
if (vdl == null || metadata == null) {
facesContext.renderResponse();
}
if (viewRoot == null) {
viewRoot = getViewHandler(facesContext).createView(facesContext, logicalViewId);
}
facesContext.setViewRoot(viewRoot);
}
} catch (Throwable fe) {
if (fe instanceof FacesException) {
thrownException = (FacesException) fe;
} else {
thrownException = new FacesException(fe);
}
} finally {
if (thrownException == null) {
FlowHandler flowHandler = facesContext.getApplication().getFlowHandler();
if (flowHandler != null) {
flowHandler.clientWindowTransition(facesContext);
}
deliverPostRestoreStateEvent(facesContext);
} else {
throw thrownException;
}
}
LOGGER.fine("Exiting RestoreViewPhase");
}
use of com.sun.faces.util.MessageUtils.getExceptionMessageString in project mojarra by eclipse-ee4j.
the class ExternalContextImpl method encodePartialActionURL.
/**
* @see jakarta.faces.context.ExternalContext#encodePartialActionURL(String)
*/
@Override
public String encodePartialActionURL(String url) {
if (null == url) {
String message = MessageUtils.getExceptionMessageString(MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "url");
throw new NullPointerException(message);
}
FacesContext context = FacesContext.getCurrentInstance();
String encodingFromContext = (String) context.getAttributes().get(RIConstants.FACELETS_ENCODING_KEY);
if (null == encodingFromContext) {
encodingFromContext = (String) context.getViewRoot().getAttributes().get(RIConstants.FACELETS_ENCODING_KEY);
}
String currentResponseEncoding = null != encodingFromContext ? encodingFromContext : getResponseCharacterEncoding();
UrlBuilder builder = new UrlBuilder(url, currentResponseEncoding);
return ((HttpServletResponse) response).encodeURL(builder.createUrl());
}
Aggregations