Uploaded image for project: 'PUBLIC - Liferay Faces'
  1. PUBLIC - Liferay Faces
  2. FACES-3064

Support ExternalContext.setResponseHeader(String name, String value)



      The ExternalContext.setResponseHeader(String name, String value) method was added as of JSF 2.0.

      The FacesBridge must follow the requirements in the JSF 2.2 JavaDoc. However, rather than calling HttpServletResponse.setHeader(String name, String value), the FacesBridge must call PortletResponse.setProperty(String name, String value). Additionally, since the JavaDoc for javax.portlet.ResourceResponse states:

      A portlet can set HTTP headers for the response via the setProperty or addProperty call in the ResourceResponse.

      Additionally, Section 15.1 of the Portlet 3.0 Specification states:

      Response properties can be viewed as header values set for the portal application. If these header values are intended to be transmitted to the client as response headers, they should be set during the header phase or before the response is committed during the resource phase.

      Finally, Section 15.8 of the Portlet 3.0 Specification states:

      The HeaderResponse interface extends the MimeResponse interface. The portlet can use this interface during the header phase, which the portlet container must execute before the overall portal response has been committed in order to allow the portlet to contribute header information.

      The portlet can use the addProperty and setProperty methods described previously to contribute cookies and HTTP header data. However, the portlet container may restrict the type of HTTP header data that the portlet can set in order enforce the portlet programming model and to avoid conflicts with other portlets. For example, the portlet will generally not be allowed to set headers relating to redirection or the overall response length.

      Because of these requirements, the FacesBridge will only be required to call PortletResponse.setProperty(String name, String value) during the HEADER_PHASE and RESOURCE_PHASE of the portlet lifecycle.

      TCK: setResponseHeaderTest

      • Portlet view XHTML contains the EL expression #{test.renderTestResult}. (Since the FacesBridge executes the JSF lifecycle in the HEADER_PHASE of the portlet lifecycle, the EL expression will be evaluated during the HEADER_PHASE.)
      • Java @BridgeTest calls ExternalContext.setHeader("foo", "a")
      • JavaScript examines the response headers and verifies that the "foo" header has the value "a"

      TCK: setResponseHeaderResourceTest

      • View contains an h:outputLink component tag with a value attribute that has an EL expression to a managed-bean method that returns a URL as a String. For example, see customers.xhtml and CustomerWrapper.java in the jsf-export-pdf-portlet demo.
      • Test contains a custom ResourceHandler that makes it possible to download a custom Resource. The custom resource getResponseHeaders() method should return a Map with a "Content-Disposition" key with one value "attachment; filename=myfile.txt". For example, see CustomerResourceHander.java and CustomerExportResource.java in the jsf-export-pdf-portlet demo.
      • Click on the h:outputLink in order to initiate a download from the custom ResourceHandler.
      • Examine the headers of the response and ensure that the "Content-Disposition" header is present with "attachment; filename=myfile.txt"" as the value.
      • The reason why this test is correct is because the JavaDoc for ResourceHandler.handleResourceRequest(FacesContext) states that the setHeader method is to be called (not addHeader) for each map entry found in Resource.getResponseHeaders().


          Issue Links



              ui_faces UI Faces
              neil.griffin Neil Griffin
              Participants of an Issue:
              0 Vote for this issue
              1 Start watching this issue




                  Version Package