struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hus...@apache.org
Subject svn commit: r387521 - in /struts/sandbox/trunk/action2/apps/mailreader/src: java/ java/mailreader2/ webapp/pages/
Date Tue, 21 Mar 2006 13:21:49 GMT
Author: husted
Date: Tue Mar 21 05:21:47 2006
New Revision: 387521

URL: http://svn.apache.org/viewcvs?rev=387521&view=rev
Log:
Action2 Apps
* Mailreader - Work in progress
** Add classes missing from prior commits
** Add validation for Registration action 
** Enable client-side validation 
** Update to latest WW build to utilize new ww:reset tag 




Added:
    struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Logoff.java   (with
props)
    struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MainMenu.java   (with
props)
    struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Registration-validation.xml
  (with props)
    struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Registration.java  
(with props)
Modified:
    struts/sandbox/trunk/action2/apps/mailreader/src/java/database.xml
    struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MailreaderSupport.java
    struts/sandbox/trunk/action2/apps/mailreader/src/java/xwork.xml
    struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Logon.jsp
    struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/MainMenu.jsp
    struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Registration.jsp
    struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Welcome.jsp

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/java/database.xml
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/java/database.xml?rev=387521&r1=387520&r2=387521&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/database.xml (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/database.xml Tue Mar 21 05:21:47
2006
@@ -10,3 +10,4 @@
         </subscription>
     </user>
 </database>
+        
\ No newline at end of file

Added: struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Logoff.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Logoff.java?rev=387521&view=auto
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Logoff.java (added)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Logoff.java Tue Mar
21 05:21:47 2006
@@ -0,0 +1,11 @@
+package mailreader2;
+
+public class Logoff extends MailreaderSupport {
+
+    public String execute() {
+
+        setUser(null);
+
+        return SUCCESS;
+    }
+}

Propchange: struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Logoff.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MailreaderSupport.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MailreaderSupport.java?rev=387521&r1=387520&r2=387521&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MailreaderSupport.java
(original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MailreaderSupport.java
Tue Mar 21 05:21:47 2006
@@ -101,7 +101,7 @@
 
     public User findUser(String username, String password) throws ExpiredPasswordException
{
         // FIXME: Stupid hack to compensate for inadequate DAO layer
-        if (username.equals("Hermes")) {
+        if ("Hermes".equals(username)) {
             throw new ExpiredPasswordException("Hermes");
         }
 
@@ -150,18 +150,25 @@
         getSession().put(Constants.SUBSCRIPTION_KEY, subscription);
     }
 
-    // ---- Control methods ----
+    /**
+     * <p>The task input field.</p>
+     */
+    private String task = null;
+
 
     /**
-     * <p> Helper method to log event and cancel transaction. </p>
-     *
-     * @param method Method being processed
-     * @param key    Attrkibute to remove from session, if any
+     * @return Returns the task.
      */
-    protected void doCancel(String method, String key) {
-        if (key != null) {
-            getSession().remove(key);
-        }
+    public String getTask() {
+        return this.task;
     }
+
+    /**
+     * @param task The task to set.
+     */
+    public void setTask(String task) {
+        this.task = task;
+    }
+
 
 }

Added: struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MainMenu.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MainMenu.java?rev=387521&view=auto
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MainMenu.java (added)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MainMenu.java Tue Mar
21 05:21:47 2006
@@ -0,0 +1,4 @@
+package mailreader2;
+
+public class MainMenu extends MailreaderSupport {
+}

Propchange: struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MainMenu.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Registration-validation.xml
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Registration-validation.xml?rev=387521&view=auto
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Registration-validation.xml
(added)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Registration-validation.xml
Tue Mar 21 05:21:47 2006
@@ -0,0 +1,55 @@
+<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
+
+<validators>
+
+    <field name="username">
+        <field-validator type="requiredstring">
+            <message key="error.username.required"/>
+        </field-validator>
+    </field>
+
+    <field name="password">
+        <field-validator type="requiredstring">
+            <message key="error.password.required"/>
+        </field-validator>
+        <field-validator type="stringlength">
+            <param name="trim">true</param>
+            <param name="minLength">5</param>
+            <param name="maxLength">10</param>
+            <message key="errors.range"/>
+        </field-validator>
+    </field>
+
+    <field name="password2">
+        <field-validator type="requiredstring">
+            <message key="error.password2.required"/>
+        </field-validator>
+    </field>
+
+    <field name="fullname">
+        <field-validator type="requiredstring">
+            <message key="error.fullName.required"/>
+        </field-validator>
+    </field>
+
+    <field name="fromaddress">
+        <field-validator type="requiredstring">
+            <message key="error.fromAddress.required"/>
+        </field-validator>
+        <field-validator type="email">
+            <message key="errors.email"/>
+        </field-validator>
+    </field>
+
+    <field name="replytoaddress">
+        <field-validator type="email">
+            <message key="errors.email"/>
+        </field-validator>
+    </field>
+
+    <validator type="expression">
+        <param name="expression">password eq password2</param>
+        <message key="error.password.match"/>
+    </validator>
+
+</validators>

Propchange: struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Registration-validation.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Registration.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Registration.java?rev=387521&view=auto
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Registration.java (added)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Registration.java Tue
Mar 21 05:21:47 2006
@@ -0,0 +1,145 @@
+package mailreader2;
+
+import com.opensymphony.util.BeanUtils;
+import org.apache.struts.apps.mailreader.dao.ExpiredPasswordException;
+import org.apache.struts.apps.mailreader.dao.User;
+import org.apache.struts.apps.mailreader.dao.UserDatabase;
+import org.apache.struts.apps.mailreader.dao.impl.memory.MemoryUser;
+
+
+/**
+ * <p> Provide an Edit method for retrieving an existing user, and a Save method for
updating or inserting a user.
+ * </p><p> Both methods utilize a RegistrationForm to obtain or expose User details.
If Save is used to create a user,
+ * additional validations ensure input is nominal. When a user is created, Save also handles
the initial logon. </p>
+ */
+public final class Registration extends MailreaderSupport {
+
+    /**
+     * <p>The confirmation password input field.</p>
+     */
+    private String password2 = null;
+
+
+    /**
+     * @return Returns the confirmationpassword.
+     */
+    public String getPassword2() {
+        return this.password2;
+    }
+
+    /**
+     * @param password2 The confirmation password to set.
+     */
+    public void setPassword2(String password2) {
+        this.password2 = password2;
+    }
+
+
+    /**
+     * <p>The username input field.</p>
+     */
+    private String username = null;
+
+
+    /**
+     * @return Returns the username.
+     */
+    public String getUsername() {
+        return this.username;
+    }
+
+    /**
+     * @param username The username to set.
+     */
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    // ---- Private Methods ----
+
+    /**
+     * <p> Verify input for creating a new user, create the user, and process the login.
</p>
+     *
+     * @return A new User and empty Errors if create succeeds, or null and Errors if create
fails
+     */
+    private User createUser(String username, String password) {
+
+        UserDatabase database = getDatabase();
+        User user;
+
+        try {
+
+            user = findUser(username, password);
+        }
+
+        catch (ExpiredPasswordException e) {
+            user = getUser(); // Just so that it is not null
+        }
+
+        if (user != null) {
+            this.addFieldError("username", "error.username.unique");
+            return null;
+        }
+
+        return database.createUser(username);
+    }
+
+    // ----- Public Methods ----
+
+
+    private boolean isCreating() {
+        User user = getUser();
+        if (null == user) {
+            return true;
+        }
+        return (null == user.getDatabase());
+    }
+
+    /**
+     * <p> Retrieve the User object to edit or null if the User does not exist, and
set an transactional token to later
+     * detect multiple Save commands. </p>
+     *
+     * @return The "Success" result for this mapping
+     * @throws Exception on any error
+     */
+    public String input() throws Exception {
+
+        if (isCreating()) {
+            User user = new MemoryUser(null, null);
+            setUser(user);
+            setTask(Constants.CREATE);
+        } else {
+            setTask(Constants.EDIT);
+        }
+
+        return INPUT;
+    }
+
+    /**
+     * <p> Insert or update a User object to the persistent store. </p><p>
If a User is not logged in, then a new User
+     * is created and automatically logged in. Otherwise, the existing User is updated. </p>
+     *
+     * @return The "Success" result for this mapping
+     * @throws Exception on any error
+     */
+    public String execute()
+            throws Exception {
+
+        boolean editing = Constants.EDIT.equals(getTask());
+        // Double check for user and database
+        editing = editing && (null != getUser()) && (null != getUser().getDatabase());
+
+        User user;
+        if (!editing) {
+            User input = getUser();
+            // Since user.username is immutable, we have to use a local property
+            user = createUser(getUsername(), input.getPassword());
+            BeanUtils.setValues(user, input, null);
+        }
+
+        saveUser();
+
+        return SUCCESS;
+    }
+
+}

Propchange: struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Registration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/java/xwork.xml
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/java/xwork.xml?rev=387521&r1=387520&r2=387521&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/xwork.xml (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/xwork.xml Tue Mar 21 05:21:47 2006
@@ -25,15 +25,17 @@
             <result>/pages/ChangePassword.jsp</result>
         </action>
 
-        <action name="MainMenu">
+        <action name="MainMenu" class="mailreader2.MainMenu">
             <result>/pages/MainMenu.jsp</result>
+            <result name="input">/pages/MainMenu.jsp</result>
         </action>
 
-        <action name="Registration">
-            <result name="edit">/pages/Registration.jsp</result>
+        <action name="Registration" class="mailreader2.Registration">
+            <result name="input">/pages/Registration.jsp</result>
+            <result type="chain">MainMenu</result>
         </action>
 
-        <action name="Logoff">
+        <action name="Logoff" class="mailreader2.Logoff">
             <result type="chain">Welcome</result>
         </action>
 

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Logon.jsp
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Logon.jsp?rev=387521&r1=387520&r2=387521&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Logon.jsp (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Logon.jsp Tue Mar 21 05:21:47
2006
@@ -9,12 +9,16 @@
 
 <body>
 
-<ww:form method="POST">
+<ww:form method="POST" validate="true">
     <ww:textfield label="%{getText('prompt.username')}" name="username"/>
 
     <ww:textfield label="%{getText('prompt.password')}" name="password"/>
 
     <ww:submit/>
+
+    <ww:reset/>
+
+    <ww:submit action="Welcome" value="%{getText('button.cancel')}" onclick="form.onsubmit=null"/>
 </ww:form>
 
 <jsp:include page="Footer.jsp"/>

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/MainMenu.jsp
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/MainMenu.jsp?rev=387521&r1=387520&r2=387521&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/MainMenu.jsp (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/MainMenu.jsp Tue Mar 21
05:21:47 2006
@@ -10,7 +10,7 @@
 <body>
 <h3><ww:text name="mainMenu.heading"/> <ww:property value="user.fullName"/></h3>
 <ul>
-    <li><a href="<ww:url action="Registration!edit" />">
+    <li><a href="<ww:url action="Registration!input" />">
         <ww:text name="mainMenu.registration"/>
     </a>
     </li>

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Registration.jsp
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Registration.jsp?rev=387521&r1=387520&r2=387521&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Registration.jsp (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Registration.jsp Tue Mar
21 05:21:47 2006
@@ -1,6 +1,46 @@
-<%@ page contentType="text/html;charset=UTF-8" language="java" %>
-<html>
-<head><title>Simple jsp page</title></head>
+<%@ taglib uri="/webwork" prefix="ww" %>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head><ww:if test="task=='Create'">
+    <title><ww:text name="registration.title.create"/></title>
+</ww:if>
+    <ww:if test="task=='Edit'">
+        <title><ww:text name="registration.title.edit"/></title>
+    </ww:if>
+</head>
 
-<body>Place your content here</body>
-</html>
\ No newline at end of file
+<body>
+
+<ww:form method="POST" validate="true">
+    <ww:hidden name="task"/>
+    <ww:if test="task == 'Create'">
+        <ww:textfield label="%{getText('prompt.username')}" name="username"/>
+    </ww:if>
+    <ww:else>
+        <ww:label label="%{getText('prompt.username')}" name="username"/>
+        <ww:hidden name="username"/>
+    </ww:else>
+
+    <ww:textfield label="%{getText('prompt.password')}" name="password"/>
+
+    <ww:textfield label="%{getText('prompt.password2')}" name="password2"/>
+
+    <ww:textfield label="%{getText('prompt.fullName')}" name="fullName"/>
+
+    <ww:textfield label="%{getText('prompt.fromAddress')}" name="fromAddress"/>
+
+    <ww:textfield label="%{getText('prompt.replyToAddress')}" name="replyToAddress"/>
+
+    <ww:submit/>
+
+    <ww:reset/>
+
+    <ww:submit action="Welcome" value="%{getText('button.cancel')}" onclick="form.onsubmit=null"/>
+
+</ww:form>
+
+<jsp:include page="Footer.jsp"/>
+
+</body>
+</html>

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Welcome.jsp
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Welcome.jsp?rev=387521&r1=387520&r2=387521&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Welcome.jsp (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Welcome.jsp Tue Mar 21 05:21:47
2006
@@ -12,7 +12,7 @@
 <h3><ww:text name="index.heading"/></h3>
 
 <ul>
-    <li><a href="<ww:url action="Registration!edit"/>"><ww:text name="index.registration"/></a></li>
+    <li><a href="<ww:url action="Registration!input"/>"><ww:text name="index.registration"/></a></li>
     <li><a href="<ww:url action="Logon!input"/>"><ww:text name="index.logon"/></a></li>
 </ul>
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Mime
View raw message