jsr344-experts@javaserverfaces-spec-public.java.net

[jsr344-experts] [762-MetaDataLifecycle] Review: fix for Dan Allen's 1 year, 3 months, 2 day old issue

From: Ed Burns <edward.burns_at_oracle.com>
Date: Wed, 8 Jun 2011 18:21:03 -0700

Tweak circumstances for skipping intervening lifecycle phases in the case of view metadata http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-762

SECTION: Modified Files
----------------------------
M common/ant/common.xml

- Unrelated but useful change to prepend the context path to simple
  tester TEST*.xml file name.

M spec/frame/requestProcessingLifecycle.fm

- Section 2.2.1. Now has this text.

  Otherwise, call getViewMetadata() on the ViewDeclarationLanguage
  instance. If the result is non-null, call createMetadataView() on the
  ViewMetadata instance. Call ViewMetadata.getViewParameters(). If the
  result is a non-empty Collection, do not call
  facesContext.renderResponse(). If the result is an empty collection,
  try to obtain the metadata facet of the UIViewRoot by asking the
  UIViewRoot for the facet named UIViewRoot.METADATA_FACET_NAME. This
  facet must exist. If the facet has no children, call
  facesContext.renderResponse(). Otherwise, none of the previous steps
  have yielded the discovery any of metadata, so call
  facesContext.renderResponse().
  
M jsf-ri/src/main/java/com/sun/faces/lifecycle/RestoreViewPhase.java

- The heart of the change. See the comments for requestProcessingLifecycle.fm

M jsf-test/build.xml

- Wire up the regression test.

A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762
A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war
A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/faces-config.NavData
A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src
A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main
A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/java
A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/java/com
A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/java/com/sun
A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/java/com/sun/faces
A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/java/com/sun/faces/regression
A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/java/com/sun/faces/regression/i_spec_762
A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/java/com/sun/faces/regression/i_spec_762/UserBean.java
A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/java/com/sun/faces/regression/i_spec_762/Issue762PhaseListener.java
A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/webapp
A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/webapp/main.xhtml
A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/webapp/WEB-INF
A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/webapp/WEB-INF/faces-config.xml
A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/webapp/WEB-INF/web.xml
A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/pom.xml
A jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/build.xml

- Regression test for the feature.

SECTION: Diffs
----------------------------
Index: common/ant/common.xml
===================================================================
--- common/ant/common.xml (revision 9138)
+++ common/ant/common.xml (working copy)
@@ -499,11 +499,18 @@
         <element name="custom-sysproperties" optional="true"/>
         <sequential>
             <var name="testname" unset="true" />
- <propertyregex property="testname"
+ <propertyregex property="testname-suffix"
                            input="@{request}"
                            global="true"
                            regexp="/"
                            replace="_" />
+ <propertyregex property="testname-prefix"
+ input="@{context-path}"
+ global="true"
+ regexp="/"
+ replace="_" />
+
+ <var name="testname" value="${testname-prefix}_${testname-suffix}" />
             <echo message="writing TEST-${testname}" />
             <junit printsummary="yes"
                    fork="yes"
Index: jsf-ri/src/main/java/com/sun/faces/lifecycle/RestoreViewPhase.java
===================================================================
--- jsf-ri/src/main/java/com/sun/faces/lifecycle/RestoreViewPhase.java (revision 9138)
+++ jsf-ri/src/main/java/com/sun/faces/lifecycle/RestoreViewPhase.java (working copy)
@@ -236,7 +236,11 @@
                         Collection<UIViewParameter> params =
                                 ViewMetadata.getViewParameters(viewRoot);
                         if (params.isEmpty()) {
- facesContext.renderResponse();
+ UIComponent metaDataFacet = viewRoot.getFacets().get(UIViewRoot.METADATA_FACET_NAME);
+ assert(null != metaDataFacet);
+ if (0 == metaDataFacet.getChildCount()) {
+ facesContext.renderResponse();
+ }
                         }
                     }
                 } else {
Index: jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/faces-config.NavData
===================================================================
--- jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/faces-config.NavData (revision 0)
+++ jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/faces-config.NavData (revision 0)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scene Scope="Project" version="2">
+ <Scope Scope="Faces Configuration Only"/>
+ <Scope Scope="Project">
+ <Node id="main.xhtml" x="150" y="150" zoom="true"/>
+ </Scope>
+ <Scope Scope="All Faces Configurations"/>
+</Scene>
Index: jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/java/com/sun/faces/regression/i_spec_762/UserBean.java
===================================================================
--- jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/java/com/sun/faces/regression/i_spec_762/UserBean.java (revision 0)
+++ jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/java/com/sun/faces/regression/i_spec_762/UserBean.java (revision 0)
@@ -0,0 +1,34 @@
+package com.sun.faces.regression.i_spec_762;
+
+import java.util.Map;
+import javax.enterprise.context.RequestScoped;
+import javax.faces.context.FacesContext;
+import javax.inject.Named;
+
+_at_RequestScoped
+_at_Named("bean")
+public class UserBean {
+
+ void appendMessage(String message) {
+ FacesContext context = FacesContext.getCurrentInstance();
+ Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
+ StringBuilder builder;
+ builder = (StringBuilder) requestMap.get("builder");
+ if (null == builder) {
+ builder = new StringBuilder();
+ requestMap.put("builder", builder);
+ }
+ builder.append(message);
+ }
+
+ public String getMessage() {
+ FacesContext context = FacesContext.getCurrentInstance();
+ Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
+ String result = (requestMap.containsKey("builder")) ? ((StringBuilder)requestMap.get("builder")).toString() : "no message";
+
+ return result;
+ }
+
+
+}
+
Index: jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/java/com/sun/faces/regression/i_spec_762/Issue762PhaseListener.java
===================================================================
--- jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/java/com/sun/faces/regression/i_spec_762/Issue762PhaseListener.java (revision 0)
+++ jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/java/com/sun/faces/regression/i_spec_762/Issue762PhaseListener.java (revision 0)
@@ -0,0 +1,80 @@
+
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common Development
+ * and Distribution License("CDDL") (collectively, the "License"). You
+ * may not use this file except in compliance with the License. You can
+ * obtain a copy of the License at
+ * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
+ * or packager/legal/LICENSE.txt. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at packager/legal/LICENSE.txt.
+ *
+ * GPL Classpath Exception:
+ * Oracle designates this particular file as subject to the "Classpath"
+ * exception as provided by Oracle in the GPL Version 2 section of the License
+ * file that accompanied this code.
+ *
+ * Modifications:
+ * If applicable, add the following below the License Header, with the fields
+ * enclosed by brackets [] replaced by your own identifying information:
+ * "Portions Copyright [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or GPL
+ * Version 2] license." If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above. However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+package com.sun.faces.regression.i_spec_762;
+
+import java.util.Map;
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+
+public class Issue762PhaseListener implements PhaseListener {
+
+ @Override
+ public void afterPhase(PhaseEvent event) {
+ }
+
+ @Override
+ public void beforePhase(PhaseEvent event) {
+ UserBean bean = getUserBean(event.getFacesContext());
+ bean.appendMessage(" beforePhase " + event.getPhaseId().toString());
+ }
+
+ private UserBean getUserBean(FacesContext context) {
+ // Can't inject into PhaseListener. Phooey.
+ Map<String, Object> requestScope = context.getExternalContext().getRequestMap();
+ UserBean result = (UserBean) requestScope.get("bean");
+ if (null == result) {
+ result = new UserBean();
+ requestScope.put("bean", result);
+ }
+
+ return result;
+ }
+
+ @Override
+ public PhaseId getPhaseId() {
+ return PhaseId.ANY_PHASE;
+ }
+
+
+
+}
Index: jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/webapp/main.xhtml
===================================================================
--- jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/webapp/main.xhtml (revision 0)
+++ jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/webapp/main.xhtml (revision 0)
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core">
+ <f:metadata id="metadata">
+ <h:inputHidden id="metadataHidden" />
+ </f:metadata>
+<h:head>
+ <title>i_spec_762</title>
+</h:head>
+<h:body>
+ <h:form prependId="false">
+ <p><h:commandButton id="button" value="submit" /></p>
+ </h:form>
+
+ <p>Message: #{bean.message}</p>
+
+</h:body>
+</html>
Index: jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/webapp/WEB-INF/faces-config.xml (revision 0)
+++ jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/webapp/WEB-INF/faces-config.xml (revision 0)
@@ -0,0 +1,14 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<!-- =========== FULL CONFIGURATION FILE ================================== -->
+
+<faces-config version="2.0"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
+
+ <lifecycle>
+ <phase-listener>com.sun.faces.regression.i_spec_762.Issue762PhaseListener</phase-listener>
+ </lifecycle>
+
+</faces-config>
Index: jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/webapp/WEB-INF/web.xml
===================================================================
--- jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/webapp/WEB-INF/web.xml (revision 0)
+++ jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/src/main/webapp/WEB-INF/web.xml (revision 0)
@@ -0,0 +1,39 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<web-app version="3.0"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
+
+ <display-name>mojarra-regression-test</display-name>
+ <description>A simple regression test to make it easier to get your bug fixed. The only reason we need a web.xml is to set the PROJECT_STAGE to Develoment. If you have a web.xml, then you need to map the FacesServlet.</description>
+
+ <context-param>
+ <description>
+ Tell the runtime where we are in the project development
+ lifecycle. Valid values are:
+ Development, UnitTest, SystemTest, or Production.
+ The runtime will display helpful hints to correct common mistakes
+ when the value is Development.
+ </description>
+ <param-name>javax.faces.PROJECT_STAGE</param-name>
+ <param-value>Development</param-value>
+ </context-param>
+
+ <!-- Faces Servlet -->
+ <servlet>
+ <servlet-name>Faces Servlet</servlet-name>
+ <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>Faces Servlet</servlet-name>
+ <url-pattern>/faces/*</url-pattern>
+ </servlet-mapping>
+
+ <welcome-file-list>
+ <welcome-file>faces/main.xhtml</welcome-file>
+ </welcome-file-list>
+
+</web-app>
Index: jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/pom.xml
===================================================================
--- jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/pom.xml (revision 0)
+++ jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/i_spec_762_war/pom.xml (revision 0)
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.sun.faces.regression.i_spec_762</groupId>
+ <artifactId>i_spec_762_war</artifactId>
+ <version>1.0</version>
+ <packaging>war</packaging>
+ <name>${project.artifactId}</name>
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>javax.faces</groupId>
+ <artifactId>jsf-api</artifactId>
+ <version>2.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax</groupId>
+ <artifactId>javaee-api</artifactId>
+ <version>6.0</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <id>java.net-maven2-repository</id>
+ <name>Java.net Repository for Maven</name>
+ <url>http://download.java.net/maven/2/</url>
+ <layout>default</layout>
+ </repository>
+ </repositories>
+</project>
Index: jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/build.xml
===================================================================
--- jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/build.xml (revision 0)
+++ jsf-test/JAVASERVERFACES_SPEC_PUBLIC-762/build.xml (revision 0)
@@ -0,0 +1,91 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+
+ Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.
+
+ The contents of this file are subject to the terms of either the GNU
+ General Public License Version 2 only ("GPL") or the Common Development
+ and Distribution License("CDDL") (collectively, the "License"). You
+ may not use this file except in compliance with the License. You can
+ obtain a copy of the License at
+ https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
+ or packager/legal/LICENSE.txt. See the License for the specific
+ language governing permissions and limitations under the License.
+
+ When distributing the software, include this License Header Notice in each
+ file and include the License file at packager/legal/LICENSE.txt.
+
+ GPL Classpath Exception:
+ Oracle designates this particular file as subject to the "Classpath"
+ exception as provided by Oracle in the GPL Version 2 section of the License
+ file that accompanied this code.
+
+ Modifications:
+ If applicable, add the following below the License Header, with the fields
+ enclosed by brackets [] replaced by your own identifying information:
+ "Portions Copyright [year] [name of copyright owner]"
+
+ Contributor(s):
+ If you wish your version of this file to be governed by only the CDDL or
+ only the GPL Version 2, indicate your decision by adding "[Contributor]
+ elects to include this software in this distribution under the [CDDL or GPL
+ Version 2] license." If you don't indicate a single choice of license, a
+ recipient has the option to distribute your version of this file under
+ either the CDDL, the GPL Version 2 or to extend the choice of license to
+ its licensees as provided above. However, if you add GPL Version 2 code
+ and therefore, elected the GPL Version 2 license, then the option applies
+ only if the new code is made subject to such option by the copyright
+ holder.
+
+-->
+
+<!-- ************ JSF build file ************************************** -->
+
+<project name="JAVASERVERFACES_SPEC_PUBLIC-762" default="test" basedir=".">
+
+ <property file="../../build.properties"/>
+
+ <import file="${jsf.build.home}/common/ant/common.xml"/>
+
+ <target name="build">
+
+ <jsf.mvn dir="${basedir}/i_spec_762_war" goals="install" />
+
+ </target>
+
+ <target name="clean">
+
+ <jsf.mvn dir="${basedir}/i_spec_762_war" goals="clean" />
+
+ </target>
+
+ <target name="install">
+ <deploy.artifact
+ artifact="${basedir}/i_spec_762_war/target/i_spec_762_war.war"
+ appName="i_spec_762_war"/>
+
+ </target>
+
+ <target name="remove">
+
+ <undeploy.artifact
+ artifact="${basedir}/i_spec_762/target/i_spec_762_war.war"
+ appName="i_spec_762_war"/>
+
+ </target>
+
+ <target name="test" depends="define.scenario.aware.port">
+
+ <jsf.tester request="/"
+ context-path="/i_spec_762_war"
+ classpath-refid="html.classpath"
+ test-results-dir="${regression.test.results.dir}"
+ regexp="(?s).*beforePhase\s+RESTORE_VIEW\s+1\s+beforePhase\s+APPLY_REQUEST_VALUES\s+2\s+beforePhase\s+PROCESS_VALIDATIONS\s+3\s+beforePhase\s+UPDATE_MODEL_VALUES\s+4\s+beforePhase\s+INVOKE_APPLICATION\s+5\s+beforePhase\s+RENDER_RESPONSE\s+6.*"/>
+
+ </target>
+
+
+
+</project>
Index: jsf-test/build.xml
===================================================================
--- jsf-test/build.xml (revision 9138)
+++ jsf-test/build.xml (working copy)
@@ -76,7 +76,8 @@
                     JAVASERVERFACES_SPEC_PUBLIC-915,
                     JAVASERVERFACES-2079,
                     JAVASERVERFACES-2065,
- JAVASERVERFACES-1995" />
+ JAVASERVERFACES-1995,
+ JAVASERVERFACES_SPEC_PUBLIC-762" />
 
     <target name="main" depends="define.applications"
             description="">



-- 
| edward.burns_at_oracle.com | office: +1 407 458 0017
| homepage:               | http://ridingthecrest.com/
|  6 Business Days til JSF 2.2 Early Draft Review
| 42 Business Days til JSF 2.2 Public Review
| 130 Business Days til JSF 2.2 Proposed Final Draft