empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rei...@apache.org
Subject svn commit: r1195598 [1/2] - in /incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2: ./ src/ src/main/ src/main/java/ src/main/java/components/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/empire/ src/main/java...
Date Mon, 31 Oct 2011 18:26:51 GMT
Author: reiher
Date: Mon Oct 31 18:26:48 2011
New Revision: 1195598

URL: http://svn.apache.org/viewvc?rev=1195598&view=rev
Log:
EMPIREDB-119 Initial commit of JSF2 / ICEfaces example

Added:
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/pom.xml
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/ValidationMessages_de.properties
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/ValidationMessages_en.properties
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/components/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/components/control.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/components/record.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/SampleDB.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/SampleTable.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/DepartmentRecord.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/EmployeeRecord.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/FacesUtils.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/PageELResolver.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplication.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleConfig.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleContext.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleEventListener.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleExceptionHandler.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleExceptionHandlerFactory.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleNavigationHandler.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SamplePhaseListener.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleRequest.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleRequestFilter.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleSession.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleUser.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/objects/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/objects/EmployeeSearch.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/objects/User.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/EmployeeDetailPage.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/EmployeeListPage.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/EmployeeSearchPage.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/ErrorPage.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/LoginPage.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/Page.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/resources/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/resources/lang/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/resources/lang/messages_de.properties
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/resources/lang/messages_en.properties
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/config.xml
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/facelets/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/facelets/templates/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/facelets/templates/header.xhtml
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/facelets/templates/layout.xhtml
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/faces-config.xml
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/web.xml
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/css/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/css/sample.css
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/index.html
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/pages/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/pages/employeeDetailPage.xhtml
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/pages/employeeListPage.xhtml
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/pages/employeeSearchPage.xhtml
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/pages/loginPage.xhtml
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/resources/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/resources/components/
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/resources/components/control.xhtml
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/resources/components/record.xhtml

Added: incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/pom.xml
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/pom.xml?rev=1195598&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/pom.xml (added)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/pom.xml Mon Oct 31 18:26:48 2011
@@ -0,0 +1,154 @@
+<?xml version="1.0" encoding="UTF-8"?>
+	<!--
+		Licensed to the Apache Software Foundation (ASF) under one or more
+		contributor license agreements. See the NOTICE file distributed with
+		this work for additional information regarding copyright ownership.
+		The ASF licenses this file to You under the Apache License, Version
+		2.0 (the "License"); you may not use this file except in compliance
+		with the License. You may obtain a copy of the License at
+
+		http://www.apache.org/licenses/LICENSE-2.0 Unless required by
+		applicable law or agreed to in writing, software distributed under the
+		License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+		CONDITIONS OF ANY KIND, either express or implied. See the License for
+		the specific language governing permissions and limitations under the
+		License.
+	-->
+<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/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.empire-db</groupId>
+		<artifactId>empire-db-examples</artifactId>
+		<version>2.2.1-incubating-SNAPSHOT</version>
+	</parent>
+	<artifactId>empire-db-example-jsf2</artifactId>
+	<packaging>war</packaging>
+	<name>Apache Empire-db JSF2 Example</name>
+	<description>Examples showing the use of empire-db.</description>
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.empire-db</groupId>
+			<artifactId>empire-db</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>javax.servlet</groupId>
+			<artifactId>servlet-api</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>javax.servlet.jsp</groupId>
+			<artifactId>jsp-api</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>hsqldb</groupId>
+			<artifactId>hsqldb</artifactId>
+		</dependency>
+		<dependency>
+            <groupId>javax.portlet</groupId>
+            <artifactId>portlet-api</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+        
+        <!-- use log4j for logging -->
+<!-- 		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-log4j12</artifactId>
+		</dependency> -->
+		
+		<!-- ICEfaces -->
+		<dependency>
+			<groupId>org.apache.tomcat</groupId>
+			<artifactId>el-api</artifactId>
+			<version>6.0.30</version>
+			<type>jar</type>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.sun.faces</groupId>
+			<artifactId>jsf-api</artifactId>
+			<version>2.1.0</version>
+			<scope>compile</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.sun.faces</groupId>
+			<artifactId>jsf-impl</artifactId>
+			<version>2.1.0</version>
+			<scope>compile</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.icefaces</groupId>
+			<artifactId>icefaces</artifactId>
+			<version>2.0.2</version>
+			<type>jar</type>
+			<scope>compile</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.icefaces</groupId>
+			<artifactId>icefaces-ace</artifactId>
+			<version>2.0.2</version>
+			<type>jar</type>
+			<scope>compile</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.icefaces</groupId>
+			<artifactId>icefaces-compat</artifactId>
+			<version>2.0.2</version>
+			<type>jar</type>
+			<scope>compile</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.icepush</groupId>
+			<artifactId>icepush</artifactId>
+			<version>2.0.2</version>
+		</dependency>		
+	</dependencies>
+	<build>
+		<plugins>
+			<!-- WTP-Eclipse-Projekt -->
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-eclipse-plugin</artifactId>
+				<configuration>
+					<m2eclipse>true</m2eclipse>
+					<downloadSources>true</downloadSources>
+					<wtpversion>2.0</wtpversion>
+					<additionalProjectFacets>
+						<jst.jsf>2.0</jst.jsf>
+					</additionalProjectFacets>
+				</configuration>
+			</plugin>
+			<!-- Sysdeo Tomcat Eclipse --> 
+			<plugin>
+			  <groupId>org.codehaus.mojo</groupId>
+			  <artifactId>sysdeo-tomcat-maven-plugin</artifactId>
+			  <version>1.1</version>
+			  <configuration>
+				  <webPath>empire-db-example-jsf2</webPath>
+			  </configuration>
+			</plugin>
+			<!-- Jetty -->			
+			<plugin>
+				<groupId>org.mortbay.jetty</groupId>
+				<artifactId>maven-jetty-plugin</artifactId>
+				<version>6.1.26</version>
+				<configuration>
+					<scanIntervalSeconds>10</scanIntervalSeconds>
+					<stopKey>foo</stopKey>
+					<stopPort>9999</stopPort>
+				</configuration>
+				<executions>
+					<!--
+						<execution> <id>start-jetty</id>
+						<phase>pre-integration-test</phase> <goals> <goal>run</goal>
+						</goals> <configuration>
+						<scanIntervalSeconds>0</scanIntervalSeconds> <daemon>true</daemon>
+						</configuration> </execution> <execution> <id>stop-jetty</id>
+						<phase>post-integration-test</phase> <goals> <goal>stop</goal>
+						</goals> </execution>
+					-->
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
+</project>
\ No newline at end of file

Added: incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/ValidationMessages_de.properties
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/ValidationMessages_de.properties?rev=1195598&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/ValidationMessages_de.properties (added)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/ValidationMessages_de.properties Mon Oct 31 18:26:48 2011
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+user.name = Benutzername darf nicht leer sein
\ No newline at end of file

Added: incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/ValidationMessages_en.properties
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/ValidationMessages_en.properties?rev=1195598&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/ValidationMessages_en.properties (added)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/ValidationMessages_en.properties Mon Oct 31 18:26:48 2011
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+user.name = User name can't be empty
\ No newline at end of file

Added: incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/components/control.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/components/control.java?rev=1195598&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/components/control.java (added)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/components/control.java Mon Oct 31 18:26:48 2011
@@ -0,0 +1,310 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package components;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
+import javax.faces.component.UISelectItem;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.LengthValidator;
+
+import org.apache.empire.commons.OptionEntry;
+import org.apache.empire.commons.Options;
+import org.apache.empire.data.DataType;
+import org.apache.empire.db.DBRecord;
+import org.apache.empire.db.DBTableColumn;
+import org.apache.empire.jsf2.websample.web.FacesUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.icesoft.faces.component.ext.HtmlInputText;
+import com.icesoft.faces.component.ext.HtmlOutputLabel;
+import com.icesoft.faces.component.ext.HtmlSelectBooleanCheckbox;
+import com.icesoft.faces.component.ext.HtmlSelectOneMenu;
+
+public class control extends UIInput implements NamingContainer {
+	// Logger
+	private static final Logger log = LoggerFactory.getLogger(control.class);
+
+	private static final String LABEL_SUFFIX = "label";
+	private static final String INPUT_SUFFIX = "input";
+
+	@Override
+	public String getFamily() {
+		return "javax.faces.NamingContainer";
+	}
+
+	@Override
+	public void encodeBegin(FacesContext context) throws IOException {
+		// add label and input components when the view is loaded for the first time
+		HtmlOutputLabel label = getLabelComponent() == null ? createOutputLabelForCol()
+				: getLabelComponent();
+		UIInput inputComponent = getInputComponent() == null ? createInputComponentForCol()
+				: getInputComponent();
+
+		// render components
+		context.getResponseWriter().startElement("div", null);
+		label.encodeAll(context);
+		inputComponent.encodeAll(context);
+		context.getResponseWriter().endElement("div");
+
+		super.encodeBegin(context);
+	}
+
+	@Override
+	public void updateModel(FacesContext context) {
+		DBRecord rec = getRecord();
+		DBTableColumn col = getColumn();
+
+		// don't set automatically created cols or readOnly cols
+		if (!col.isAutoGenerated() && !isReadOnly()) {
+			UIInput inputComponent = getInputComponent();
+			rec.setValue(col, inputComponent.getValue());
+		}
+		super.updateModel(context);
+	}
+
+	@Override
+	public void validate(FacesContext context) {
+		// nothing submitted (AJAX part request, e.g. calendar component) or readonly (won't be set in updateModel())?
+		UIInput inputComponent = getInputComponent();
+		if (isReadOnly() || inputComponent == null || inputComponent.getSubmittedValue() == null)
+		{
+			return;
+		}
+		
+		DBRecord rec = getRecord();
+		DBTableColumn col = (DBTableColumn) rec.getDBColumn(rec
+				.getFieldIndex(getAttributes().get("column").toString()));
+		try {
+			inputComponent.validate(context);
+			col.checkValue(inputComponent.getValue());
+		} catch (Exception e) {
+			FacesContext.getCurrentInstance().addMessage(getClientId(), new FacesMessage(e.getLocalizedMessage()));
+			this.setValid(false);
+		}
+		super.validate(context);
+	}
+
+	private void addSelectItems(UIComponent component) {
+		Options options = getRecord().getFieldOptions(getColumn());
+		if (options != null) {
+			Iterator<OptionEntry> optionsIterator = options.iterator();
+			while (optionsIterator.hasNext()) {
+				OptionEntry optionEntry = optionsIterator.next();
+				UISelectItem selectItem = new UISelectItem();
+				selectItem.setItemValue(optionEntry.getValue());
+				selectItem.setItemLabel(FacesUtils.getMessageForKey(optionEntry
+						.getText()));
+				component.getChildren().add(selectItem);
+			}
+		}
+	}
+
+	private UIInput createInputComponentForCol() {
+		DBTableColumn col = getColumn();
+		String controlType = col.getControlType();
+		// registerControl("text", new TextInputControl());
+		// registerControl("select", new SelectInputControl());
+		// registerControl("checkbox", new CheckboxInputControl());
+		// registerControl("phone", new PhoneInputControl());
+		// registerControl("radio", new RadioInputControl());
+		// registerControl("textarea", new TextAreaInputControl());
+		// registerControl("email", new EMailInputControl());
+		// registerControl("hlink", new HLinkInputControl());
+		// registerControl("password", new PasswordInputControl());
+		UIInput input = null;
+		if (controlType.equals("text")) {
+			// DATE_TIME
+			if (col.getDataType().equals(DataType.DATETIME))
+			{
+				HtmlInputText inputText = new HtmlInputText();
+				inputText.setReadonly(isReadOnly() || col.isAutoGenerated());
+				inputText.setLabel(getLabelString());
+				input = inputText;				
+			}
+			// AUTOINC
+			else if (col.getDataType().equals(DataType.AUTOINC))
+			{
+				HtmlInputText inputText = new HtmlInputText();
+				inputText.setReadonly(true);
+				inputText.setLabel(getLabelString());
+				input = inputText;				
+			}
+			
+			// INTEGER
+			else if (col.getDataType().equals(DataType.INTEGER))
+			{
+				HtmlInputText inputText = new HtmlInputText();
+				inputText.setReadonly(isReadOnly() || col.isAutoGenerated());
+				inputText.setLabel(getLabelString());
+				input = inputText;				
+			}			
+			// DATE
+			else if (col.getDataType().equals(DataType.TEXT) || col.getDataType().equals(DataType.DATE)) {
+				HtmlInputText inputText = new HtmlInputText();
+				inputText.setReadonly(isReadOnly() || col.isAutoGenerated());
+				inputText.setLabel(getLabelString());
+				input = inputText;
+			}
+			// TEXT
+			else if (col.getDataType().equals(DataType.TEXT) || col.getDataType().equals(DataType.DATE)) {
+				HtmlInputText inputText = new HtmlInputText();
+				inputText.setReadonly(isReadOnly() || col.isAutoGenerated());
+				inputText.setLabel(getLabelString());
+				inputText.setMaxlength((int) Math.round(col.getSize()));
+				input = inputText;
+			}
+		} 
+		
+		else if (controlType.equals("textarea")) {
+			
+			HtmlSelectBooleanCheckbox inputSelectBooleanCheckbox = new HtmlSelectBooleanCheckbox();
+			inputSelectBooleanCheckbox.setReadonly(isReadOnly() || col.isAutoGenerated());
+			inputSelectBooleanCheckbox.setLabel(getLabelString());
+			input = inputSelectBooleanCheckbox;
+		} else if (controlType.equals("password")) {
+			HtmlSelectBooleanCheckbox inputSelectBooleanCheckbox = new HtmlSelectBooleanCheckbox();
+			inputSelectBooleanCheckbox.setReadonly(isReadOnly() || col.isAutoGenerated());
+			inputSelectBooleanCheckbox.setLabel(getLabelString());
+			input = inputSelectBooleanCheckbox;
+		} else if (controlType.equals("select")) {
+			HtmlSelectOneMenu inputSelectOneMenu = new HtmlSelectOneMenu();
+			inputSelectOneMenu.setReadonly(isReadOnly() || col.isAutoGenerated());
+			addSelectItems(inputSelectOneMenu);
+			inputSelectOneMenu.setLabel(getLabelString());
+			input = inputSelectOneMenu;
+
+		} else if (controlType.equals("checkbox")) {
+			HtmlSelectBooleanCheckbox inputSelectBooleanCheckbox = new HtmlSelectBooleanCheckbox();
+			inputSelectBooleanCheckbox.setReadonly(isReadOnly() || col.isAutoGenerated());
+			inputSelectBooleanCheckbox.setLabel(getLabelString());
+			input = inputSelectBooleanCheckbox;
+		} 
+		
+		else if (controlType.equals("phone")) {
+			HtmlInputText inputText = new HtmlInputText();
+			inputText.setReadonly(isReadOnly() || col.isAutoGenerated());
+			inputText.setLabel(getLabelString());
+			inputText.setMaxlength((int) Math.round(col.getSize()));
+			input = inputText;
+		}
+
+		// For testing purposes only
+		if (input == null) {
+			log.error("No matching control found for column "
+					+ col.getFullName());
+			input = new HtmlInputText();
+		}
+
+		// JSF2 Validator
+		switch (col.getDataType()) {
+		case TEXT: {
+			input.addValidator(new LengthValidator((int) Math.round(col
+					.getSize())));
+			break;
+		}
+		}
+
+		input.setRequired(col.isRequired() && !col.isAutoGenerated());
+		input.setId(this.getId() + INPUT_SUFFIX);
+		input.setValue(getRecord().getValue(col));
+		this.getChildren().add(input);
+		return input;
+	}
+
+	private HtmlOutputLabel createOutputLabelForCol() {
+		DBTableColumn col = getColumn();
+		HtmlOutputLabel label = new HtmlOutputLabel();
+		String colName = getLabelString()+":";
+		if (col.isRequired()) {
+			colName += "*";
+		}
+		label.setId(this.getId() + LABEL_SUFFIX);
+		label.setValue(colName);
+		this.getChildren().add(label);
+		return label;
+	}
+
+	private DBRecord getRecord() {
+		// if parent is a record tag, get the record from there
+		record recordComponent = getRecordComponent();
+		if (recordComponent != null)
+		{
+			return recordComponent.getRecord();
+		}
+		return (DBRecord) getAttributes().get("record");
+	}
+
+	private record getRecordComponent() {
+		// walk upwards the parent component tree and return the first record component found (if any)
+		UIComponent parent = this;
+		while ((parent = parent.getParent()) != null)
+		{
+			if (parent instanceof record)
+			{
+				return (record)parent;
+			}
+		}
+		return null;
+	}
+
+	private DBTableColumn getColumn() {
+		return (DBTableColumn) getRecord().getDBColumn(
+				getRecord().getFieldIndex(
+						getAttributes().get("column").toString()));
+	}
+
+	private boolean isReadOnly() {
+		// if readonly attribute is set, override column setting
+		Object readonlyString = getAttributes().get("readonly");
+		if (readonlyString != null)
+		{
+			return Boolean.parseBoolean(readonlyString.toString().toLowerCase());
+		}
+		return getColumn().isReadOnly();
+	}
+
+	private HtmlOutputLabel getLabelComponent() {
+		return (HtmlOutputLabel) findComponent(this.getId() + LABEL_SUFFIX);
+	}
+
+	private UIInput getInputComponent() {
+		return (UIInput) findComponent(this.getId() + INPUT_SUFFIX);
+	}
+
+	private String getLabelString() {
+		String label = null;
+		// check attributes if default col label is overriden
+		if (getAttributes().get("label") != null) {
+			label = getAttributes().get("label").toString();
+		}
+		// not overriden: take label from column full name
+		else {
+			label = getColumn().getFullName();
+		}
+		return FacesUtils.getMessageForKey(label);
+	}
+
+}
\ No newline at end of file

Added: incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/components/record.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/components/record.java?rev=1195598&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/components/record.java (added)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/components/record.java Mon Oct 31 18:26:48 2011
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package components;
+
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIInput;
+
+import org.apache.empire.db.DBRecord;
+
+public class record extends UIInput implements NamingContainer {
+
+	@Override
+	public String getFamily() {
+		return "javax.faces.NamingContainer";
+	}
+
+	public DBRecord getRecord() {
+		return (DBRecord) getAttributes().get("value");
+	}
+}
\ No newline at end of file

Added: incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/SampleDB.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/SampleDB.java?rev=1195598&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/SampleDB.java (added)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/SampleDB.java Mon Oct 31 18:26:48 2011
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.websample.db;
+
+import org.apache.empire.commons.Options;
+import org.apache.empire.data.DataMode;
+import org.apache.empire.data.DataType;
+import org.apache.empire.db.DBColumn;
+import org.apache.empire.db.DBDatabase;
+import org.apache.empire.db.DBTableColumn;
+
+
+public class SampleDB extends DBDatabase
+{
+    private final static long serialVersionUID = 1L;
+  
+    /**
+     * This class represents the definition of the Departments table.
+     */
+    public static class Departments extends SampleTable
+    {
+		private static final long serialVersionUID = -2993431379391158533L;
+
+		public final DBTableColumn C_DEPARTMENT_ID;
+        public final DBTableColumn C_NAME;
+        public final DBTableColumn C_HEAD;
+        public final DBTableColumn C_BUSINESS_UNIT;
+        public final DBTableColumn C_UPDATE_TIMESTAMP;
+
+        public Departments(DBDatabase db)
+        {
+            super("DEPARTMENTS", db);
+            // ID
+            C_DEPARTMENT_ID   = addColumn("DEPARTMENT_ID",    DataType.AUTOINC,       0, DataMode.NotNull, "DEP_ID_SEQUENCE");
+            C_NAME            = addColumn("NAME",             DataType.TEXT,         80, DataMode.NotNull);
+            C_HEAD            = addColumn("HEAD",             DataType.TEXT,         80, DataMode.Nullable);
+            C_BUSINESS_UNIT   = addColumn("BUSINESS_UNIT",    DataType.TEXT,          4, DataMode.NotNull, "ITTK");
+            C_UPDATE_TIMESTAMP= addColumn("UPDATE_TIMESTAMP", DataType.DATETIME,      0, DataMode.NotNull);
+        
+            // Primary Key
+            setPrimaryKey(C_DEPARTMENT_ID);
+            // Set other Indexes
+            addIndex("DEARTMENT_NAME_IDX", true, new DBColumn[] { C_NAME });
+            // Set timestamp column for save updates
+            setTimestampColumn(C_UPDATE_TIMESTAMP);
+
+        }    
+    }   
+
+    /**
+     * This class represents the definition of the Employees table.
+     */
+    public static class Employees extends SampleTable
+    {
+		private static final long serialVersionUID = 2175667816137804685L;
+
+		public final DBTableColumn C_EMPLOYEE_ID;
+        public final DBTableColumn C_SALUTATION;
+        public final DBTableColumn C_FIRST_NAME;
+        public final DBTableColumn C_LAST_NAME;
+        public final DBTableColumn C_DATE_OF_BIRTH;
+        public final DBTableColumn C_DEPARTMENT_ID;
+        public final DBTableColumn C_GENDER;
+        public final DBTableColumn C_PHONE_NUMBER;
+        public final DBTableColumn C_EMAIL;
+        public final DBTableColumn C_RETIRED;
+        public final DBTableColumn C_UPDATE_TIMESTAMP;
+
+        public Employees(DBDatabase db)
+        {
+            super("EMPLOYEES", db);
+            // ID
+            C_EMPLOYEE_ID     = addColumn("EMPLOYEE_ID",      DataType.AUTOINC,      0, DataMode.NotNull, "EMPLOYEE_ID_SEQUENCE");
+            C_SALUTATION      = addColumn("SALUTATION",       DataType.TEXT,        5, DataMode.Nullable);
+            C_FIRST_NAME       = addColumn("FIRST_NAME",       DataType.TEXT,        40, DataMode.NotNull);
+            C_LAST_NAME        = addColumn("LAST_NAME",        DataType.TEXT,        40, DataMode.NotNull);
+            C_DATE_OF_BIRTH   = addColumn("DATE_OF_BIRTH",    DataType.DATE,         0, DataMode.Nullable);
+            C_DEPARTMENT_ID   = addColumn("DEPARTMENT_ID",    DataType.INTEGER,      0, DataMode.NotNull);
+            C_GENDER          = addColumn("GENDER",           DataType.TEXT,         1, DataMode.Nullable);
+            C_PHONE_NUMBER    = addColumn("PHONE",     		  DataType.TEXT,        40, DataMode.Nullable);
+            C_EMAIL           = addColumn("EMAIL",            DataType.TEXT,        80, DataMode.Nullable);
+            C_RETIRED         = addColumn("RETIRED",          DataType.BOOL,         0, DataMode.NotNull, false);
+            C_UPDATE_TIMESTAMP= addColumn("UPDATE_TIMESTAMP", DataType.DATETIME,     0, DataMode.NotNull);
+        
+            // Primary Key
+            setPrimaryKey(C_EMPLOYEE_ID);
+            // Set other Indexes
+            addIndex("PERSON_NAME_IDX", true, new DBColumn[] { C_FIRST_NAME, C_LAST_NAME, C_DATE_OF_BIRTH });
+            // Set timestamp column for save updates
+            setTimestampColumn(C_UPDATE_TIMESTAMP);
+            
+            // Create Options for GENDER column
+            Options genders = new Options();
+            genders.set("M", "option.employee.gender.male");
+            genders.set("F", "option.employee.gender.female");
+            C_GENDER.setOptions(genders);
+            C_GENDER.setControlType("select");
+            
+            // Set special control types
+            C_DEPARTMENT_ID.setControlType("select");
+            C_PHONE_NUMBER .setControlType("phone");
+            
+        }    
+    }   
+
+    // Declare all Tables
+    public final Departments  T_DEPARTMENTS = new Departments(this);
+    public final Employees    T_EMPLOYEES   = new Employees(this);
+    
+    /**
+     * Constructor SampleDB
+     */
+    public SampleDB()
+    {
+        // Define Foreign-Key Relations
+        addRelation( T_EMPLOYEES.C_DEPARTMENT_ID.referenceOn( T_DEPARTMENTS.C_DEPARTMENT_ID ));
+    }
+    
+}

Added: incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/SampleTable.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/SampleTable.java?rev=1195598&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/SampleTable.java (added)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/SampleTable.java Mon Oct 31 18:26:48 2011
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.websample.db;
+
+import org.apache.empire.data.DataType;
+import org.apache.empire.db.DBDatabase;
+import org.apache.empire.db.DBTable;
+import org.apache.empire.db.DBTableColumn;
+
+/**
+ * Base class definition for all database tables
+ * Automatically generates a message-key for the field title
+ * e.g. for the column EMPLOYEES.DATE_OF_BIRTH
+ * it generates the key "!field.title.employees.dateOfBirth";
+ */
+public class SampleTable extends DBTable
+{
+    private final static long serialVersionUID = 1L;
+    public final String MESSAGE_KEY_PREFIX = "!field.title.";
+    
+    public SampleTable(String name, DBDatabase db)
+    {
+        super(name, db);
+    }
+
+    @Override
+    protected void addColumn(DBTableColumn column)
+    {
+        // Set Translation Title
+        String col = column.getBeanPropertyName();  
+        String tbl = getName().toLowerCase();   
+        String key = MESSAGE_KEY_PREFIX + tbl + "." + col;
+        column.setTitle(key);
+
+        // Set Default Control Type
+        DataType type = column.getDataType();
+        column.setControlType((type==DataType.BOOL) ? "checkbox" : "text");
+
+        // Add Column
+        super.addColumn(column);
+    }
+}

Added: incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/DepartmentRecord.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/DepartmentRecord.java?rev=1195598&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/DepartmentRecord.java (added)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/DepartmentRecord.java Mon Oct 31 18:26:48 2011
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.websample.db.records;
+
+import org.apache.empire.db.DBRecord;
+import org.apache.empire.jsf2.websample.db.SampleDB;
+import org.apache.empire.jsf2.websample.web.FacesUtils;
+
+public class DepartmentRecord extends DBRecord
+{
+    private final static long serialVersionUID = 1L;
+  
+    public static final SampleDB.Departments T = FacesUtils.getDatabase().T_DEPARTMENTS;  
+}

Added: incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/EmployeeRecord.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/EmployeeRecord.java?rev=1195598&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/EmployeeRecord.java (added)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/EmployeeRecord.java Mon Oct 31 18:26:48 2011
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.websample.db.records;
+
+import org.apache.empire.commons.Options;
+import org.apache.empire.db.DBColumn;
+import org.apache.empire.db.DBCommand;
+import org.apache.empire.db.DBRecord;
+import org.apache.empire.jsf2.websample.db.SampleDB;
+import org.apache.empire.jsf2.websample.web.FacesUtils;
+
+
+public class EmployeeRecord extends DBRecord
+{
+    private final static long serialVersionUID = 1L;
+  
+    public static final SampleDB.Employees T = FacesUtils.getDatabase().T_EMPLOYEES;  
+ 
+    // Sample Implementation for Department Record
+    public DepartmentRecord getDepartmentRecord()
+    {
+        DepartmentRecord rec = new DepartmentRecord();
+        SampleDB.Departments table = FacesUtils.getDatabase().T_DEPARTMENTS;
+        try {
+			rec.read(table, this.getInt(T.C_DEPARTMENT_ID), FacesUtils.getConnection());
+		} catch (Exception e) {
+	        log.error("Unable to get department record. Message is " + e.getMessage());
+	        return null;
+		}
+        return rec; 
+    }
+    
+    @Override
+    public Options getFieldOptions(DBColumn column)
+    {
+        if (column.equals(T.C_DEPARTMENT_ID)) {
+            SampleDB db = (SampleDB)getDatabase();
+            DBCommand cmd = db.createCommand();
+            cmd.select(db.T_DEPARTMENTS.C_DEPARTMENT_ID);
+            cmd.select(db.T_DEPARTMENTS.C_NAME);
+            return db.queryOptionList(cmd.getSelect(), FacesUtils.getConnection());
+        }
+        // base class implementation
+        return super.getFieldOptions(column);
+    }
+    
+}

Added: incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/FacesUtils.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/FacesUtils.java?rev=1195598&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/FacesUtils.java (added)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/FacesUtils.java Mon Oct 31 18:26:48 2011
@@ -0,0 +1,259 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.websample.web;
+
+import java.sql.Connection;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import javax.el.ELContext;
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.empire.jsf2.websample.db.SampleDB;
+import org.apache.empire.jsf2.websample.web.pages.Page;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class FacesUtils
+{
+
+    private static final Logger log = LoggerFactory.getLogger(FacesUtils.class);
+
+    /**
+     * gets the Managed Bean of a given bean name
+     * 
+     * @param context
+     *            the faces context
+     * @param name
+     *            the name of the bean
+     * @return the managed bean instance or null if name was not found
+     */
+    public static Object getManagedBean(final FacesContext context, final String name)
+    {
+        if (context == null)
+        {
+            throw new NullPointerException("context must not be null");
+        }
+        if (name == null)
+        {
+            throw new NullPointerException("name must not be null");
+        }
+
+        final ELContext elcontext = context.getELContext();
+        final Application application = context.getApplication();
+
+        return application.getELResolver().getValue(elcontext, null, name);
+    }
+
+    public static Object getManagedBean(final String name)
+    {
+        if (FacesContext.getCurrentInstance() == null)
+        {
+            return null;
+        }
+        return FacesUtils.getManagedBean(FacesContext.getCurrentInstance(), name);
+    }
+
+    public static Object getManagedBean(Class<?> clazz)
+    {
+        return FacesUtils.getManagedBean(getManagedBeanName(clazz));
+    }
+
+    public static String getManagedBeanName(Class<?> clazz)
+    {
+    	String className = clazz.getSimpleName();
+    	className = className.substring(0,1).toLowerCase()+className.substring(1);
+    	return className;
+    }
+    
+    /**
+     * returns the request param value for a given param
+     * 
+     * @param context
+     *            the faces context
+     * @param param
+     *            the param name
+     * @return the param value
+     */
+    public static String getRequestParam(final FacesContext context, final String param)
+    {
+        return context.getExternalContext().getRequestParameterMap().get(param);
+    }
+
+    /**
+     * returns the request param value for a given param
+     * 
+     * @param param
+     *            the param name
+     * @return the param value
+     */
+    public static String getRequestParam(final String param)
+    {
+        return FacesUtils.getRequestParam(FacesContext.getCurrentInstance(), param);
+    }
+
+    /**
+     * Add information message.
+     * 
+     * @param msg
+     *            the information message
+     */
+    public static void addInfoMessage(String msg)
+    {
+        FacesUtils.addInfoMessage(null, msg);
+    }
+
+    /**
+     * Add information message to a specific client.
+     * 
+     * @param clientId
+     *            the client id
+     * @param msg
+     *            the information message
+     */
+    public static void addInfoMessage(String clientId, String msg)
+    {
+        FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg));
+    }
+
+    /**
+     * Add error message.
+     * 
+     * @param msg
+     *            the error message
+     */
+    public static void addErrorMessage(String msg)
+    {
+        FacesUtils.addErrorMessage(null, msg);
+    }
+
+    /**
+     * Add error message to a specific client.
+     * 
+     * @param clientId
+     *            the client id
+     * @param msg
+     *            the error message
+     */
+    public static void addErrorMessage(String clientId, String msg)
+    {
+        FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));
+    }
+
+    public static Application getFacesApplication()
+    {
+        ApplicationFactory appFactory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+        return appFactory.getApplication();
+    }
+
+    // public static String getResource(String key)
+    // {
+    // String resource;
+    // // TODO: remove debug try/catch
+    // try
+    // {
+    // // TODO resource = ResourceBundle.getBundle("lang.messages",
+    // FacesUtils.getUserBean().getLocale())
+    // .getString(key);
+    // }
+    // catch (MissingResourceException e)
+    // {
+    // resource = "Key '" + key + "' missing.";
+    // e.printStackTrace();
+    // }
+    // if (resource == null)
+    // {
+    // throw new RuntimeException("The resource '" + key + "' does not exist.");
+    // }
+    // return resource;
+    // }
+
+    public static SampleApplication getApplication()
+    {
+        return (SampleApplication) FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get("app");
+    }
+
+    public static SampleDB getDatabase()
+    {
+        return FacesUtils.getApplication().getDatabase();
+    }
+
+    public static HttpServletRequest getHttpRequest()
+    {
+        // Check
+        /*
+         * HttpServletRequest req =
+         * (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
+         * FWSRequest x1 =
+         * (FWSRequest)req.getAttribute(FWSRequest.REQUEST_ATTRIBUTE_NAME); FWSRequest x2 =
+         * FWSRequest.get();
+         * log.info("Comparing FWS-Requests: x1={} | x2={}", x1.getId(), x2.getId()); if
+         * (x1.getId()!=x2.getId()) {
+         * x1.checkDisposed(false); x2.checkDisposed(false); }
+         */
+        return SampleRequest.get().getHttpRequest();
+    }
+
+    public static Connection getConnection()
+    {
+        int reqId = SampleRequest.get() != null ? SampleRequest.get().getId() : 0;
+        FacesUtils.log.info("REQUEST {}: obtaining connection.", reqId);
+        return SampleRequest.get().getConnection();
+    }
+
+    static Connection getRequestConnection(ServletRequest request)
+    {
+        int requestId = (Integer) request.getAttribute("requestId");
+        FacesUtils.log.debug("REQUEST {}: obtaining connection.", requestId);
+        return (Connection) request.getAttribute("connection");
+    }
+
+    public static String getMessageForKey(String messageKey)
+    {
+		// if translation available, use it
+		try {
+			return ResourceBundle.getBundle("lang.messages").getString(messageKey);
+		} catch (MissingResourceException mre) {
+			log.warn("Couldn't find resource for '" + messageKey
+					+ "', using key directly instead.");
+		}
+        return "!!!"+ messageKey;
+    }
+
+    public static void setPage(String page)
+    {
+        ((SampleSession) FacesUtils.getManagedBean("sampleSession")).setPage(page);
+    }
+
+    public static Page getPage()
+    {
+        return (Page) FacesUtils.getManagedBean(((SampleSession) FacesUtils.getManagedBean("sampleSession")).getPage());
+    }
+
+    public static SampleSession getSampleSession()
+    {
+        return (SampleSession) FacesUtils.getManagedBean("sampleSession");
+    }
+}

Added: incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/PageELResolver.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/PageELResolver.java?rev=1195598&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/PageELResolver.java (added)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/PageELResolver.java Mon Oct 31 18:26:48 2011
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.websample.web;
+
+import java.beans.FeatureDescriptor;
+import java.util.Iterator;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+
+public class PageELResolver extends ELResolver
+{
+
+    @Override
+    public Class<?> getCommonPropertyType(ELContext context, Object base)
+    {
+        return null;
+    }
+
+    @Override
+    public Class<?> getType(ELContext context, Object base, Object property)
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext arg0, Object arg1)
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Object getValue(ELContext context, Object base, Object property)
+    {
+        if (property.equals("page"))
+        {
+            context.setPropertyResolved(true);
+            return FacesUtils.getPage();
+        }
+        return null;
+    }
+
+    @Override
+    public boolean isReadOnly(ELContext context, Object base, Object property)
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public void setValue(ELContext context, Object base, Object property, Object value)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+}

Added: incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplication.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplication.java?rev=1195598&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplication.java (added)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplication.java Mon Oct 31 18:26:48 2011
@@ -0,0 +1,257 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.websample.web;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+
+import javax.faces.bean.ApplicationScoped;
+import javax.faces.bean.ManagedBean;
+import javax.servlet.ServletContext;
+
+import org.apache.empire.commons.StringUtils;
+import org.apache.empire.db.DBCommand;
+import org.apache.empire.db.DBDatabaseDriver;
+import org.apache.empire.db.DBRecord;
+import org.apache.empire.db.DBSQLScript;
+import org.apache.empire.db.exceptions.QueryFailedException;
+import org.apache.empire.db.hsql.DBDatabaseDriverHSql;
+import org.apache.empire.db.mysql.DBDatabaseDriverMySQL;
+import org.apache.empire.db.oracle.DBDatabaseDriverOracle;
+import org.apache.empire.db.sqlserver.DBDatabaseDriverMSSQL;
+import org.apache.empire.jsf2.websample.db.SampleDB;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@ManagedBean(name = "application")
+@ApplicationScoped
+public class SampleApplication {
+	// Logger
+	private static final Logger log = LoggerFactory
+			.getLogger(SampleApplication.class);
+
+	// Non-Static
+	private SampleDB db = new SampleDB();
+	private SampleConfig config = new SampleConfig();
+
+	private Connection conn = null;
+
+	public void init(ServletContext servletContext) {
+		try {
+			// register all controls
+			// InputControlManager.registerControl("myType", new
+			// MyTypeInputControl());
+			config.init(servletContext.getRealPath("WEB-INF/config.xml"));
+
+			// Set Database to Servlet Context
+			servletContext.setAttribute("db", db);
+
+			// Get a JDBC Connection
+			log.info("*** getJDBCConnection() ***");
+			conn = getJDBCConnection(servletContext);
+
+			// Choose a driver
+			log.info("*** create DBDatabaseDriverOracle() ***");
+			DBDatabaseDriver driver = getDatabaseDriver(config
+					.getDatabaseProvider());
+
+			// Open Database (and create if not existing)
+			log.info("*** open database ***");
+			db.open(driver, conn);
+			if (!databaseExists(conn)) {
+				// STEP 4: Create Database
+				log.info("*** create Database ***");
+				createSampleDatabase(driver, conn);
+			}
+
+			// Done
+			log.info("Application initialized ");
+
+		} catch (Exception e) {
+			// Error
+			log.info(e.toString());
+			e.printStackTrace();
+		}
+
+	}
+
+	public SampleDB getDatabase() {
+		return db;
+	}
+
+	public Connection getPooledConnection() {
+		return conn;
+	}
+
+	/**
+	 * releases a connection from the connection pool
+	 */
+	public void releaseConnection(Connection conn, boolean commit) {
+		// Return Connection to Connection Pool
+	}
+
+	/*
+	 * getJDBCConnection
+	 */
+	private Connection getJDBCConnection(ServletContext appContext) {
+		// Establish a new database connection
+		Connection conn = null;
+		String jdbcURL = config.getJdbcURL();
+		if (jdbcURL.indexOf("file:") > 0)
+			jdbcURL = StringUtils.replace(jdbcURL, "file:", "file:"
+					+ appContext.getRealPath("/"));
+		// Connect
+		log.info("Connecting to Database'" + jdbcURL + "' / User="
+				+ config.getJdbcUser());
+		try { // Connect to the databse
+			Class.forName(config.getJdbcClass()).newInstance();
+			conn = DriverManager.getConnection(jdbcURL, config.getJdbcUser(),
+					config.getJdbcPwd());
+			log.info("Connected successfully");
+			// set the AutoCommit to false this session. You must commit
+			// explicitly now
+			conn.setAutoCommit(false);
+			log.info("AutoCommit is " + conn.getAutoCommit());
+
+		} catch (Exception e) {
+			log.error("Failed to connect directly to '" + config.getJdbcURL()
+					+ "' / User=" + config.getJdbcUser());
+			log.error(e.toString());
+			throw new RuntimeException(e);
+		}
+		return conn;
+	}
+
+	/*
+	 * getDatabaseDriver
+	 */
+	private DBDatabaseDriver getDatabaseDriver(String provider) {
+		if (provider.equalsIgnoreCase("mysql")) {
+			DBDatabaseDriverMySQL driver = new DBDatabaseDriverMySQL();
+			// Set Driver specific properties (if any)
+			driver.setDatabaseName(config.getSchemaName());
+			return driver;
+		} else if (provider.equalsIgnoreCase("oracle")) {
+			DBDatabaseDriverOracle driver = new DBDatabaseDriverOracle();
+			// Set Driver specific properties (if any)
+			return driver;
+		} else if (provider.equalsIgnoreCase("sqlserver")) {
+			DBDatabaseDriverMSSQL driver = new DBDatabaseDriverMSSQL();
+			// Set Driver specific properties (if any)
+			driver.setDatabaseName(config.getSchemaName());
+			return driver;
+		} else if (provider.equalsIgnoreCase("hsqldb")) {
+			DBDatabaseDriverHSql driver = new DBDatabaseDriverHSql();
+			// Set Driver specific properties (if any)
+			return driver;
+		} else { // Unknown Provider
+			throw new RuntimeException("Unknown Database Provider " + provider);
+		}
+	}
+
+	private boolean databaseExists(Connection conn) {
+		// Check wether DB exists
+		DBCommand cmd = db.createCommand();
+		cmd.select(db.T_DEPARTMENTS.count());
+		try {
+			return (db.querySingleInt(cmd.getSelect(), -1, conn) >= 0);
+		} catch (QueryFailedException e) {
+			return false;
+		}
+	}
+
+	/*
+	 * creates a DDL Script for the entire SampleDB Database then checks if the
+	 * department table exists by running "select count(*) from DEPARTMENTS" if
+	 * the department tables does not exist, the entire dll-script is executed
+	 * line by line
+	 */
+	private void createSampleDatabase(DBDatabaseDriver driver, Connection conn) {
+		// create DLL for Database Definition
+		DBSQLScript script = new DBSQLScript();
+		db.getCreateDDLScript(driver, script);
+		// Show DLL Statements
+		System.out.println(script.toString());
+		// Execute Script
+		script.run(driver, conn, false);
+		db.commit(conn);
+		// Open again
+		if (!db.isOpen()) {
+			db.open(driver, conn);
+		}
+		// Insert Sample Departments
+		int idDevDep = insertDepartmentSampleRecord(conn, "Development", "ITTK");
+		int idSalDep = insertDepartmentSampleRecord(conn, "Sales", "ITTK");
+		// Insert Sample Employees
+		insertEmployeeSampleRecord(conn, "Mr.", "Eugen", "Miller", "M",
+				idDevDep);
+		insertEmployeeSampleRecord(conn, "Mr.", "Max", "Mc. Callahan", "M",
+				idDevDep);
+		insertEmployeeSampleRecord(conn, "Mrs.", "Anna", "Smith", "F", idSalDep);
+		// Commit
+		db.commit(conn);
+	}
+
+	/*
+	 * Insert a department
+	 */
+	private int insertDepartmentSampleRecord(Connection conn,
+			String department_name, String businessUnit) {
+		// Insert a Department
+		DBRecord rec = new DBRecord();
+		rec.create(db.T_DEPARTMENTS);
+		rec.setValue(db.T_DEPARTMENTS.C_NAME, department_name);
+		rec.setValue(db.T_DEPARTMENTS.C_BUSINESS_UNIT, businessUnit);
+		try {
+			rec.update(conn);
+		} catch (Exception e) {
+			log.error(e.getLocalizedMessage());
+			return 0;
+		}
+		// Return Department ID
+		return rec.getInt(db.T_DEPARTMENTS.C_DEPARTMENT_ID);
+	}
+
+	/*
+	 * Insert a person
+	 */
+	private int insertEmployeeSampleRecord(Connection conn, String salutation,
+			String firstName, String lastName, String gender, int depID) {
+		// Insert an Employee
+		DBRecord rec = new DBRecord();
+		rec.create(db.T_EMPLOYEES);
+		rec.setValue(db.T_EMPLOYEES.C_SALUTATION, salutation);
+		rec.setValue(db.T_EMPLOYEES.C_FIRST_NAME, firstName);
+		rec.setValue(db.T_EMPLOYEES.C_LAST_NAME, lastName);
+		rec.setValue(db.T_EMPLOYEES.C_GENDER, gender);
+		rec.setValue(db.T_EMPLOYEES.C_DEPARTMENT_ID, depID);
+		try
+		{
+			rec.update(conn);
+		}
+		catch(Exception e)
+		{
+			log.error(e.getLocalizedMessage());
+			return 0;
+		}
+		// Return Employee ID
+		return rec.getInt(db.T_EMPLOYEES.C_EMPLOYEE_ID);
+	}
+
+}

Added: incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleConfig.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleConfig.java?rev=1195598&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleConfig.java (added)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleConfig.java Mon Oct 31 18:26:48 2011
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.websample.web;
+
+import org.apache.empire.xml.XMLConfiguration;
+import org.apache.empire.xml.XMLUtil;
+import org.apache.log4j.xml.DOMConfigurator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Element;
+
+public class SampleConfig extends XMLConfiguration {
+	// Logger
+	private static final Logger log = LoggerFactory
+			.getLogger(SampleConfig.class);
+    private String loggingNodeName = "log4j:configuration";
+
+	private String databaseProvider = "oracle";
+
+	private String jdbcClass = "oracle.jdbc.driver.OracleDriver";
+
+	private String jdbcURL = "jdbc:oracle:thin:@192.168.0.2:1521:ora10";
+
+	private String jdbcUser = "DBSAMPLE";
+
+	private String jdbcPwd = "DBSAMPLE";
+
+	private String schemaName = "DBSAMPLE";
+
+	/**
+	 * Initialize the configuration
+	 * 
+	 * @param filename the file to read 
+	 * 
+	 * @return true on success 
+	 */
+	public boolean init(String filename) {
+		try
+		{
+			// Read the properties file
+			super.init(filename, false);
+			// Done			
+			readProperties(this, "properties");
+			if (initLogging() == false)
+				return false;
+			readProperties(this, "properties-" + databaseProvider);
+		}
+		catch(Exception e)
+		{
+			log.error(e.getLocalizedMessage());
+			return false;
+		}
+		return true;
+	}
+
+	public String getDatabaseProvider() {
+		return databaseProvider;
+	}
+
+	public String getJdbcClass() {
+		return jdbcClass;
+	}
+
+	public void setJdbcClass(String jdbcClass) {
+		this.jdbcClass = jdbcClass;
+	}
+
+	public String getJdbcPwd() {
+		return jdbcPwd;
+	}
+
+	public void setJdbcPwd(String jdbcPwd) {
+		this.jdbcPwd = jdbcPwd;
+	}
+
+	public String getJdbcURL() {
+		return jdbcURL;
+	}
+
+	public String getSchemaName() {
+		return schemaName;
+	}
+
+	// ------- Setters -------
+
+	public void setDatabaseProvider(String databaseProvider) {
+		this.databaseProvider = databaseProvider;
+	}
+	
+	public void setJdbcURL(String jdbcURL) {
+		this.jdbcURL = jdbcURL;
+	}
+
+	public String getJdbcUser() {
+		return jdbcUser;
+	}
+
+	public void setJdbcUser(String jdbcUser) {
+		this.jdbcUser = jdbcUser;
+	}
+
+	public void setSchemaName(String schemaName) {
+		this.schemaName = schemaName;
+	}
+
+    /**
+     * Init logging using Log4J's DOMConfigurator
+     * 
+     * @return
+     */
+    private boolean initLogging()
+    {
+        // Get configuration root node
+        Element rootNode = getRootNode();
+        if (rootNode == null)
+        {
+            return false;
+        }
+        // Find log configuration node
+        Element loggingNode = XMLUtil.findFirstChild(rootNode, loggingNodeName);
+        if (loggingNode == null)
+        { // log configuration node not found
+            SampleConfig.log.error("Log configuration node {} has not been found. Logging has not been configured.",
+            		loggingNodeName);
+            return false;
+        }
+        // Init Log4J
+        DOMConfigurator.configure(loggingNode);
+        // done
+        SampleConfig.log.info("Logging sucessfully configured from node {}.", loggingNodeName);
+        return true;
+    }
+
+
+}

Added: incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleContext.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleContext.java?rev=1195598&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleContext.java (added)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleContext.java Mon Oct 31 18:26:48 2011
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.websample.web;
+
+import java.sql.Connection;
+
+import org.apache.empire.jsf2.websample.db.SampleDB;
+
+
+public interface SampleContext
+{
+    public SampleDB getDatabase();
+    
+    public SampleUser getUser();
+    
+    public Connection getConnection();
+
+}

Added: incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleEventListener.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleEventListener.java?rev=1195598&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleEventListener.java (added)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleEventListener.java Mon Oct 31 18:26:48 2011
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.websample.web;
+
+import java.sql.Connection;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletRequestEvent;
+import javax.servlet.ServletRequestListener;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SampleEventListener implements ServletContextListener, ServletRequestListener
+{
+    private static final Logger log = LoggerFactory.getLogger(SampleEventListener.class);
+
+    public SampleEventListener()
+    {
+        SampleEventListener.log.debug("EventListener created");
+    }
+
+    // *********************************************
+    // *** ServletContextListener implementation ***
+    // *********************************************
+    public void contextInitialized(ServletContextEvent contextEvent)
+    {
+        SampleEventListener.log.info("EventListener: Application startup");
+
+        // Get Context
+        ServletContext ctx = contextEvent.getServletContext();
+
+        // Create Application
+        SampleApplication app = new SampleApplication();
+        app.init(ctx);
+
+        ctx.setAttribute("app", app);
+        // done
+        SampleEventListener.log.info("Application startup done");
+    }
+
+    public void contextDestroyed(ServletContextEvent contextEvent)
+    {
+        SampleEventListener.log.info("EventListener: Application shutdown");
+    }
+
+    // *********************************************
+    // *** ServletRequestListener implementation ***
+    // *********************************************
+    private static int requestIdSeq = 5000;
+
+    private boolean isException(ServletRequest request)
+    {
+        // THIS IS PART OF SPECIFICATION
+        return request.getAttribute("javax.servlet.error.exception") != null;
+    }
+
+    public void requestInitialized(ServletRequestEvent sre)
+    {
+        int requestId = SampleEventListener.requestIdSeq++;
+        ServletRequest request = sre.getServletRequest();
+        request.setAttribute("requestId", requestId);
+        if (SampleEventListener.log.isDebugEnabled())
+        {
+            SampleEventListener.log.debug("Starting faces request {}.", requestId);
+        }
+    }
+
+    public void requestDestroyed(ServletRequestEvent sre)
+    {
+        ServletRequest request = sre.getServletRequest();
+        int requestId = (Integer) request.getAttribute("requestId");
+
+        if (SampleEventListener.log.isDebugEnabled())
+        {
+            SampleEventListener.log.debug("Destroying faces request {}.", requestId);
+        }
+
+        // Release connection (if any)
+        Connection conn = FacesUtils.getRequestConnection(request);
+        if (conn != null)
+        {
+            ServletContext ctx = sre.getServletContext();
+            boolean commit = !isException(request);
+            // Release
+            SampleApplication app = (SampleApplication) ctx.getAttribute("app");
+            app.releaseConnection(conn, commit);
+        }
+    }
+
+}

Added: incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleExceptionHandler.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleExceptionHandler.java?rev=1195598&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleExceptionHandler.java (added)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleExceptionHandler.java Mon Oct 31 18:26:48 2011
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.websample.web;
+
+import java.util.Iterator;
+
+import javax.faces.FacesException;
+import javax.faces.context.ExceptionHandler;
+import javax.faces.context.ExceptionHandlerWrapper;
+import javax.faces.context.FacesContext;
+import javax.faces.event.ExceptionQueuedEvent;
+import javax.faces.event.ExceptionQueuedEventContext;
+import javax.servlet.http.HttpServletResponse;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SampleExceptionHandler extends ExceptionHandlerWrapper
+{
+
+    private ExceptionHandler    wrapped;
+
+    private static final Logger log = LoggerFactory.getLogger(SampleExceptionHandler.class);
+
+    public SampleExceptionHandler(ExceptionHandler wrapped)
+    {
+        this.wrapped = wrapped;
+    }
+
+    @Override
+    public ExceptionHandler getWrapped()
+    {
+        return this.wrapped;
+    }
+
+    @Override
+    public void handle()
+    throws FacesException
+    {
+        boolean redirectToErrorPage = false;
+        Iterator<ExceptionQueuedEvent> events = getUnhandledExceptionQueuedEvents().iterator();
+        Throwable rootCause = null;
+
+        // log each error
+        while (events.hasNext())
+        {
+            ExceptionQueuedEvent event = events.next();
+            ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
+            Throwable t = context.getException();
+            redirectToErrorPage = true;
+            log.error("SampleExceptionHandler caught exception.", t);
+            rootCause = getRootCause(t);
+            events.remove();
+        }
+
+        // if an error has been found
+        /*
+        if (redirectToErrorPage)
+        {
+            HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
+            try
+            {
+                if (rootCause != null)
+                {
+                    FacesUtils.getSampleSession().setError(rootCause);
+                }
+                response.sendRedirect("error.iface");
+            }
+            catch (Exception e)
+            {
+                SampleExceptionHandler.log.error("SampleExceptionHandler produced exception.", e);
+                throw new FacesException(e);
+            }
+        }
+        */
+
+        // let next handler deal
+        // getWrapped().handle();
+    }
+}

Added: incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleExceptionHandlerFactory.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleExceptionHandlerFactory.java?rev=1195598&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleExceptionHandlerFactory.java (added)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleExceptionHandlerFactory.java Mon Oct 31 18:26:48 2011
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.websample.web;
+
+import javax.faces.context.ExceptionHandler;
+import javax.faces.context.ExceptionHandlerFactory;
+
+public class SampleExceptionHandlerFactory extends ExceptionHandlerFactory
+{
+
+    private ExceptionHandlerFactory delegateFactory;
+
+    public SampleExceptionHandlerFactory(ExceptionHandlerFactory delegateFactory)
+    {
+        this.delegateFactory = delegateFactory;
+    }
+
+    @Override
+    public ExceptionHandler getExceptionHandler()
+    {
+        return new SampleExceptionHandler(this.delegateFactory.getExceptionHandler());
+    }
+
+}

Added: incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleNavigationHandler.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleNavigationHandler.java?rev=1195598&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleNavigationHandler.java (added)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleNavigationHandler.java Mon Oct 31 18:26:48 2011
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.websample.web;
+
+import javax.faces.context.FacesContext;
+
+import org.apache.empire.commons.StringUtils;
+
+import com.sun.faces.application.NavigationHandlerImpl;
+
+public class SampleNavigationHandler extends NavigationHandlerImpl {
+
+    @Override
+    public void handleNavigation(FacesContext context, String fromAction,
+                                 String outcome) {
+        if (!StringUtils.isEmpty(outcome)) {
+            String logicalOutcome = outcome;
+            // FIXME this is ugly
+            if (logicalOutcome.endsWith("WithPreview")) {
+                logicalOutcome = logicalOutcome.replace("WithPreview", "");
+            }
+            FacesUtils.setPage(logicalOutcome);
+        }
+        super.handleNavigation(context, fromAction, outcome);
+    }
+
+}



Mime
View raw message