use of javax.portlet.faces.component.PortletNamingContainerUIViewRoot in project liferay-faces-bridge-impl by liferay.
the class BodyRendererBridgeImpl method encodeBegin.
/**
* It is forbidden for a portlet to render the &<body&> element, so instead, render a
* &<div&>element.
*
* @see Renderer#encodeBegin(FacesContext, UIComponent)
*/
@Override
@SuppressWarnings("unchecked")
public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
ResponseWriter originalResponseWriter = facesContext.getResponseWriter();
ResponseWriter responseWriter = new ResponseWriterBridgeBodyImpl(originalResponseWriter);
facesContext.setResponseWriter(responseWriter);
super.encodeBegin(facesContext, uiComponent);
PortletNamingContainerUIViewRoot viewRoot = (PortletNamingContainerUIViewRoot) facesContext.getViewRoot();
String clientId = viewRoot.getContainerClientId(facesContext);
responseWriter.writeAttribute("id", clientId, null);
String styleClass = (String) uiComponent.getAttributes().get("styleClass");
// ResponseWriterBridgeBodyImpl will append STYLE_CLASS_PORTLET_BODY to the specified styleClass.
if (styleClass == null) {
responseWriter.writeAttribute("class", RenderKitUtil.STYLE_CLASS_PORTLET_BODY, "styleClass");
}
// Render each of the head resources that were not renderable in the head section into the top of the portlet
// body (the outer <div> of the portlet markup). This happens when the portlet container may not support adding
// resources to the <head> section. For example, Pluto does not support the feature of adding resources to the
// <head> section. Liferay supports it with the exception of "runtime" and WSRP portlets. See
// PortalContextBridgeImpl and PortalContextBridgeLiferayImpl (in bridge-ext) for more information. Script
// resources are rendered at the top of the portlet body instead of the bottom because elements and scripts in
// the portlet body may depend on these resources (for example jquery.js), so head resource scripts must be
// loaded before the portlet body is rendered.
Map<Object, Object> facesContextAttributes = facesContext.getAttributes();
List<UIComponent> headResourcesToRenderInBody = (List<UIComponent>) facesContextAttributes.get(RenderKitUtil.HEAD_RESOURCES_TO_RENDER_IN_BODY);
Set<String> headResourceIds = RenderKitUtil.getHeadResourceIds(facesContext);
// https://html.spec.whatwg.org/multipage/semantics.html#the-link-element
if (headResourcesToRenderInBody != null) {
ExternalContext externalContext = facesContext.getExternalContext();
final Product BOOTSFACES = ProductFactory.getProductInstance(externalContext, Product.Name.BOOTSFACES);
final boolean BOOTSFACES_DETECTED = BOOTSFACES.isDetected();
for (UIComponent headResource : headResourcesToRenderInBody) {
headResource.encodeAll(facesContext);
// tracked as if they were rendered in the <head> section so that they are not loaded multiple times.
if (RenderKitUtil.isScriptResource(headResource, BOOTSFACES_DETECTED)) {
headResourceIds.add(ResourceUtil.getResourceId(headResource));
}
}
}
facesContext.setResponseWriter(originalResponseWriter);
}
use of javax.portlet.faces.component.PortletNamingContainerUIViewRoot in project liferay-faces-bridge-impl by liferay.
the class Tests method portletNamingContainerUIViewRootClientIdTest.
// Test is SingleRequest -- Render
// Test #6.96
@BridgeTest(test = "portletNamingContainerUIViewRootClientIdTest")
public String portletNamingContainerUIViewRootClientIdTest(TestBean testBean) {
FacesContext facesContext = FacesContext.getCurrentInstance();
String namespace = ((MimeResponse) facesContext.getExternalContext().getResponse()).getNamespace();
testBean.setTestComplete(true);
try {
PortletNamingContainerUIViewRoot vr = new PortletNamingContainerUIViewRoot();
// ensure it has an id
vr.setId("nc");
if (vr.getContainerClientId(facesContext).indexOf(namespace) >= 0) {
testBean.setTestResult(true, "class PortletNamingContainerUIViewRoot correctly encodes portlet namespace id in the result from getContainerClientId");
return Constants.TEST_SUCCESS;
} else {
testBean.setTestResult(false, "class PortletNamingContainerUIViewRoot doesn't encodes portlet namespace id in the result from getContainerClientId. namespaceId: " + namespace + " getContainerClientId returned: " + vr.getContainerClientId(facesContext));
return Constants.TEST_FAILED;
}
} catch (Exception e) {
testBean.setTestResult(false, "class PortletNamingContainerUIViewRoot doesn't exist or can't be instantiated. Received exception: " + e.getMessage());
return Constants.TEST_FAILED;
}
}
Aggregations