(TRINIDAD-2545)
Update of view state in partial response not working (JSF 2.2)

some more jsf 2.2 fixes and myfaces 2.2 fixes
added profile for jsf 2.2 see comment in root pom.xml
update jsf impl versions 
update jetty plugin

diff --git a/pom.xml b/pom.xml
index 70738fe..175a3eb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -67,8 +67,8 @@
     <jsp.version>2.1</jsp.version>
     <jstl.version>1.2</jstl.version>
     <jsf-spec.version>2.1</jsf-spec.version>
-    <jsf-ri.version>2.1.7</jsf-ri.version>
-    <jsf-myfaces.version>2.1.6</jsf-myfaces.version>
+    <jsf-ri.version>2.1.29-08</jsf-ri.version>
+    <jsf-myfaces.version>2.1.18</jsf-myfaces.version>
     <portlet-bridge.version>2.0.0</portlet-bridge.version>
     <commons-lang.version>2.4</commons-lang.version>
     <commons-io.version>2.0</commons-io.version>
@@ -84,7 +84,8 @@
     <!-- Plugins -->
     <trinidad-plugins.version>2.0.8</trinidad-plugins.version>
     <wagon-plugin.version>1.0.6</wagon-plugin.version>
-    <jetty-plugin.version>6.1.21</jetty-plugin.version>
+    <jetty.groupId>org.mortbay.jetty</jetty.groupId>
+    <jetty-plugin.version>7.6.9.v20130131</jetty-plugin.version>
     <pluto.version>1.1.6</pluto.version>
     <pluto.package>org.apache.pluto</pluto.package>
     <myfaces-builder-plugin.version>1.0.9</myfaces-builder-plugin.version>
@@ -579,8 +580,8 @@
         </plugin>
 
         <plugin>
-          <groupId>org.mortbay.jetty</groupId>
-          <artifactId>maven-jetty-plugin</artifactId>
+          <groupId>${jetty.groupId}</groupId>
+          <artifactId>jetty-maven-plugin</artifactId>
           <version>${jetty-plugin.version}</version>
         </plugin>
 
@@ -1035,6 +1036,22 @@
       </dependencyManagement>      
     </profile>
 
+    <profile>
+      <id>jsfversion</id>
+      <activation>
+        <property>
+          <name>jsfversion</name>
+          <value>2.2</value>
+        </property>
+      </activation>
+      <properties>
+        <jsf-ri.version>2.2.14</jsf-ri.version>
+        <jsf-myfaces.version>2.2.12</jsf-myfaces.version>
+        <jetty.groupId>org.eclipse.jetty</jetty.groupId>
+        <jetty-plugin.version>9.2.13.v20150730</jetty-plugin.version>
+      </properties>
+    </profile>
+
   </profiles>
 
 </project>
diff --git a/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java b/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java
index 347c798..0d466d0 100644
--- a/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java
+++ b/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java
@@ -30,6 +30,7 @@
 import java.util.Set;
 
 import javax.faces.FacesException;
+import javax.faces.application.StateManager;
 import javax.faces.component.ContextCallback;
 import javax.faces.component.NamingContainer;
 import javax.faces.component.UIComponent;
@@ -692,7 +693,7 @@
     super.setupVisitingContext(context);
     _setupContextChange();
 
-    if (Boolean.TRUE.equals(context.getAttributes().get("javax.faces.IS_SAVING_STATE")))
+    if (Boolean.TRUE.equals(context.getAttributes().get(StateManager.IS_SAVING_STATE)))
     {
       _stateSavingCurrencyKey = _resetCurrencyKeyForStateSaving(context);
     }
@@ -701,7 +702,7 @@
   @Override
   protected void tearDownVisitingContext(FacesContext context)
   {
-    if (Boolean.TRUE.equals(context.getAttributes().get("javax.faces.IS_SAVING_STATE")))
+    if (Boolean.TRUE.equals(context.getAttributes().get(StateManager.IS_SAVING_STATE)))
     {
       _restoreCurrencyKeyForStateSaving(_stateSavingCurrencyKey);
       _resetInternalState();
diff --git a/trinidad-examples/trinidad-blank/pom.xml b/trinidad-examples/trinidad-blank/pom.xml
index 114753d..107b095 100644
--- a/trinidad-examples/trinidad-blank/pom.xml
+++ b/trinidad-examples/trinidad-blank/pom.xml
@@ -78,8 +78,8 @@
       <build>
         <plugins>
           <plugin>
-            <groupId>org.mortbay.jetty</groupId>
-            <artifactId>maven-jetty-plugin</artifactId>
+            <groupId>${jetty.groupId}</groupId>
+            <artifactId>jetty-maven-plugin</artifactId>
             
             <configuration>
               <scanIntervalSeconds>10</scanIntervalSeconds>
diff --git a/trinidad-examples/trinidad-blank/src/main/webapp/WEB-INF/faces-config.xml b/trinidad-examples/trinidad-blank/src/main/webapp/WEB-INF/faces-config.xml
index 2172be8..66eb6c8 100644
--- a/trinidad-examples/trinidad-blank/src/main/webapp/WEB-INF/faces-config.xml
+++ b/trinidad-examples/trinidad-blank/src/main/webapp/WEB-INF/faces-config.xml
@@ -20,7 +20,7 @@
 -->
 <faces-config 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"
+              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd"
               version="2.1">
   
   <application>
diff --git a/trinidad-examples/trinidad-components-showcase/pom.xml b/trinidad-examples/trinidad-components-showcase/pom.xml
index ad7b13a..d4455e2 100644
--- a/trinidad-examples/trinidad-components-showcase/pom.xml
+++ b/trinidad-examples/trinidad-components-showcase/pom.xml
@@ -113,8 +113,8 @@
           <build>
             <plugins>
               <plugin>
-                <groupId>org.mortbay.jetty</groupId>
-                <artifactId>maven-jetty-plugin</artifactId>
+                <groupId>${jetty.groupId}</groupId>
+                <artifactId>jetty-maven-plugin</artifactId>
                 <configuration>
                   <scanIntervalSeconds>10</scanIntervalSeconds>
                 </configuration>
diff --git a/trinidad-examples/trinidad-components-showcase/src/main/java/org/apache/myfaces/trinidaddemo/support/IComponentVariantDemo.java b/trinidad-examples/trinidad-components-showcase/src/main/java/org/apache/myfaces/trinidaddemo/support/IComponentVariantDemo.java
index 736d937..12fb497 100644
--- a/trinidad-examples/trinidad-components-showcase/src/main/java/org/apache/myfaces/trinidaddemo/support/IComponentVariantDemo.java
+++ b/trinidad-examples/trinidad-components-showcase/src/main/java/org/apache/myfaces/trinidaddemo/support/IComponentVariantDemo.java
@@ -106,5 +106,5 @@
    * 
    * @return true if this component demo is static, otherwise returns false.
    */
-  boolean isStatic();
+  boolean isDynamic();
 }
diff --git a/trinidad-examples/trinidad-components-showcase/src/main/java/org/apache/myfaces/trinidaddemo/support/impl/AbstractComponentVariantDemo.java b/trinidad-examples/trinidad-components-showcase/src/main/java/org/apache/myfaces/trinidaddemo/support/impl/AbstractComponentVariantDemo.java
index fc48607..e3c7cb1 100644
--- a/trinidad-examples/trinidad-components-showcase/src/main/java/org/apache/myfaces/trinidaddemo/support/impl/AbstractComponentVariantDemo.java
+++ b/trinidad-examples/trinidad-components-showcase/src/main/java/org/apache/myfaces/trinidaddemo/support/impl/AbstractComponentVariantDemo.java
@@ -102,8 +102,8 @@
     return null;
   }
 
-  public boolean isStatic() {
-    return getBackingBeanResourcePath() == null;
+  public boolean isDynamic() {
+    return getBackingBeanResourcePath() != null;
   }
 
     private String getDefault() {
diff --git a/trinidad-examples/trinidad-components-showcase/src/main/webapp/WEB-INF/faces-config.xml b/trinidad-examples/trinidad-components-showcase/src/main/webapp/WEB-INF/faces-config.xml
index fbe6b6a..923709e 100644
--- a/trinidad-examples/trinidad-components-showcase/src/main/webapp/WEB-INF/faces-config.xml
+++ b/trinidad-examples/trinidad-components-showcase/src/main/webapp/WEB-INF/faces-config.xml
@@ -20,7 +20,7 @@
 -->        
 <faces-config 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"
+              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd"
               version="2.1">    
 
   <application>
diff --git a/trinidad-examples/trinidad-components-showcase/src/main/webapp/pages/componentDemo.xhtml b/trinidad-examples/trinidad-components-showcase/src/main/webapp/pages/componentDemo.xhtml
index 46d1e0b..82e37db 100644
--- a/trinidad-examples/trinidad-components-showcase/src/main/webapp/pages/componentDemo.xhtml
+++ b/trinidad-examples/trinidad-components-showcase/src/main/webapp/pages/componentDemo.xhtml
@@ -108,7 +108,7 @@
                             </tr:showDetailItem>
                         </c:forEach>
 
-                        <tr:showDetailItem text="Backing Beans" rendered="#{!navigationHandler.currentComponentVariantDemo.static}">
+                        <tr:showDetailItem text="Backing Beans" rendered="#{navigationHandler.currentComponentVariantDemo.dynamic}">
                             <trd:outputSource value="#{navigationHandler.currentComponentVariantDemo.backingBeanResourcePath}"
                                               pathPrefix="/WEB-INF/src" styleClass="sourceCode" styleUsage="java"/>
                         </tr:showDetailItem>
diff --git a/trinidad-examples/trinidad-demo/pom.xml b/trinidad-examples/trinidad-demo/pom.xml
index fd4c599..9d00bed 100644
--- a/trinidad-examples/trinidad-demo/pom.xml
+++ b/trinidad-examples/trinidad-demo/pom.xml
@@ -170,9 +170,8 @@
       <build>
         <plugins>
           <plugin>
-            <groupId>org.mortbay.jetty</groupId>
-            <artifactId>maven-jetty-plugin</artifactId>
-            
+            <groupId>${jetty.groupId}</groupId>
+            <artifactId>jetty-maven-plugin</artifactId>
             <configuration>
               <scanIntervalSeconds>10</scanIntervalSeconds>
             </configuration>
@@ -280,7 +279,7 @@
 		<build>      
         <plugins>
           <plugin>
-            <groupId>org.mortbay.jetty</groupId>
+            <groupId>${jetty.groupId}</groupId>
             <artifactId>jetty-maven-plugin</artifactId>
             <configuration>
               <webXml>${project.build.directory}/pluto-resources/web.xml</webXml>
diff --git a/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/faces-config.xml b/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/faces-config.xml
index 4fa028b..18048e3 100644
--- a/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/faces-config.xml
+++ b/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/faces-config.xml
@@ -20,7 +20,7 @@
 -->
 <faces-config 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"
+              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd"
               version="2.1">
 
   <application>
diff --git a/trinidad-impl/pom.xml b/trinidad-impl/pom.xml
index be26c65..3acd77a 100644
--- a/trinidad-impl/pom.xml
+++ b/trinidad-impl/pom.xml
@@ -69,7 +69,7 @@
     <dependency>
       <groupId>com.sun.faces</groupId>
       <artifactId>jsf-api</artifactId>
-      <scope>provided</scope> 
+      <scope>provided</scope>
     </dependency>
 
     <dependency>
diff --git a/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java b/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java
index 7474ce0..e77b2de 100644
--- a/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java
+++ b/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java
@@ -67,6 +67,7 @@
 import org.apache.myfaces.trinidad.util.ref.StrongPseudoReferenceFactory;
 import org.apache.myfaces.trinidadinternal.context.RequestContextImpl;
 import org.apache.myfaces.trinidadinternal.context.TrinidadPhaseListener;
+import org.apache.myfaces.trinidadinternal.util.JsfUtils;
 import org.apache.myfaces.trinidadinternal.util.ObjectInputStreamResolveClass;
 import org.apache.myfaces.trinidadinternal.util.SubKeyMap;
 import org.apache.myfaces.trinidadinternal.util.TokenCache;
@@ -191,9 +192,7 @@
     
     try
     {
-      // TODO Once we're dependent on JSF 2.1 we should be using StateManager.IS_SAVING_STATE as the key, but 
-      // for now we can use the String value of StateManager.IS_SAVING_STATE
-      contextAttributes.put("javax.faces.IS_SAVING_STATE", Boolean.TRUE);
+      contextAttributes.put(StateManager.IS_SAVING_STATE, Boolean.TRUE);
       
       if (sms != null)
       {
@@ -220,9 +219,7 @@
     }
     finally 
     {
-      // TODO Once we're dependent on JSF 2.1 we should be using StateManager.IS_SAVING_STATE as the key, but 
-      // for now we can use the String value of StateManager.IS_SAVING_STATE
-      contextAttributes.remove("javax.faces.IS_SAVING_STATE");
+      contextAttributes.remove(StateManager.IS_SAVING_STATE);
     }
 
     if (_saveAsToken(context, false))
@@ -1237,10 +1234,21 @@
       String caseInsensitiveViewRootCaching;
       
       if ((viewRootCaching != null) && (viewRootCaching.length() > 0))
+      {
         caseInsensitiveViewRootCaching = viewRootCaching.toLowerCase();
+      }
       else
-        caseInsensitiveViewRootCaching = "true"; // the default
-      
+      {
+        // ViewRootCaching conflicts with myfaces >= 2,2
+        if (JsfUtils.IS_JSF_2_2 && JsfUtils.IS_MYFACES)
+        {
+          caseInsensitiveViewRootCaching = "false";
+        }
+        else
+        {
+          caseInsensitiveViewRootCaching = "true"; // the default
+        }
+      }
       PseudoReferenceFactory<ViewRootState> factory;
   
       if ("false".equals(caseInsensitiveViewRootCaching))
diff --git a/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormRenderer.java b/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormRenderer.java
index 5989677..68527c7 100644
--- a/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormRenderer.java
+++ b/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormRenderer.java
@@ -439,15 +439,7 @@
       rw.writeAttribute("value", state, null);
       rw.endElement("input");
     }
-    else
-    {
-      // Include JSF state.
-      // Note that MultiViewHandler in JSF RI will not write the state
-      // for any AJAX requests. PartialViewContextImpl will write out the state
-      // for these requets
-      context.getApplication().getViewHandler().writeState(context);
-    }
-    
+
     // Include the Window state, if any
     RequestContext.getCurrentInstance().getWindowManager().writeState(context);
 
@@ -471,6 +463,17 @@
     // Close up our postscript span if we have one
     if (postscriptId != null)
       rw.endElement("span");
+
+    if (!(isPDA(rc) &&
+            RequestContext.getCurrentInstance().isPartialRequest(context)))
+    {
+      // Include JSF state.
+      // Note that MultiViewHandler in JSF RI will not write the state
+      // for any AJAX requests. PartialViewContextImpl will write out the state
+      // for these requets
+      context.getApplication().getViewHandler().writeState(context);
+    }
+
   }
 
   @Override
diff --git a/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/JsfUtils.java b/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/JsfUtils.java
index 893f6e2..07a36c3 100644
--- a/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/JsfUtils.java
+++ b/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/JsfUtils.java
@@ -22,6 +22,8 @@
 
     public static final boolean IS_JSF_2_2 = ClassUtils.isPresent("javax.faces.flow.Flow");
 
+    public static final boolean IS_MYFACES = ClassUtils.isPresent("org.apache.myfaces.application.ApplicationImpl");
+
     private JsfUtils() {
     }