[410117] Problems creating child modules from New Ear wizard
diff --git a/plugins/org.eclipse.jst.j2ee/common/org/eclipse/jst/j2ee/internal/common/J2EEVersionUtil.java b/plugins/org.eclipse.jst.j2ee/common/org/eclipse/jst/j2ee/internal/common/J2EEVersionUtil.java
index d19bbc7..45051bf 100644
--- a/plugins/org.eclipse.jst.j2ee/common/org/eclipse/jst/j2ee/internal/common/J2EEVersionUtil.java
+++ b/plugins/org.eclipse.jst.j2ee/common/org/eclipse/jst/j2ee/internal/common/J2EEVersionUtil.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2005, 2007 IBM Corporation and others.
+ * Copyright (c) 2005, 2014 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -13,10 +13,12 @@
  */
 package org.eclipse.jst.j2ee.internal.common;
 
+import org.eclipse.jst.common.project.facet.core.JavaFacet;
 import org.eclipse.jst.j2ee.internal.J2EEVersionConstants;
 import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
 import org.eclipse.jst.j2ee.project.JavaEEProjectUtilities;
 import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
 
 /**
  * @author nagrawal
@@ -382,4 +384,27 @@
 		return nVersion;
 	}
 	
+	public static IProjectFacetVersion getJavaFacetVersionForJavaEE(int javaEEVersion){
+		IProjectFacetVersion javaFacetVersion = null;
+
+		switch (javaEEVersion){
+			case J2EEVersionConstants.J2EE_1_2_ID:
+			case J2EEVersionConstants.J2EE_1_3_ID:
+			case J2EEVersionConstants.J2EE_1_4_ID:
+				javaFacetVersion = JavaFacet.VERSION_1_4;
+				break;
+			case J2EEVersionConstants.JEE_5_0_ID:
+				javaFacetVersion = JavaFacet.VERSION_1_5;
+				break;
+			case J2EEVersionConstants.JEE_6_0_ID:
+				javaFacetVersion = JavaFacet.VERSION_1_6;
+				break;
+			case J2EEVersionConstants.JEE_7_0_ID:
+				javaFacetVersion = JavaFacet.VERSION_1_7;
+				break;
+		}
+		
+		return javaFacetVersion;
+	}
+	
 }
diff --git a/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/internal/earcreation/DefaultJ2EEComponentCreationDataModelProvider.java b/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/internal/earcreation/DefaultJ2EEComponentCreationDataModelProvider.java
index d75ca36..c0280c7 100644
--- a/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/internal/earcreation/DefaultJ2EEComponentCreationDataModelProvider.java
+++ b/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/internal/earcreation/DefaultJ2EEComponentCreationDataModelProvider.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2003, 2006 IBM Corporation and others.
+ * Copyright (c) 2003, 2014 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -261,6 +261,8 @@
 
 	private void updatedJ2EEVersion(Integer version) {
 		setNestedJ2EEVersion(version);
+		// Make sure the correct java version is used for the Java EE version specified.
+		setNestedJavaVersion(version);
 		if (version.intValue() < J2EEVersionConstants.J2EE_1_3_ID && model.isPropertySet(CREATE_CONNECTOR)) {
 			model.setProperty(CREATE_CONNECTOR, Boolean.FALSE);
 		}
@@ -445,6 +447,43 @@
 			fpwc.changeProjectFacetVersion(facetVersion);
 		}
 	}
+	
+	private void setNestedJavaVersion(int j2eeVersion){
+		if (ejbModel != null && ejbFacetModel != null) {
+			setJavaVersion(j2eeVersion, ejbModel);
+		}
+		if (webModel != null &&webFacetModel != null) {
+			setJavaVersion(j2eeVersion, webModel);
+		}
+		if (jcaModel != null && jcaFacetModel != null) {
+			setJavaVersion(j2eeVersion, jcaModel);
+		}
+		if (clientModel != null && clientFacetModel != null){
+			setJavaVersion(j2eeVersion, clientModel);
+		}
+	}
+	
+	/*
+	 * 
+	 * Sets the version of the java facet to be used based on the Java EE version.
+	 */
+	private void setJavaVersion(int javaEEVersion, IDataModel j2eeModel){
+		IProjectFacetVersion javaFacetVersion = J2EEVersionUtil.getJavaFacetVersionForJavaEE(javaEEVersion);
+
+		if(javaFacetVersion != null){
+			FacetDataModelMap map = (FacetDataModelMap) j2eeModel.getProperty(IFacetProjectCreationDataModelProperties.FACET_DM_MAP);
+			if (map != null){
+				IDataModel javaFacetDataModel = map.getFacetDataModel( J2EEProjectUtilities.JAVA );
+				if (javaFacetDataModel != null){
+					javaFacetDataModel.setProperty(IFacetDataModelProperties.FACET_VERSION, javaFacetVersion);
+					//IFacetedProjectWorkingCopy facet version is not automatically updated so it has to be done manually
+					IFacetedProjectWorkingCopy fpwc = (IFacetedProjectWorkingCopy)j2eeModel.getProperty(IFacetProjectCreationDataModelProperties.FACETED_PROJECT_WORKING_COPY);
+					fpwc.changeProjectFacetVersion(javaFacetVersion);
+				}
+			}
+		}
+
+	}
 
 	private IDataModel getNestedModel(int flag) {
 		switch (flag) {