You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2007/04/15 12:14:03 UTC

svn commit: r528951 - in /myfaces/tobago/trunk/example/addressbook/src/main: java/org/apache/myfaces/tobago/example/addressbook/web/ webapp/ webapp/WEB-INF/ webapp/application/

Author: lofwyr
Date: Sun Apr 15 03:14:01 2007
New Revision: 528951

URL: http://svn.apache.org/viewvc?view=rev&rev=528951
Log:
Working on login/startup
* Unotherized users will forwarded to the "list", athough when they type ".../editor.jsp"
* add logout method
* spashscreen to evaluate browser dimensions

Added:
    myfaces/tobago/trunk/example/addressbook/src/main/java/org/apache/myfaces/tobago/example/addressbook/web/StartupPhaseListener.java
    myfaces/tobago/trunk/example/addressbook/src/main/webapp/application/start.jsp
    myfaces/tobago/trunk/example/addressbook/src/main/webapp/error.jsp
Removed:
    myfaces/tobago/trunk/example/addressbook/src/main/webapp/start.jsp
Modified:
    myfaces/tobago/trunk/example/addressbook/src/main/java/org/apache/myfaces/tobago/example/addressbook/web/Controller.java
    myfaces/tobago/trunk/example/addressbook/src/main/webapp/WEB-INF/faces-config.xml
    myfaces/tobago/trunk/example/addressbook/src/main/webapp/application/list.jsp
    myfaces/tobago/trunk/example/addressbook/src/main/webapp/index.jsp

Modified: myfaces/tobago/trunk/example/addressbook/src/main/java/org/apache/myfaces/tobago/example/addressbook/web/Controller.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/addressbook/src/main/java/org/apache/myfaces/tobago/example/addressbook/web/Controller.java?view=diff&rev=528951&r1=528950&r2=528951
==============================================================================
--- myfaces/tobago/trunk/example/addressbook/src/main/java/org/apache/myfaces/tobago/example/addressbook/web/Controller.java (original)
+++ myfaces/tobago/trunk/example/addressbook/src/main/java/org/apache/myfaces/tobago/example/addressbook/web/Controller.java Sun Apr 15 03:14:01 2007
@@ -47,6 +47,7 @@
 import javax.faces.validator.ValidatorException;
 import java.io.IOException;
 import java.util.ArrayList;
+import javax.servlet.http.HttpSession;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
@@ -263,6 +264,15 @@
   public String cancelPopup() {
     setRenderPopup(false);
     return OUTCOME_LIST;
+  }
+
+  public String logout() {
+    FacesContext facesContext = FacesContext.getCurrentInstance();
+    HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false);
+    if (session != null) {
+      session.invalidate();
+    }
+    return "logout";
   }
 
   public Locale getLanguage() {

Added: myfaces/tobago/trunk/example/addressbook/src/main/java/org/apache/myfaces/tobago/example/addressbook/web/StartupPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/addressbook/src/main/java/org/apache/myfaces/tobago/example/addressbook/web/StartupPhaseListener.java?view=auto&rev=528951
==============================================================================
--- myfaces/tobago/trunk/example/addressbook/src/main/java/org/apache/myfaces/tobago/example/addressbook/web/StartupPhaseListener.java (added)
+++ myfaces/tobago/trunk/example/addressbook/src/main/java/org/apache/myfaces/tobago/example/addressbook/web/StartupPhaseListener.java Sun Apr 15 03:14:01 2007
@@ -0,0 +1,73 @@
+package org.apache.myfaces.tobago.example.addressbook.web;
+
+
+import org.apache.commons.lang.BooleanUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.faces.FacesException;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+import java.io.IOException;
+
+public class StartupPhaseListener implements PhaseListener {
+
+  private static final Log LOG = LogFactory.getLog(StartupPhaseListener.class);
+  public static final String LOGGED_IN
+      = StartupPhaseListener.class.getName() + ".LOGGED_IN";
+  public static final String PRINCIPAL
+      = StartupPhaseListener.class.getName() + ".PRINCIPAL";
+
+  public PhaseId getPhaseId() {
+    return PhaseId.RESTORE_VIEW;
+  }
+
+  public void beforePhase(PhaseEvent event) {
+
+    FacesContext facesContext = event.getFacesContext();
+    ExternalContext externalContext = facesContext.getExternalContext();
+    String pathInfo = externalContext.getRequestPathInfo();
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("externalContext.getRequestPathInfo() = '" + pathInfo + "'");
+    }
+
+    if (pathInfo.equals("/error.jsp") || // todo: not nice, find a declarative way.
+        pathInfo.startsWith("/auth/")) {
+      Object session = externalContext.getSession(false);
+      if (session != null) {
+        externalContext.getSessionMap().put(LOGGED_IN, Boolean.FALSE);
+      }
+      return; // nothing to do.
+    }
+
+    Boolean loggedIn = (Boolean) // todo: not nice to get this object directly from the session
+        externalContext.getSessionMap().get(LOGGED_IN);
+
+    if (! BooleanUtils.toBoolean(loggedIn)) {
+      try {
+        externalContext.getSessionMap().put(LOGGED_IN, Boolean.TRUE);
+        String forward = externalContext.getRequestContextPath()
+            + "/faces/application/start.jsp";
+        externalContext.redirect(externalContext.encodeResourceURL(forward));
+      } catch (Exception e) {
+        LOG.error("", e);
+        String forward = externalContext.getRequestContextPath()
+            + "/error.jsp";
+        try {
+          externalContext.redirect(externalContext.encodeResourceURL(forward));
+        } catch (IOException e2) {
+          LOG.error("", e2);
+          throw new FacesException("Can't redirect to errorpage '"
+              + forward + "'");
+        }
+      }
+    }
+  }
+
+  public void afterPhase(PhaseEvent event) {
+  }
+
+}

Modified: myfaces/tobago/trunk/example/addressbook/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/addressbook/src/main/webapp/WEB-INF/faces-config.xml?view=diff&rev=528951&r1=528950&r2=528951
==============================================================================
--- myfaces/tobago/trunk/example/addressbook/src/main/webapp/WEB-INF/faces-config.xml (original)
+++ myfaces/tobago/trunk/example/addressbook/src/main/webapp/WEB-INF/faces-config.xml Sun Apr 15 03:14:01 2007
@@ -43,6 +43,7 @@
 
   <lifecycle>
     <phase-listener>org.apache.myfaces.tobago.util.DebugPhaseListener</phase-listener>
+    <phase-listener>org.apache.myfaces.tobago.example.addressbook.web.StartupPhaseListener</phase-listener>
   </lifecycle>
 
   <managed-bean>

Modified: myfaces/tobago/trunk/example/addressbook/src/main/webapp/application/list.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/addressbook/src/main/webapp/application/list.jsp?view=diff&rev=528951&r1=528950&r2=528951
==============================================================================
--- myfaces/tobago/trunk/example/addressbook/src/main/webapp/application/list.jsp (original)
+++ myfaces/tobago/trunk/example/addressbook/src/main/webapp/application/list.jsp Sun Apr 15 03:14:01 2007
@@ -29,7 +29,8 @@
                          image="image/org/tango-project/tango-icon-theme/16x16/actions/contact-new.png"/>
             <tc:menuItem label="Add Dummy Addresses" action="#{controller.addDummyAddresses}" immediate="true"/>
             <tc:menuSeparator/>
-            <tc:menuItem label="Logout" image="image/org/tango-project/tango-icon-theme/16x16/actions/system-log-out.png"/>
+            <tc:menuItem label="Logout" action="#{controller.logout}" 
+                         image="image/org/tango-project/tango-icon-theme/16x16/actions/system-log-out.png"/>
           </tc:menu>
 
           <tc:menu label="#{bundle.menuSettings}">
@@ -67,14 +68,13 @@
       </f:facet>
       <tc:toolBar iconSize="big">
         <tc:button label="#{bundle.toolbarAddressList}" action="#{controller.search}" immediate="true"
-            image="image/org/tango-project/tango-icon-theme/32x32/mimetypes/x-office-address-book.png"
-            disabled="#{facesContext.viewRoot.viewId == '/application/list.jsp'}"/>
+            image="image/org/tango-project/tango-icon-theme/32x32/mimetypes/x-office-address-book.png"/>
         <tc:button label="#{bundle.listNew}" action="#{controller.createAddress}"
             image="image/org/tango-project/tango-icon-theme/32x32/actions/contact-new.png" />
         <tc:button onclick="alert('#{bundle.aboutMessage}')" label="#{bundle.toolbarAbout}"
             image="image/org/tango-project/tango-icon-theme/32x32/apps/help-browser.png"/>
-        <tc:button label="#{bundle.admin}" action="#{admin.admin}" 
-            image="image/org/tango-project/tango-icon-theme/32x32/categories/preferences-system.png" />
+        <tc:button label="#{bundle.admin}" action="#{admin.admin}"
+            image="image/org/tango-project/tango-icon-theme/32x32/categories/applications-system.png" />
       </tc:toolBar>
       <tc:box label="#{bundle.listBoxTitle}">
         <f:facet name="layout">
@@ -83,7 +83,7 @@
         <f:facet name="toolBar">
           <tc:toolBar>
             <tc:button label="#{bundle.listNew}" action="#{controller.createAddress}"
-                image="image/org/tango-project/tango-icon-theme/16x16/actions/contact-new.png"/>
+                image="image/org/tango-project/tango-icon-theme/16x16/actions/contact-new.png" />
             <tc:button label="#{bundle.listEdit}" action="#{controller.editAddress}"
                 image="image/org/tango-project/tango-icon-theme/16x16/apps/accessories-text-editor.png" />
             <tc:button label="#{bundle.listDelete}" action="#{controller.deleteAddresses}"
@@ -92,8 +92,7 @@
                 <tc:out value="#{bundle.listDeleteConfirmation}" />
               </f:facet>
             </tc:button>
-            <tc:button label="Select Columns" action="#{controller.selectColumns}"
-                image="image/org/tango-project/tango-icon-theme/16x16/categories/applications-system.png">
+            <tc:button label="Select Columns" action="#{controller.selectColumns}">
               <f:facet name="popup">
                 <tc:popup width="300px" height="200px" left="200px" top="200px"
                     rendered="#{controller.renderPopup}" id="popup">
@@ -125,8 +124,7 @@
 
         <tc:sheet columns="1*;1*;1*" value="#{controller.currentAddressList}"
             var="address" state="#{controller.selectedAddresses}"
-            sortActionListener="#{controller.sheetSorter}" rows="25"
-            showRowRange="left" showPageRange="right" showDirectLinks="center">
+            sortActionListener="#{controller.sheetSorter}">
           <tc:column id="firstName" label="#{bundle.listFirstName}" sortable="true"
                      rendered="#{controller.renderFirstName}">
             <tc:out value="#{address.firstName}" />

Added: myfaces/tobago/trunk/example/addressbook/src/main/webapp/application/start.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/addressbook/src/main/webapp/application/start.jsp?view=auto&rev=528951
==============================================================================
--- myfaces/tobago/trunk/example/addressbook/src/main/webapp/application/start.jsp (added)
+++ myfaces/tobago/trunk/example/addressbook/src/main/webapp/application/start.jsp Sun Apr 15 03:14:01 2007
@@ -0,0 +1,38 @@
+<%--
+ * 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.
+--%>
+<%@ taglib uri="http://myfaces.apache.org/tobago/component" prefix="tc" %>
+<%@ taglib uri="http://myfaces.apache.org/tobago/extension" prefix="tx" %>
+<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
+
+<f:view>
+  <tc:loadBundle basename="addressbook" var="bundle" />
+
+  <tc:page label="#{bundle.editorTitle}" state="#{layout}" width="#{layout.width}" height="#{layout.height}">
+    <f:facet name="action">
+      <tc:link action="list" />
+    </f:facet>
+
+    <tc:panel>
+      <f:facet name="layout">
+        <tc:gridLayout margin="10px"/>
+      </f:facet>
+
+      <tc:out value="Initializing the Addressbook Demo ..."/>
+
+    </tc:panel>
+  </tc:page>
+</f:view>

Added: myfaces/tobago/trunk/example/addressbook/src/main/webapp/error.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/addressbook/src/main/webapp/error.jsp?view=auto&rev=528951
==============================================================================
--- myfaces/tobago/trunk/example/addressbook/src/main/webapp/error.jsp (added)
+++ myfaces/tobago/trunk/example/addressbook/src/main/webapp/error.jsp Sun Apr 15 03:14:01 2007
@@ -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.
+--%>
+
+Sorry, an error has occured. (Todo: make a "real" error page)
\ No newline at end of file

Modified: myfaces/tobago/trunk/example/addressbook/src/main/webapp/index.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/addressbook/src/main/webapp/index.jsp?view=diff&rev=528951&r1=528950&r2=528951
==============================================================================
--- myfaces/tobago/trunk/example/addressbook/src/main/webapp/index.jsp (original)
+++ myfaces/tobago/trunk/example/addressbook/src/main/webapp/index.jsp Sun Apr 15 03:14:01 2007
@@ -14,4 +14,4 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
 --%>
-<jsp:forward page="faces/start.jsp"/>
\ No newline at end of file
+<jsp:forward page="faces/application/start.jsp"/>
\ No newline at end of file