incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmatth...@apache.org
Subject svn commit: r1081175 - in /incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher: logon/LogonAction.java logon/LogoutAction.java view/logon/Logon.java
Date Sun, 13 Mar 2011 18:01:45 GMT
Author: rmatthews
Date: Sun Mar 13 18:01:44 2011
New Revision: 1081175

URL: http://svn.apache.org/viewvc?rev=1081175&view=rev
Log:
Login form is now repopulated on failure and an error is displayed

Modified:
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/logon/LogonAction.java
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/logon/LogoutAction.java
    incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Logon.java

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/logon/LogonAction.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/logon/LogonAction.java?rev=1081175&r1=1081174&r2=1081175&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/logon/LogonAction.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/logon/LogonAction.java
Sun Mar 13 18:01:44 2011
@@ -30,6 +30,8 @@ import org.apache.isis.viewer.scimpi.dis
 import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext;
 import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext.Scope;
 import org.apache.isis.viewer.scimpi.dispatcher.debug.DebugView;
+import org.apache.isis.viewer.scimpi.dispatcher.edit.FieldEditState;
+import org.apache.isis.viewer.scimpi.dispatcher.edit.FormState;
 
 
 // TODO this should work like EditAction so that logon page is repopulated
@@ -42,19 +44,33 @@ public class LogonAction implements Acti
 
         String view;
         if (session == null) {
-            context.addVariable("login-failure", "Failed to login. Check the username and
ensure that your password was entered correctly", Scope.INTERACTION);
+            FormState formState = new FormState();
+            formState.setError("Failed to login. Check the username and ensure that your
password was entered correctly");
+            FieldEditState fieldState = formState.createField("username", username);
+            if (username.length() == 0) {
+                fieldState.setError("User Name required");
+            }
+            fieldState = formState.createField("password", password);
+            if (password.length() == 0) {
+                fieldState.setError("Password required");
+            }
+            if (username.length() == 0 || password.length() == 0) {
+                formState.setError("Both the user name and password must be entered");
+            }
+            context.addVariable(ENTRY_FIELDS, formState, Scope.REQUEST);
+            
             view = context.getParameter("error");
+            context.setRequestPath("/" + view, Dispatcher.ACTION);
         } else {
             context.setSession(session);
-//            UserManager.logonUser(session);
             context.startHttpSession();
             view = context.getParameter("view");
             if (view == null) {
                 // REVIEW this is duplicated in Logon.java
                 view = "start." + Dispatcher.EXTENSION;
             }
+            context.redirectTo(view);
         }
-        context.redirectTo(view);
     }
 
     public String getName() {

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/logon/LogoutAction.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/logon/LogoutAction.java?rev=1081175&r1=1081174&r2=1081175&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/logon/LogoutAction.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/logon/LogoutAction.java
Sun Mar 13 18:01:44 2011
@@ -17,7 +17,6 @@
  *  under the License.
  */
 
-
 package org.apache.isis.viewer.scimpi.dispatcher.logon;
 
 import java.io.IOException;
@@ -29,6 +28,7 @@ import org.apache.isis.viewer.scimpi.dis
 import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext;
 import org.apache.isis.viewer.scimpi.dispatcher.debug.DebugView;
 
+
 public class LogoutAction implements Action {
 
     public String getName() {
@@ -36,7 +36,7 @@ public class LogoutAction implements Act
     }
 
     public void init() {}
-    
+
     public void process(RequestContext context) throws IOException {
         AuthenticationSession session = context.getSession();
         if (session != null) {
@@ -44,17 +44,14 @@ public class LogoutAction implements Act
             UserManager.logoffUser(session);
             context.endHttpSession();
         }
-        
+
         String view = context.getParameter("view");
         if (view == null) {
-            //view = context.getUrlBase() + context.getContextPath();
             view = context.getContextPath();
         }
         context.redirectTo(view);
     }
-    
-    public void debug(DebugView view) {}
-    
-}
 
+    public void debug(DebugView view) {}
 
+}

Modified: incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Logon.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Logon.java?rev=1081175&r1=1081174&r2=1081175&view=diff
==============================================================================
--- incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Logon.java
(original)
+++ incubator/isis/trunk/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Logon.java
Sun Mar 13 18:01:44 2011
@@ -26,6 +26,7 @@ import java.util.List;
 import org.apache.isis.runtimes.dflt.runtime.context.IsisContext;
 import org.apache.isis.viewer.scimpi.dispatcher.AbstractElementProcessor;
 import org.apache.isis.viewer.scimpi.dispatcher.UserlessSession;
+import org.apache.isis.viewer.scimpi.dispatcher.edit.FieldEditState;
 import org.apache.isis.viewer.scimpi.dispatcher.edit.FormState;
 import org.apache.isis.viewer.scimpi.dispatcher.processor.Request;
 import org.apache.isis.viewer.scimpi.dispatcher.view.form.HiddenInputField;
@@ -48,31 +49,23 @@ public class Logon extends AbstractEleme
     }
 
     public static void loginForm(Request request, String view) {
-        Object message = request.getContext().getVariable("login-failure");
-        if (message != null) {
-            request.appendHtml("<p class=\"login-failure\">" + message + "</p>");
-        }
-        
+    //    String message = (String) request.getContext().getVariable("login-failure");
+           
         String error = request.getOptionalProperty(ERRORS, request.getContext().getRequestedFile());
         List<HiddenInputField> hiddenFields = new ArrayList<HiddenInputField>();
         hiddenFields.add(new HiddenInputField(ERRORS, error));
         if (view != null) {
             hiddenFields.add(new HiddenInputField(VIEW, view));
         }
-   
-        InputField nameField = new InputField("username");
-        nameField.setType(InputField.TEXT);
+
+        FormState entryState = (FormState) request.getContext().getVariable(ENTRY_FIELDS);
+        InputField nameField = createdField("username", "User Name", InputField.TEXT, entryState);
         String width = request.getOptionalProperty("width");
         if (width != null) {
             int w = Integer.valueOf(width).intValue();
             nameField.setWidth(w);
         }
-        nameField.setLabel("User Name");
-   
-        InputField passwordField = new InputField("password");
-        passwordField.setType(InputField.PASSWORD);
-        passwordField.setLabel("Password");
-   
+        InputField passwordField = createdField("password", "Password", InputField.PASSWORD,
entryState); 
         InputField[] fields = new InputField[] { nameField, passwordField, };
    
         String formTitle = request.getOptionalProperty(FORM_TITLE);
@@ -80,13 +73,24 @@ public class Logon extends AbstractEleme
         String className = request.getOptionalProperty(CLASS, "action login full");
         String  id = request.getOptionalProperty(ID);
         
-        FormState entryState = (FormState) request.getContext().getVariable(ENTRY_FIELDS);
-
-        
         HtmlFormBuilder.createForm(request, "logon.app", hiddenFields.toArray(new HiddenInputField[hiddenFields.size()]),
fields,
                 className, id, formTitle, null, null, loginButtonTitle, entryState == null
? null : entryState.getError());
     }
 
+    protected static InputField createdField(String fieldName, String fieldLabel, int type,
FormState entryState) {
+        InputField nameField = new InputField(fieldName);
+        nameField.setType(type);
+        nameField.setLabel(fieldLabel);
+        if (entryState != null) {
+            FieldEditState fieldState = entryState.getField(fieldName);
+            String entry = fieldState == null ? "" : fieldState.getEntry();
+            nameField.setValue(entry);
+            String error =  fieldState == null ? "" : fieldState.getError();
+            nameField.setErrorText(error);
+        }
+        return nameField;
+    }
+
     public String getName() {
         return "logon";
     }



Mime
View raw message