empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1351458 [1/2] - in /empire-db/trunk/empire-db-examples/empire-db-example-jsf2: ./ src/main/java/ src/main/java/org/apache/empire/jsf2/custom/ src/main/java/org/apache/empire/jsf2/custom/controls/ src/main/java/org/apache/empire/jsf2/websam...
Date Mon, 18 Jun 2012 18:52:38 GMT
Author: doebele
Date: Mon Jun 18 18:52:35 2012
New Revision: 1351458

URL: http://svn.apache.org/viewvc?rev=1351458&view=rev
Log:
EMPIREDB-140
jsf-example v2

Added:
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/custom/
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/custom/controls/
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/custom/controls/FileInputControl.java   (with props)
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/SampleRecord.java   (with props)
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/AutheticationPhaseListener.java   (with props)
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplicationFactory.java   (with props)
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleUtils.java   (with props)
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/objects/EmployeeSearchFilter.java   (with props)
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/SamplePage.java   (with props)
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/SamplePages.java   (with props)
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/META-INF/
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/META-INF/context.xml   (with props)
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/css/common.css   (with props)
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/css/content.css   (with props)
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/css/layout.css   (with props)
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/resources/components/column.xhtml   (with props)
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/resources/empire/
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/resources/empire/control.xhtml   (with props)
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/resources/empire/input.xhtml   (with props)
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/resources/empire/label.xhtml   (with props)
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/resources/empire/link.xhtml   (with props)
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/resources/empire/record.xhtml   (with props)
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/resources/empire/title.xhtml   (with props)
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/resources/empire/value.xhtml   (with props)
Removed:
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/ValidationMessages_de.properties
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/ValidationMessages_en.properties
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/FacesUtils.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleContext.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleEventListener.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleNavigationHandler.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SamplePhaseListener.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleRequest.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleRequestFilter.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/objects/EmployeeSearch.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/EmployeeSearchPage.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/Page.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/css/sample.css
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/pages/employeeSearchPage.xhtml
Modified:
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/pom.xml
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/SampleDB.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/SampleTable.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/DepartmentRecord.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/EmployeeRecord.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplication.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleConfig.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleSession.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleUser.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/objects/User.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/EmployeeDetailPage.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/EmployeeListPage.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/ErrorPage.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/LoginPage.java
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/resources/lang/messages_de.properties
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/resources/lang/messages_en.properties
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/config.xml
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/facelets/templates/layout.xhtml
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/faces-config.xml
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/web.xml
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/index.html
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/pages/employeeDetailPage.xhtml
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/pages/employeeListPage.xhtml
    empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/webapp/pages/loginPage.xhtml

Modified: empire-db/trunk/empire-db-examples/empire-db-example-jsf2/pom.xml
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/pom.xml?rev=1351458&r1=1351457&r2=1351458&view=diff
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-jsf2/pom.xml (original)
+++ empire-db/trunk/empire-db-examples/empire-db-example-jsf2/pom.xml Mon Jun 18 18:52:35 2012
@@ -15,40 +15,40 @@
 		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>
+		<groupId>org.apache.empire-db</groupId>
 		<version>2.3.1-SNAPSHOT</version>
 	</parent>
+	<modelVersion>4.0.0</modelVersion>
 	<groupId>org.apache.empire-db</groupId>
 	<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>
+	<description>Examples showing the use of empire-db-jsf.</description>
+
 	<dependencies>
+
 		<dependency>
 			<groupId>org.apache.empire-db</groupId>
 			<artifactId>empire-db</artifactId>
 		</dependency>
+
+		<!-- java server faces -->
 		<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>
+			<groupId>com.sun.faces</groupId>
+			<artifactId>jsf-api</artifactId>
 		</dependency>
 		<dependency>
-			<groupId>hsqldb</groupId>
-			<artifactId>hsqldb</artifactId>
+			<groupId>com.sun.faces</groupId>
+			<artifactId>jsf-impl</artifactId>
 		</dependency>
 		<dependency>
-			<groupId>javax.portlet</groupId>
-			<artifactId>portlet-api</artifactId>
-			<scope>runtime</scope>
+			<groupId>org.apache.empire-db</groupId>
+			<artifactId>empire-db-jsf2</artifactId>
 		</dependency>
 
 		<!-- myfaces -->
@@ -59,33 +59,31 @@
 			<type>jar</type>
 			<scope>provided</scope>
 		</dependency>
+
+        <!-- use log4j for logging -->
 		<dependency>
-			<groupId>org.apache.myfaces.core</groupId>
-			<artifactId>myfaces-api</artifactId>
-			<version>2.0.4</version>
-			<scope>compile</scope>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-log4j12</artifactId>
 		</dependency>
+
 		<dependency>
-			<groupId>org.apache.myfaces.core</groupId>
-			<artifactId>myfaces-impl</artifactId>
-			<version>2.0.4</version>
-			<scope>compile</scope>
+			<groupId>hsqldb</groupId>
+			<artifactId>hsqldb</artifactId>
 		</dependency>
+
 	</dependencies>
+	
 	<build>
 		<plugins>
-			<!-- WTP-Eclipse-Projekt -->
+			<!-- WTP-Eclipse-Projekt --> 
 			<plugin>
 				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-eclipse-plugin</artifactId>
+				<artifactId>maven-eclipse-plugin</artifactId> 
 				<configuration>
-					<m2eclipse>true</m2eclipse>
+					<m2eclipse>true</m2eclipse> 
 					<downloadSources>true</downloadSources>
-					<wtpversion>2.0</wtpversion>
-					<additionalProjectFacets>
-						<jst.jsf>2.0</jst.jsf>
-					</additionalProjectFacets>
-				</configuration>
+					<wtpversion>1.5</wtpversion> 
+				</configuration> 
 			</plugin>
 			<!-- Sysdeo Tomcat Eclipse -->
 			<plugin>
@@ -96,23 +94,8 @@
 					<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
+	
+</project>
+

Added: empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/custom/controls/FileInputControl.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/custom/controls/FileInputControl.java?rev=1351458&view=auto
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/custom/controls/FileInputControl.java (added)
+++ empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/custom/controls/FileInputControl.java Mon Jun 18 18:52:35 2012
@@ -0,0 +1,156 @@
+/*
+ * 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.custom.controls;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.html.HtmlInputText;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.convert.ConverterException;
+
+import org.apache.empire.exceptions.InternalException;
+import org.apache.empire.jsf2.controls.InputControl;
+
+import com.sun.faces.renderkit.Attribute;
+import com.sun.faces.renderkit.AttributeManager;
+import com.sun.faces.renderkit.RenderKitUtils;
+import com.sun.faces.renderkit.html_basic.TextRenderer;
+
+public class FileInputControl extends InputControl
+{
+    public static final String             NAME                = "blob";
+
+    private Class<? extends HtmlInputFile> inputComponentClass = null;
+
+    public FileInputControl(Class<? extends HtmlInputFile> inputComponentClass)
+    {
+        super(NAME);
+        this.inputComponentClass = inputComponentClass;
+    }
+
+    public FileInputControl()
+    {
+        this(HtmlInputFile.class);
+    }
+
+    @Override
+    protected void createInputComponents(UIComponent parent, InputInfo ii, FacesContext context, List<UIComponent> compList)
+    {
+        HtmlInputFile input;
+        try
+        {
+            input = inputComponentClass.newInstance();
+        }
+        catch (InstantiationException e1)
+        {
+            throw new InternalException(e1);
+        }
+        catch (IllegalAccessException e2)
+        {
+            throw new InternalException(e2);
+        }
+
+        copyAttributes(parent, ii, input);
+        setInputValue(input, ii);
+        input.setDisabled(ii.isDisabled());
+        
+        compList.add(input);
+    }
+
+    public class HtmlInputFile extends HtmlInputText
+    {
+
+        public static final String COMPONENT_TYPE = "HtmlFileInput";
+        public static final String RENDER_TYPE    = "org.apache.empire.jsf2.custom.controls.FileInputRenderer";
+
+        @Override
+        public String getRendererType()
+        {
+            return RENDER_TYPE;
+        }
+
+    }
+
+    public class FileInputRenderer extends TextRenderer
+    {
+
+        // Constants ----------------------------------------------------------------------------------
+
+        private static final String EMPTY_STRING     = "";
+        private final Attribute[]   INPUT_ATTRIBUTES = AttributeManager.getAttributes(AttributeManager.Key.INPUTTEXT);
+
+        // Actions ------------------------------------------------------------------------------------
+
+        @Override
+        protected void getEndTextToRender(FacesContext context, UIComponent component, String currentValue)
+            throws IOException
+        {
+            ResponseWriter writer = context.getResponseWriter();
+            writer.startElement("input", component);
+            writeIdAttributeIfNecessary(context, writer, component);
+            writer.writeAttribute("type", "file", null);
+            writer.writeAttribute("name", (component.getClientId(context)), "clientId");
+
+            // Render styleClass, if any.
+            String styleClass = (String) component.getAttributes().get("styleClass");
+            if (styleClass != null)
+            {
+                writer.writeAttribute("class", styleClass, "styleClass");
+            }
+
+            // Render standard HTMLattributes expect of styleClass.
+            RenderKitUtils.renderPassThruAttributes(context, writer, component, INPUT_ATTRIBUTES, getNonOnChangeBehaviors(component));
+            RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer, component);
+            RenderKitUtils.renderOnchange(context, component, false);
+
+            writer.endElement("input");
+        }
+
+        @Override
+        public void decode(FacesContext context, UIComponent component)
+        {
+            rendererParamsNotNull(context, component);
+            if (!shouldDecode(component))
+            {
+                return;
+            }
+            String clientId = decodeBehaviors(context, component);
+            if (clientId == null)
+            {
+                clientId = component.getClientId(context);
+            }
+
+            //            File file = ((MultipartRequest) context.getExternalContext().getRequest()).getFile(clientId);
+            // If no file is specified, set empty String to trigger validators.
+            //            ((UIInput) component).setSubmittedValue((file != null) ? file : EMPTY_STRING);
+        }
+
+        @Override
+        public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue)
+            throws ConverterException
+        {
+            return (submittedValue != EMPTY_STRING) ? submittedValue : null;
+        }
+
+    }
+
+}

Propchange: empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/custom/controls/FileInputControl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 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/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/SampleDB.java?rev=1351458&r1=1351457&r2=1351458&view=diff
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/SampleDB.java (original)
+++ empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/SampleDB.java Mon Jun 18 18:52:35 2012
@@ -25,111 +25,129 @@ 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;
-  
+    private final static long       serialVersionUID = 1L;
+
+    // Declare all Tables
+    public final TDepartments       T_DEPARTMENTS    = new TDepartments(this);
+    public final TEmployees         T_EMPLOYEES      = new TEmployees(this);
+
+    /**
+     * Constructor SampleDB
+     */
+    public SampleDB()
+    {
+        // Define Foreign-Key Relations
+        addRelation(T_EMPLOYEES.DEPARTMENT_ID.referenceOn(T_DEPARTMENTS.DEPARTMENT_ID));
+    }
+
+    // Needed for the DBELResolver
+    @Override
+    protected void register(String id)
+    {
+        super.register("db");
+    }
+
     /**
      * This class represents the definition of the Departments table.
      */
-    public static class Departments extends SampleTable
+    public static class TDepartments extends SampleTable
     {
-		private static final long serialVersionUID = -2993431379391158533L;
+        private static final long  serialVersionUID = 1L;
 
-		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 final DBTableColumn DEPARTMENT_ID;
+        public final DBTableColumn NAME;
+        public final DBTableColumn HEAD;
+        public final DBTableColumn BUSINESS_UNIT;
+        public final DBTableColumn UPDATE_TIMESTAMP;
 
-        public Departments(DBDatabase db)
+        public TDepartments(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);
-        
+            DEPARTMENT_ID = addColumn("DEPARTMENT_ID", DataType.AUTOINC, 0, DataMode.NotNull, "DEP_ID_SEQUENCE");
+            NAME = addColumn("NAME", DataType.TEXT, 80, DataMode.NotNull);
+            HEAD = addColumn("HEAD", DataType.TEXT, 80, DataMode.Nullable);
+            BUSINESS_UNIT = addColumn("BUSINESS_UNIT", DataType.TEXT, 4, DataMode.NotNull, "ITTK");
+            UPDATE_TIMESTAMP = addColumn("UPDATE_TIMESTAMP", DataType.DATETIME, 0, DataMode.NotNull);
+
             // Primary Key
-            setPrimaryKey(C_DEPARTMENT_ID);
+            setPrimaryKey(DEPARTMENT_ID);
             // Set other Indexes
-            addIndex("DEARTMENT_NAME_IDX", true, new DBColumn[] { C_NAME });
+            addIndex("DEARTMENT_NAME_IDX", true, new DBColumn[] { NAME });
             // Set timestamp column for save updates
-            setTimestampColumn(C_UPDATE_TIMESTAMP);
+            setTimestampColumn(UPDATE_TIMESTAMP);
 
-        }    
-    }   
+        }
+    }
+
+  
 
     /**
      * This class represents the definition of the Employees table.
      */
-    public static class Employees extends SampleTable
+    public static class TEmployees 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;
+        private static final long  serialVersionUID = 1L;
 
-        public Employees(DBDatabase db)
+        public final DBTableColumn EMPLOYEE_ID;
+        public final DBTableColumn SALUTATION;
+//        public final DBTableColumn PICTURE;
+        public final DBTableColumn FIRST_NAME;
+        public final DBTableColumn LAST_NAME;
+        public final DBTableColumn DATE_OF_BIRTH;
+        public final DBTableColumn DEPARTMENT_ID;
+        public final DBTableColumn GENDER;
+        public final DBTableColumn PHONE_NUMBER;
+        public final DBTableColumn EMAIL;
+        public final DBTableColumn RETIRED;
+        public final DBTableColumn UPDATE_TIMESTAMP;
+        public TEmployees(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);
-        
+            EMPLOYEE_ID = addColumn("EMPLOYEE_ID", DataType.AUTOINC, 0, DataMode.NotNull, "EMPLOYEE_ID_SEQUENCE");
+            SALUTATION = addColumn("SALUTATION", DataType.TEXT, 5, DataMode.Nullable);
+//            PICTURE = addColumn("PICTURE", DataType.BLOB, 0, DataMode.Nullable);
+            FIRST_NAME = addColumn("FIRST_NAME", DataType.TEXT, 40, DataMode.NotNull);
+            LAST_NAME = addColumn("LAST_NAME", DataType.TEXT, 40, DataMode.NotNull);
+            DATE_OF_BIRTH = addColumn("DATE_OF_BIRTH", DataType.DATE, 0, DataMode.Nullable);
+            DEPARTMENT_ID = addColumn("DEPARTMENT_ID", DataType.INTEGER, 0, DataMode.NotNull);
+            GENDER = addColumn("GENDER", DataType.TEXT, 1, DataMode.Nullable);
+            PHONE_NUMBER = addColumn("PHONE_NUMBER", DataType.TEXT, 40, DataMode.Nullable);
+            EMAIL = addColumn("EMAIL", DataType.TEXT, 80, DataMode.Nullable);
+            RETIRED = addColumn("RETIRED", DataType.BOOL, 0, DataMode.NotNull, false);
+            UPDATE_TIMESTAMP = addColumn("UPDATE_TIMESTAMP", DataType.DATETIME, 0, DataMode.NotNull);
+
             // Primary Key
-            setPrimaryKey(C_EMPLOYEE_ID);
+            setPrimaryKey(EMPLOYEE_ID);
             // Set other Indexes
-            addIndex("PERSON_NAME_IDX", true, new DBColumn[] { C_FIRST_NAME, C_LAST_NAME, C_DATE_OF_BIRTH });
+            addIndex("PERSON_NAME_IDX", true, new DBColumn[] { FIRST_NAME, LAST_NAME, DATE_OF_BIRTH });
+
             // Set timestamp column for save updates
-            setTimestampColumn(C_UPDATE_TIMESTAMP);
-            
+            setTimestampColumn(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");
+            genders.set("M", "!option.employee.gender.male");
+            genders.set("F", "!option.employee.gender.female");
+            GENDER.setOptions(genders);
+            GENDER.setControlType("select");
+
+            Options retireds = new Options();
+            retireds.set("N", "!option.employee.retired.true");
+            retireds.set("F", "!option.employee.retired.false");
+            RETIRED.setOptions(retireds);
+            RETIRED.setControlType("checkbox");
             
             // Set special control types
-            C_DEPARTMENT_ID.setControlType("select");
-            C_PHONE_NUMBER .setControlType("phone");
+            DEPARTMENT_ID.setControlType("select");
+            PHONE_NUMBER.setControlType("phone");
             
-        }    
-    }   
+//            PICTURE.setControlType("blob");
 
-    // 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 ));
+        }
     }
-    
+
 }

Modified: 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/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/SampleTable.java?rev=1351458&r1=1351457&r2=1351458&view=diff
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/SampleTable.java (original)
+++ empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/SampleTable.java Mon Jun 18 18:52:35 2012
@@ -18,22 +18,22 @@
  */
 package org.apache.empire.jsf2.websample.db;
 
+import java.util.Locale;
+
 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";
+ * 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.";
-    
+    private final static long serialVersionUID   = 1L;
+    public final String       MESSAGE_KEY_PREFIX = "!field.title.";
+
     public SampleTable(String name, DBDatabase db)
     {
         super(name, db);
@@ -43,16 +43,39 @@ public class SampleTable extends DBTable
     protected void addColumn(DBTableColumn column)
     {
         // Set Translation Title
-        String col = column.getBeanPropertyName();  
-        String tbl = getName().toLowerCase();   
+        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");
+        column.setControlType((type == DataType.BOOL) ? "checkbox" : "text");
 
         // Add Column
         super.addColumn(column);
     }
+
+    public enum LanguageIndex {
+        DE(Locale.GERMAN),
+
+        EN(Locale.ENGLISH);
+
+        private final Locale locale;
+
+        private LanguageIndex(Locale locale)
+        {
+            this.locale = locale;
+        }
+
+        public Locale getLocale()
+        {
+            return this.locale;
+        }
+
+        public String getDBLangKey()
+        {
+            return this.name().toUpperCase();
+        }
+    }
 }

Modified: 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/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/DepartmentRecord.java?rev=1351458&r1=1351457&r2=1351458&view=diff
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/DepartmentRecord.java (original)
+++ empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/DepartmentRecord.java Mon Jun 18 18:52:35 2012
@@ -18,13 +18,16 @@
  */
 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;
+import org.apache.empire.jsf2.websample.db.SampleDB.TDepartments;
 
-public class DepartmentRecord extends DBRecord
+public class DepartmentRecord extends SampleRecord<TDepartments>
 {
     private final static long serialVersionUID = 1L;
+
+    public DepartmentRecord(SampleDB db)
+    {
+        super(db.T_DEPARTMENTS);
+    }
   
-    public static final SampleDB.Departments T = FacesUtils.getDatabase().T_DEPARTMENTS;  
 }

Modified: 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/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/EmployeeRecord.java?rev=1351458&r1=1351457&r2=1351458&view=diff
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/EmployeeRecord.java (original)
+++ empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/EmployeeRecord.java Mon Jun 18 18:52:35 2012
@@ -21,43 +21,42 @@ package org.apache.empire.jsf2.websample
 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;
+import org.apache.empire.jsf2.websample.db.SampleDB.TEmployees;
+import org.apache.empire.jsf2.websample.web.SampleUtils;
 
-
-public class EmployeeRecord extends DBRecord
+public class EmployeeRecord extends SampleRecord<TEmployees>
 {
     private final static long serialVersionUID = 1L;
-  
-    public static final SampleDB.Employees T = FacesUtils.getDatabase().T_EMPLOYEES;  
- 
-    // Sample Implementation for Department Record
-    public DepartmentRecord getDepartmentRecord()
+
+    public EmployeeRecord(SampleDB db)
     {
-        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; 
+        super(db.T_EMPLOYEES);
     }
-    
+
     @Override
     public Options getFieldOptions(DBColumn column)
     {
-        if (column.equals(T.C_DEPARTMENT_ID)) {
-            SampleDB db = (SampleDB)getDatabase();
+        if (column.equals(T.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());
+            cmd.select(db.T_DEPARTMENTS.DEPARTMENT_ID);
+            cmd.select(db.T_DEPARTMENTS.NAME);
+            cmd.orderBy(db.T_DEPARTMENTS.NAME);
+            return db.queryOptionList(cmd.getSelect(), SampleUtils.getConnection());
         }
         // base class implementation
         return super.getFieldOptions(column);
     }
-    
+
+    // Sample Implementation for Department Record
+    public DepartmentRecord getDepartmentRecord()
+    {
+        DepartmentRecord rec = new DepartmentRecord((SampleDB)this.getDatabase());
+        SampleDB.TDepartments table = SampleUtils.getDatabase().T_DEPARTMENTS;
+        rec.read(table, this.getInt(T.DEPARTMENT_ID), SampleUtils.getConnection());
+        return rec;
+    }
+
 }

Added: empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/SampleRecord.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/SampleRecord.java?rev=1351458&view=auto
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/SampleRecord.java (added)
+++ empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/SampleRecord.java Mon Jun 18 18:52:35 2012
@@ -0,0 +1,66 @@
+/*
+ * 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 java.sql.Connection;
+
+import org.apache.empire.db.DBRecord;
+import org.apache.empire.jsf2.websample.db.SampleTable;
+
+
+public abstract class SampleRecord<T extends SampleTable> extends DBRecord {
+
+	private static final long serialVersionUID = 1L;
+	
+	protected T T; // The table
+
+	public SampleRecord(T table) {
+		super.init(table, DBRecord.REC_EMTPY, null);
+		this.T = table;
+	}
+
+	/**
+	 * Returns the table this record is based upon.
+	 * @return The table this record is based upon.
+	 */
+	public T getTable() {
+		return T;
+	}
+    
+    public void create(Connection conn)
+    {
+        super.create(getTable(), conn);
+    }
+    
+    public void create()
+    {
+        super.create(getTable());
+    }
+	
+    public void read(Object[] keys, Connection conn)
+    {
+        super.read(getTable(), keys, conn);
+    }
+
+    public void read(Object id, Connection conn)
+    {
+        super.read(getTable(), id, conn);
+    }
+	
+}
\ No newline at end of file

Propchange: empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/db/records/SampleRecord.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/AutheticationPhaseListener.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/AutheticationPhaseListener.java?rev=1351458&view=auto
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/AutheticationPhaseListener.java (added)
+++ empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/AutheticationPhaseListener.java Mon Jun 18 18:52:35 2012
@@ -0,0 +1,154 @@
+/*
+ * 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 javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.empire.commons.ObjectUtils;
+import org.apache.empire.commons.StringUtils;
+import org.apache.empire.exceptions.InvalidArgumentException;
+import org.apache.empire.jsf2.app.FacesUtils;
+import org.apache.empire.jsf2.websample.web.pages.SamplePages;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AutheticationPhaseListener implements PhaseListener
+{
+    private static final long   serialVersionUID = 1L;
+    private static final Logger log              = LoggerFactory.getLogger(AutheticationPhaseListener.class);
+
+    private static final String LOGOUT_PARAM     = "logout";    // must be ?logout=true
+//    private static final String LANGUAGE_PARAM   = "prefLanguage";    // must be ?logout=true
+    
+    public AutheticationPhaseListener()
+    {
+    }
+
+    // @Override
+    public PhaseId getPhaseId()
+    {
+        return PhaseId.RESTORE_VIEW;
+    }
+
+    // @Override
+    public void beforePhase(PhaseEvent pe)
+    {
+        // Check App
+        SampleApplication app = SampleUtils.getSampleApplication();
+        if (app == null)
+        {
+            log.error("Application not initialized!");
+            return;
+        }
+        try
+        {
+            FacesContext fc = pe.getFacesContext();
+            // Path Info
+            if (log.isDebugEnabled())
+            {
+                String path = fc.getExternalContext().getRequestServletPath();
+                log.debug("Restoring view for request path {}.", path);
+            }    
+            checkAuthetication(fc, app);
+        }
+        catch (Exception e)
+        {
+            log.error("Authetication exception \"{}\" redirecting to error page!", e.getMessage(), e);
+            String errorPage = getPageUri(app.getSampleConfig().getAccessDeniedPage());
+            FacesUtils.redirectDirectly(pe.getFacesContext(), errorPage);
+        }
+    }
+    
+    // @Override
+    public void afterPhase(PhaseEvent event)
+    {
+        
+    }
+    
+    /******************************************************************************************/
+
+    
+    private void checkAuthetication(FacesContext fc, SampleApplication app)
+        throws Exception
+    {
+        SampleSession session = SampleUtils.getSampleSession(fc);
+
+        if (!session.isAuthorized())
+        {   
+            HttpServletRequest req = FacesUtils.getHttpRequest(fc);
+            String reqURI = req.getRequestURI();
+            int iSession = reqURI.indexOf(';');
+            if (iSession>0)
+            	reqURI = reqURI.substring(0,iSession);
+            
+            String loginPage = getPageUri(SamplePages.LoginPage.getOutcome().toString());
+            if (reqURI.equalsIgnoreCase(loginPage))
+            {   
+                log.debug("Showing login page {}.", loginPage);
+                return;
+            }
+            FacesUtils.redirectDirectly(fc, SamplePages.LoginPage);
+        }
+        else
+        {   // Check Logout
+            HttpServletRequest req = FacesUtils.getHttpRequest(fc);
+            Object logout = req.getParameter(LOGOUT_PARAM);
+            if (logout!=null && ObjectUtils.getBoolean(logout))
+            {   // Perform logout
+                doLogout(fc);
+                // return to login page
+                String redirectPage = req.getRequestURI();
+                log.info("User logout performed. Returning to start page {}!", redirectPage);
+                FacesUtils.redirectDirectly(fc, redirectPage);
+            }
+        }
+        
+     
+    }
+    
+    /******************************************************************************************/
+
+    private void doLogout(FacesContext fc)
+    {
+        fc.getExternalContext().invalidateSession();
+    }
+    
+   
+    
+    private String getPageUri(String page)
+    {
+        if (StringUtils.isEmpty(page))
+            throw new InvalidArgumentException("page", page);
+        if (page.startsWith("http"))
+            return page;
+        if (page.startsWith("/")==false)
+            page="/"+page;
+        // Detect page uri
+        String pathPrefix = SampleUtils.getContextPath();
+        String pageUri = pathPrefix + page;
+        return pageUri;
+    }
+
+ 
+    
+}

Propchange: empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/AutheticationPhaseListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 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/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplication.java?rev=1351458&r1=1351457&r2=1351458&view=diff
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplication.java (original)
+++ empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplication.java Mon Jun 18 18:52:35 2012
@@ -20,13 +20,14 @@ package org.apache.empire.jsf2.websample
 
 import java.sql.Connection;
 import java.sql.DriverManager;
+import java.util.Locale;
 
-import javax.faces.bean.ApplicationScoped;
-import javax.faces.bean.ManagedBean;
 import javax.servlet.ServletContext;
+import javax.sql.DataSource;
 
 import org.apache.empire.commons.StringUtils;
 import org.apache.empire.db.DBCommand;
+import org.apache.empire.db.DBDatabase;
 import org.apache.empire.db.DBDatabaseDriver;
 import org.apache.empire.db.DBRecord;
 import org.apache.empire.db.DBSQLScript;
@@ -35,75 +36,73 @@ import org.apache.empire.db.hsql.DBDatab
 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.app.FacesApplication;
+import org.apache.empire.jsf2.controls.InputControlManager;
+import org.apache.empire.jsf2.custom.controls.FileInputControl;
 import org.apache.empire.jsf2.websample.db.SampleDB;
+import org.apache.empire.jsf2.websample.web.pages.SamplePages;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@ManagedBean(name = "application")
-@ApplicationScoped
-public class SampleApplication {
+import com.sun.faces.application.ApplicationAssociate;
+import com.sun.faces.mgbean.BeanManager;
+
+public class SampleApplication extends FacesApplication {
 	// Logger
 	private static final Logger log = LoggerFactory
 			.getLogger(SampleApplication.class);
 
+	private static SampleApplication sampleApplication = null;
+
+	protected static final String MANAGED_BEAN_NAME = "sampleApplication";
+	protected static final Locale DEFAULT_LOCALE = Locale.ENGLISH;
 	// Non-Static
-	private SampleDB db = new SampleDB();
 	private SampleConfig config = new SampleConfig();
+	private SampleDB sampleDB = null;
 
 	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 ");
+	public static SampleApplication get() {
+		return SampleApplication.sampleApplication;
+	}
 
-		} catch (Exception e) {
-			// Error
-			log.info(e.toString());
-			e.printStackTrace();
+	public SampleApplication() { 
+		
+		// Check for single instance
+		if (SampleApplication.sampleApplication != null) {
+			throw new RuntimeException(
+					"Attempt to create second instance of SampleApplication. SampleApplication is a singleton!");
 		}
+		// trace
+		SampleApplication.log.trace("SampleApplication created");
+		SampleApplication.sampleApplication = this;
 
+		// register custom control types
+		InputControlManager.registerControl(new FileInputControl());
 	}
 
-	public SampleDB getDatabase() {
-		return db;
-	}
+	@Override
+	public void init(ServletContext servletContext) {
+		// register all controls
+		// InputControlManager.registerControl("myType", new
+		// MyTypeInputControl());
+		config.init(servletContext.getRealPath("WEB-INF/config.xml"));
+
+		// Get a JDBC Connection
+		log.info("*** getJDBCConnection() ***");
+		conn = getJDBCConnection(servletContext);
+
+		log.info("*** initDatabase() ***");
+		initDatabase();
 
-	public Connection getPooledConnection() {
-		return conn;
-	}
+		log.info("*** initPages() ***");
+		initPages(servletContext);
 
-	/**
-	 * releases a connection from the connection pool
-	 */
-	public void releaseConnection(Connection conn, boolean commit) {
-		// Return Connection to Connection Pool
+		// Set Database to Servlet Context
+		servletContext.setAttribute("db", sampleDB);
+
+		// Done
+		log.info("Application initialized ");
 	}
 
 	/*
@@ -138,6 +137,27 @@ public class SampleApplication {
 		return conn;
 	}
 
+	private void initDatabase() {
+		sampleDB = new SampleDB();
+
+		// Open Database (and create if not existing)
+		log.info("*** open database ***");
+		String driverProvider = config.getDatabaseProvider();
+		DBDatabaseDriver driver = getDatabaseDriver(driverProvider);
+		Connection conn = null;
+		try {
+			conn = getConnection(sampleDB);
+			sampleDB.open(driver, conn);
+			if (!databaseExists(conn)) {
+				// STEP 4: Create Database
+				log.info("*** create Database ***");
+				createSampleDatabase(driver, conn);
+			}
+		} finally {
+			releaseConnection(sampleDB, conn, true);
+		}
+	}
+
 	/*
 	 * getDatabaseDriver
 	 */
@@ -165,12 +185,21 @@ public class SampleApplication {
 		}
 	}
 
+	private void initPages(ServletContext sc) {
+		BeanManager bm = ApplicationAssociate.getInstance(sc).getBeanManager();
+		new SamplePages().registerPageBeans(bm);
+	}
+
+	public SampleDB getDatabase() {
+		return sampleDB;
+	}
+
 	private boolean databaseExists(Connection conn) {
 		// Check wether DB exists
-		DBCommand cmd = db.createCommand();
-		cmd.select(db.T_DEPARTMENTS.count());
+		DBCommand cmd = sampleDB.createCommand();
+		cmd.select(sampleDB.T_DEPARTMENTS.count());
 		try {
-			return (db.querySingleInt(cmd.getSelect(), -1, conn) >= 0);
+			return (sampleDB.querySingleInt(cmd.getSelect(), -1, conn) >= 0);
 		} catch (QueryFailedException e) {
 			return false;
 		}
@@ -185,15 +214,15 @@ public class SampleApplication {
 	private void createSampleDatabase(DBDatabaseDriver driver, Connection conn) {
 		// create DLL for Database Definition
 		DBSQLScript script = new DBSQLScript();
-		db.getCreateDDLScript(driver, script);
+		sampleDB.getCreateDDLScript(driver, script);
 		// Show DLL Statements
 		System.out.println(script.toString());
 		// Execute Script
 		script.run(driver, conn, false);
-		db.commit(conn);
+		sampleDB.commit(conn);
 		// Open again
-		if (!db.isOpen()) {
-			db.open(driver, conn);
+		if (!sampleDB.isOpen()) {
+			sampleDB.open(driver, conn);
 		}
 		// Insert Sample Departments
 		int idDevDep = insertDepartmentSampleRecord(conn, "Development", "ITTK");
@@ -205,7 +234,7 @@ public class SampleApplication {
 				idDevDep);
 		insertEmployeeSampleRecord(conn, "Mrs.", "Anna", "Smith", "F", idSalDep);
 		// Commit
-		db.commit(conn);
+		sampleDB.commit(conn);
 	}
 
 	/*
@@ -215,9 +244,9 @@ public class SampleApplication {
 			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);
+		rec.create(sampleDB.T_DEPARTMENTS);
+		rec.setValue(sampleDB.T_DEPARTMENTS.NAME, department_name);
+		rec.setValue(sampleDB.T_DEPARTMENTS.BUSINESS_UNIT, businessUnit);
 		try {
 			rec.update(conn);
 		} catch (Exception e) {
@@ -225,7 +254,7 @@ public class SampleApplication {
 			return 0;
 		}
 		// Return Department ID
-		return rec.getInt(db.T_DEPARTMENTS.C_DEPARTMENT_ID);
+		return rec.getInt(sampleDB.T_DEPARTMENTS.DEPARTMENT_ID);
 	}
 
 	/*
@@ -235,23 +264,70 @@ public class SampleApplication {
 			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.create(sampleDB.T_EMPLOYEES);
+		rec.setValue(sampleDB.T_EMPLOYEES.SALUTATION, salutation);
+		rec.setValue(sampleDB.T_EMPLOYEES.FIRST_NAME, firstName);
+		rec.setValue(sampleDB.T_EMPLOYEES.LAST_NAME, lastName);
+		rec.setValue(sampleDB.T_EMPLOYEES.GENDER, gender);
+		rec.setValue(sampleDB.T_EMPLOYEES.DEPARTMENT_ID, depID);
+		try {
 			rec.update(conn);
-		}
-		catch(Exception e)
-		{
+		} catch (Exception e) {
 			log.error(e.getLocalizedMessage());
 			return 0;
 		}
 		// Return Employee ID
-		return rec.getInt(db.T_EMPLOYEES.C_EMPLOYEE_ID);
+		return rec.getInt(sampleDB.T_EMPLOYEES.EMPLOYEE_ID);
+	}
+
+	@Override
+	/**
+	 * returns null as connection pooling is not used
+	 */
+	protected DataSource getAppDataSource(DBDatabase db) {
+		return null;
+	}
+
+    /**
+     * Usually returns a connection from the connection pool
+     * As the sample does not use connection pooling, a static connection is returned
+     * @return a connection for the requested db
+     */
+    protected Connection getConnection(DBDatabase db)
+    {
+    	return conn;
+    }
+
+    /**
+     * Usually releases a connection from the connection pool
+     * As the sample does not use connection pooling, only a commit or rollback is performed
+     */
+    protected void releaseConnection(DBDatabase db, Connection conn, boolean commit)
+    {
+        // release connection
+        if (conn == null)
+        {
+            return;
+        }
+        // Commit or rollback connection depending on the exit code
+        if (commit)
+        { // success: commit all changes
+            db.commit(conn);
+            log.debug("REQUEST {}: commited.");
+        }
+        else
+        { // failure: rollback all changes
+            db.rollback(conn);
+            log.debug("REQUEST {}: rolled back.");
+        }
+    }
+	
+	protected SampleConfig getSampleConfig() {
+		if (config == null) {
+			SampleApplication.log
+					.error("Application configuration not initialized!");
+		}
+		return config;
 	}
 
 }

Added: empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplicationFactory.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplicationFactory.java?rev=1351458&view=auto
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplicationFactory.java (added)
+++ empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplicationFactory.java Mon Jun 18 18:52:35 2012
@@ -0,0 +1,69 @@
+/*
+ * 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.Map;
+
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.context.FacesContext;
+
+import org.apache.empire.exceptions.InvalidArgumentException;
+import org.apache.empire.exceptions.ItemExistsException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.sun.faces.application.InjectionApplicationFactory;
+
+public class SampleApplicationFactory extends ApplicationFactory
+{
+    private static final Logger  log = LoggerFactory.getLogger(SampleApplicationFactory.class);
+    private volatile Application application;
+
+    public SampleApplicationFactory()
+    {
+        log.info("SampleApplicationFactory created");
+    }
+
+    @Override
+    public Application getApplication()
+    {
+        if (application == null)
+        { // Create Application
+            application = new SampleApplication();
+            // InjectionApplicationFactory.setApplicationInstance(application);
+            Map<String, Object> appMap = FacesContext.getCurrentInstance().getExternalContext().getApplicationMap();
+            appMap.put(InjectionApplicationFactory.class.getName(), application);
+            // log
+            log.info("Fin2Application Application instance created");
+        }
+        return application;
+    }
+
+    @Override
+    public void setApplication(Application application)
+    {
+        if (this.application != null)
+            throw new ItemExistsException(this.application);
+        if (!(application instanceof SampleApplication))
+            throw new InvalidArgumentException("application", application);
+        this.application = application;
+    }
+
+}

Propchange: empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplicationFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 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/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleConfig.java?rev=1351458&r1=1351457&r2=1351458&view=diff
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleConfig.java (original)
+++ empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleConfig.java Mon Jun 18 18:52:35 2012
@@ -25,99 +25,115 @@ 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;
-	}
+public class SampleConfig extends XMLConfiguration
+{
+    // Logger
+    private static final Logger log              = LoggerFactory.getLogger(SampleConfig.class);
+    private String              loggingNodeName  = "log4j:configuration";
+
+    private String              jndiContext      = "";
+
+    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              dataSource       = "java:comp/env/jdbc/sampleDataSource";
+
+    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
@@ -136,8 +152,7 @@ public class SampleConfig extends XMLCon
         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);
+            SampleConfig.log.error("Log configuration node {} has not been found. Logging has not been configured.", loggingNodeName);
             return false;
         }
         // Init Log4J
@@ -147,5 +162,30 @@ public class SampleConfig extends XMLCon
         return true;
     }
 
+    public String getDataSourceName()
+    {
+        return dataSource;
+    }
+
+    public void setDataSourceName(String dataSource)
+    {
+        this.dataSource = dataSource;
+    }
+
+
+    public String getJndiContextFactoryName()
+    {
+        return jndiContext;
+    }
+
+    public void setJndiContextFactoryName(String jndiContext)
+    {
+        this.jndiContext = jndiContext;
+    }
+
+    public String getAccessDeniedPage()
+    {
+        return null;
+    }
 
 }

Modified: empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleSession.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleSession.java?rev=1351458&r1=1351457&r2=1351458&view=diff
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleSession.java (original)
+++ empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleSession.java Mon Jun 18 18:52:35 2012
@@ -18,27 +18,28 @@
  */
 package org.apache.empire.jsf2.websample.web;
 
-import javax.faces.bean.ManagedBean;
-import javax.faces.bean.SessionScoped;
+import java.io.Serializable;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@ManagedBean
-@SessionScoped
-public class SampleSession
+public class SampleSession implements Serializable
 {
-    private static final Logger log                = LoggerFactory.getLogger(SampleSession.class);
+    private static final long     serialVersionUID  = 1L;
 
-    private SampleUser user;
+    private static final Logger   log               = LoggerFactory.getLogger(SampleSession.class);
 
-	private String              page               = "loginPage";
+    protected static final String MANAGED_BEAN_NAME = "sampleSession";
 
-    private Throwable           rootCause;
+    private SampleUser            user              = null;
+
+    private String                page              = "loginPage";
+
+    private Throwable             rootCause;
 
     public SampleSession()
     {
-    	SampleSession.log.info("SESSION: created.");
+        SampleSession.log.info("SESSION: created.");
     }
 
     public void setPage(String page)
@@ -61,12 +62,19 @@ public class SampleSession
         return this.rootCause;
     }
 
-    public SampleUser getUser() {
-		return user;
-	}
-
-	public void setUser(SampleUser user) {
-		this.user = user;
-	}
+    public boolean isAuthorized()
+    {
+        return user != null;
+    }
+    
+    public SampleUser getUser()
+    {
+        return user;
+    }
+
+    public void setUser(SampleUser user)
+    {
+        this.user = user;
+    }
 
 }

Modified: empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleUser.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleUser.java?rev=1351458&r1=1351457&r2=1351458&view=diff
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleUser.java (original)
+++ empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleUser.java Mon Jun 18 18:52:35 2012
@@ -18,24 +18,50 @@
  */
 package org.apache.empire.jsf2.websample.web;
 
-public class SampleUser
+import java.io.Serializable;
+import java.util.Locale;
+
+public class SampleUser implements Serializable
 {
-    private String userName;
-    private String password;
-    
-    public SampleUser(String userName, String password)
+    private static final long     serialVersionUID  = 1L;
+    protected static final String MANAGED_BEAN_NAME = "sampleUser";
+
+    private String                userName          = "";
+    private String                password          = "";
+    private Locale                language          = SampleApplication.DEFAULT_LOCALE;
+
+    public SampleUser()
     {
-        this.userName = userName;
-        this.password = password;
     }
-    
+
     public String getPassword()
     {
         return password;
     }
+
     public String getUserName()
     {
         return userName;
     }
+
+    public void setUserName(String name)
+    {
+        this.userName = name;
+    }
+
+    public void setPassword(String password)
+    {
+        this.password = password;
+    }
+
+    public Locale getLocale()
+    {
+        return this.language;
+    }
     
+    public void setLocale(Locale lo)
+    {
+        this.language = lo;
+    }
+
 }

Added: empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleUtils.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleUtils.java?rev=1351458&view=auto
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleUtils.java (added)
+++ empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleUtils.java Mon Jun 18 18:52:35 2012
@@ -0,0 +1,131 @@
+/*
+ * 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.faces.context.FacesContext;
+
+import org.apache.empire.jsf2.app.FacesUtils;
+import org.apache.empire.jsf2.utils.ParameterMap;
+import org.apache.empire.jsf2.websample.db.SampleDB;
+
+public class SampleUtils extends FacesUtils
+{
+    public static SampleApplication getSampleApplication()
+    {
+        return SampleApplication.get();
+    }
+
+    public static SampleDB getDatabase()
+    {
+        return getSampleApplication().getDatabase();
+    }
+
+    public static SampleUser getSampleUser()
+    {
+        FacesContext fc = getContext();
+        return (SampleUser) getManagedBean(fc, SampleUser.MANAGED_BEAN_NAME);
+    }
+
+    public static SampleSession getSampleSession(FacesContext fc)
+    {
+        return (SampleSession) getManagedBean(fc, SampleSession.MANAGED_BEAN_NAME);
+    }
+
+    public static SampleSession getSampleSession()
+    {
+        return getSampleSession(FacesContext.getCurrentInstance());
+    }
+
+    public static ParameterMap getParameterMap()
+    {
+        return getParameterMap(getContext());
+    }
+
+    public static String getContextPath()
+    {
+        return FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();
+    }
+
+    public static Object getRequestAttribute(final String key)
+    {
+        FacesContext fc = getContext();
+        return getRequestAttribute(fc, key);
+    }
+
+    public static void setRequestAttribute(final String key, Object value)
+    {
+        FacesContext fc = getContext();
+        setRequestAttribute(fc, key, value);
+    }
+
+    public static <T> T getManagedBean(final Class<T> cls)
+    {
+        FacesContext fc = getContext();
+        return getManagedBean(fc, cls);
+    }
+
+    /* file */
+
+    public static String getRealPath(String path)
+    {
+        FacesContext fc = getContext();
+        return getRealPath(fc, path);
+    }
+
+    public static String getFilePath(String path, String file)
+    {
+        FacesContext fc = getContext();
+        return getFilePath(fc, path, file);
+    }
+
+    /* Connection */
+
+    public static Connection getConnection()
+    {
+        FacesContext fc = getContext();
+        return getFacesApplication().getConnectionForRequest(fc, getDatabase());
+    }
+
+    public static void releaseConnection(boolean commit)
+    {
+        FacesContext fc = getContext();
+        getFacesApplication().releaseConnection(fc, getDatabase(), commit);
+    }
+
+    public static void releaseConnection()
+    {
+        FacesContext fc = getContext();
+        getFacesApplication().releaseConnection(fc, getDatabase());
+    }
+
+    /* Messages */
+
+    public static String getMessage(String messageKey)
+    {
+        return getMessage(getContext(), messageKey);
+    }
+
+    public static void addErrorMessage(String msg)
+    {
+        FacesContext fc = getContext();
+        addErrorMessage(fc, msg);
+    }
+}

Propchange: empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/objects/EmployeeSearchFilter.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/objects/EmployeeSearchFilter.java?rev=1351458&view=auto
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/objects/EmployeeSearchFilter.java (added)
+++ empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/objects/EmployeeSearchFilter.java Mon Jun 18 18:52:35 2012
@@ -0,0 +1,94 @@
+/*
+ * 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.objects;
+
+import java.io.Serializable;
+
+public class EmployeeSearchFilter implements Serializable
+{
+    private static final long serialVersionUID = 1L;
+
+    private String            employeeId;
+    private String            firstName;
+    private String            lastName;
+    private String            departmentId;
+    private String            gender;
+
+    public EmployeeSearchFilter()
+    {
+        resetFilter();
+    }
+
+    public void resetFilter()
+    {
+        employeeId = "";
+        firstName = "";
+        lastName = "";
+        departmentId = "";
+        gender = "";
+    }
+
+    public String getEmployeeId()
+    {
+        return employeeId;
+    }
+
+    public void setEmployeeId(String employeeId)
+    {
+        this.employeeId = employeeId;
+    }
+
+    public String getDepartmentId()
+    {
+        return departmentId;
+    }
+
+    public void setDepartmentId(String departmentId)
+    {
+        this.departmentId = departmentId;
+    }
+
+    public String getFirstName()
+    {
+        return firstName;
+    }
+
+    public void setFirstName(String firstName)
+    {
+        this.firstName = firstName;
+    }
+
+    public String getLastName()
+    {
+        return lastName;
+    }
+
+    public void setLastName(String lastName)
+    {
+        this.lastName = lastName;
+    }
+
+	public String getGender() {
+		return gender;
+	}
+
+	public void setGender(String gender) {
+		this.gender = gender;
+	}
+}

Propchange: empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/objects/EmployeeSearchFilter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/objects/User.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/objects/User.java?rev=1351458&r1=1351457&r2=1351458&view=diff
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/objects/User.java (original)
+++ empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/objects/User.java Mon Jun 18 18:52:35 2012
@@ -20,30 +20,29 @@ package org.apache.empire.jsf2.websample
 
 import java.io.Serializable;
 
-import javax.faces.bean.ManagedBean;
-import javax.faces.bean.ViewScoped;
-
-@ManagedBean
-@ViewScoped
 public class User implements Serializable
 {
-	private static final long serialVersionUID = -3099402366604009203L;
+    private static final long serialVersionUID = 1L;
+
+    private String            name             = "";
+
+    private String            password         = "";
 
-    private String name;
-	
-    private String password;
     public String getName()
     {
         return name;
     }
+
     public void setName(String name)
     {
         this.name = name;
     }
+
     public String getPassword()
     {
         return password;
     }
+
     public void setPassword(String password)
     {
         this.password = password;

Modified: empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/EmployeeDetailPage.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/EmployeeDetailPage.java?rev=1351458&r1=1351457&r2=1351458&view=diff
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/EmployeeDetailPage.java (original)
+++ empire-db/trunk/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/EmployeeDetailPage.java Mon Jun 18 18:52:35 2012
@@ -18,72 +18,94 @@
  */
 package org.apache.empire.jsf2.websample.web.pages;
 
-import javax.faces.bean.ManagedBean;
-import javax.faces.bean.ViewScoped;
+import java.sql.Connection;
 
+import org.apache.empire.jsf2.pageelements.RecordPageElement;
+import org.apache.empire.jsf2.pages.PageOutcome;
 import org.apache.empire.jsf2.websample.db.SampleDB;
 import org.apache.empire.jsf2.websample.db.records.EmployeeRecord;
-import org.apache.empire.jsf2.websample.web.FacesUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@ManagedBean
-@ViewScoped
-public class EmployeeDetailPage extends Page {
-	// Logger
-	private static final Logger log = LoggerFactory
-			.getLogger(EmployeeDetailPage.class);
-
-	private EmployeeRecord employeeRecord;
-
-	public EmployeeRecord getEmployeeRecord() {
-		return employeeRecord;
-	}
-
-	/**
-	 * 
-	 */
-	private static final long serialVersionUID = 7880544317192692309L;
-
-	public String save() {
-		try {
-			employeeRecord.update(FacesUtils.getConnection());
-		} catch (Exception e) {
-			FacesUtils.addErrorMessage(e.getMessage());
-			return "";
-		}
-		return new EmployeeListPage().name();
-	}
-
-	public String delete() {
-		try {
-			employeeRecord.delete(FacesUtils.getConnection());
-		} catch (Exception e) {
-			FacesUtils.addErrorMessage(e.getMessage());
-		}
-		return new EmployeeListPage().name();
-	}
-
-	public String cancel() {
-		return new EmployeeListPage().name();
-	}
-
-	@Override
-	public void preRenderViewAction() {
-		if (employeeRecord == null) {
-			employeeRecord = new EmployeeRecord();
-			SampleDB sampleDB = FacesUtils.getDatabase();
-			String id = FacesUtils.getHttpRequest().getParameter("id");
-			if (id != null) {
-				try {
-					employeeRecord.read(sampleDB.T_EMPLOYEES,
-							new String[] { id }, FacesUtils.getConnection());
-				} catch (Exception e) {
-					FacesUtils.addErrorMessage(e.getMessage());
-				}
-			} else {
-				employeeRecord.create(sampleDB.T_EMPLOYEES);
-			}
-		}
-	}
+public class EmployeeDetailPage extends SamplePage
+{
+    private static final Logger               log               = LoggerFactory.getLogger(EmployeeDetailPage.class);
+    private static final long                 serialVersionUID  = 1L;
+
+    private static final String               EMPLOYEE_PROPERTY = "employee";
+    private String                            idParam;
+
+    private RecordPageElement<EmployeeRecord> employee;
+
+    public EmployeeDetailPage()
+    {
+        log.trace("EmployeeDetailPage created");
+
+        SampleDB db = getDatabase();
+        EmployeeRecord emplRec = new EmployeeRecord(db);
+        employee = new RecordPageElement<EmployeeRecord>(this, emplRec.getTable(), emplRec, EMPLOYEE_PROPERTY);
+    }
+
+    public String getIdParam()
+    {
+        return this.idParam;
+    }
+
+    public void setIdParam(String idParam)
+    {
+        log.info("EmployeeDetailPage idParam = {}.", idParam);
+        this.idParam = idParam;
+    }
+
+    public RecordPageElement<EmployeeRecord> getEmployee()
+    {
+        return employee;
+    }
+
+    public EmployeeRecord getEmployeeRecord()
+    {
+        return employee.getRecord();
+    }
+
+    @Override
+    public void doInit()
+    { // Notify Elements
+        if (!employee.getRecord().isValid())
+        {
+            employee.reloadRecord();
+        }
+    }
+
+    public void doLoad()
+    {
+        log.info("EmployeeDetailPage Loading entryId {}.", this.idParam);
+        // load the record
+        this.employee.loadRecord(this.idParam);
+    }
+
+    public void doCreate()
+    {
+        Connection conn = getConnection();
+        getEmployeeRecord().create(conn);
+        doRefresh();
+    }
+    
+    public PageOutcome doSave()
+    {
+        Connection conn = getConnection();
+        getEmployeeRecord().update(conn);
+        return getParentOutcome(true);
+    }
+
+    public PageOutcome doDelete()
+    {
+        Connection conn = getConnection();
+        getEmployeeRecord().delete(conn);
+        return getParentOutcome(true);
+    }
+    
+    public PageOutcome doCancel()
+    {
+        return getParentOutcome(true);
+    }
 }



Mime
View raw message