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

Support ExternalContext.addResponseHeader(String name, String value)



      The ExternalContext.addResponseHeader(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.addHeader(String name, String value), the FacesBridge must call PortletResponse.addProperty(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.addProperty(String name, String value) during the HEADER_PHASE and RESOURCE_PHASE of the portlet lifecycle.

      TCK: addResponseHeaderTest

      • 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.addHeader("foo", "a") and ExternalContext.addHeader("foo", "b")
      • JavaScript examines the response headers and verifies that the "foo" header has the value "a,b"

      TCK: addResponseHeaderResourceTest

      • View has a command button that performs an "Ajax Redirect". For example:
        <h:commandButton action="doRedirect" value="Invoke and redirect">
        	<f:ajax execute="@this"/>
      • Click on the command button and examine the headers of the response and ensure that the "Cache-Control" header is present with "nocache" as the value.
      • The reason why this test is correct is because the JavaDoc for ExternalContext.redirect(String) requires that the ExternalContext.addResponseHeader(String,String) method be called with "Cache-Control", "no-cache".


          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