Locale locale = view.getLocale();
response.setLocale(locale);
Config.set(request, Config.FMT_LOCALE, context.getViewRoot().getLocale());
String viewId = view.getViewId();
ServletViewResponseWrapper wrappedResponse = new ServletViewResponseWrapper((HttpServletResponse) response);
externalContext.setResponse(wrappedResponse);
try
{
externalContext.dispatch(viewId);
}
catch (FacesException e)
{
// try to extract the most likely exceptions here
// and provide a better error message for them
String message = e.getMessage();
// errors related to using facelets-only tags on a JSP page
if (message != null)
{
// does the message contain "f" (prefix f of tags)
// or the related uri http://java.sun.com/jsf/core
if (message.contains("\"f\"")
|| message.contains("\"" + CoreLibrary.NAMESPACE + "\""))
{
// check facelets-only f tags
for (String tag : FACELETS_ONLY_F_TAGS)
{
if (message.contains("\"" + tag + "\""))
{
String exceptionMessage = "The tag f:" + tag +
" is only available on facelets.";
throw new FacesException(exceptionMessage,
new FaceletsOnlyException(exceptionMessage, e.getCause()));
}
}
}
else if (message.contains("\"h\"")
|| message.contains("\"" + HtmlLibrary.NAMESPACE + "\""))
{
// check facelets-only h tags
for (String tag : FACELETS_ONLY_H_TAGS)
{
if (message.contains("\"" + tag + "\""))
{
String exceptionMessage = "The tag h:" + tag +
" is only available on facelets.";
throw new FacesException(exceptionMessage,
new FaceletsOnlyException(exceptionMessage, e.getCause()));
}
}
}
else
{
// check facelets-only namespaces
String namespace = null;
if (message.contains(UILibrary.NAMESPACE))
{
namespace = UILibrary.NAMESPACE;
}
else if (message.contains(CompositeLibrary.NAMESPACE))
{
namespace = CompositeLibrary.NAMESPACE;
}
if (namespace != null)
{
// the message contains a facelets-only namespace
String exceptionMessage = "All tags with namespace " +
namespace + " are only available on facelets.";
throw new FacesException(exceptionMessage,
new FaceletsOnlyException(exceptionMessage, e.getCause()));
}
}
}
// no rule applied to this Exception - rethrow it
throw e;
}
finally
{
externalContext.setResponse(response);
}
boolean errorResponse = wrappedResponse.getStatus() < 200 || wrappedResponse.getStatus() > 299;
if (errorResponse)
{
wrappedResponse.flushToWrappedResponse();
return;
}
// Skip this step if we are rendering an ajax request, because no content outside
// f:view tag should be output.