struts-dev mailing list archives

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

URL: http://svn.apache.org/viewcvs?rev=387725&view=rev
Log:
Action2 Apps
* Mailreader - Work in progress
** Switch from "model driven" to POJOs to work around DAO quirks. 

Modified:
    struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Logon.java
    struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MailreaderSupport.java
    struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Registration-validation.xml
    struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Registration.java
    struts/sandbox/trunk/action2/apps/mailreader/src/java/xwork.xml
    struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Registration.jsp

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Logon.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Logon.java?rev=387725&r1=387724&r2=387725&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Logon.java (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Logon.java Tue Mar 21
21:05:41 2006
@@ -27,48 +27,6 @@
  */
 public final class Logon extends MailreaderSupport {
 
-    // -------------------------------------------------------------- Properties
-
-    /**
-     * <p>The password input field.</p>
-     */
-    private String password = null;
-
-
-    /**
-     * @return Returns the password.
-     */
-    public String getPassword() {
-        return this.password;
-    }
-
-    /**
-     * @param password The password to set.
-     */
-    public void setPassword(String password) {
-        this.password = password;
-    }
-
-    /**
-     * <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;
-    }
-
     /**
      * <p> Use "username" and "password" fields to retrieve a User object from the
database. If credentials are not
      * valid, or database has disappeared, post error messages and forward to input. </p>

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=387725&r1=387724&r2=387725&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 21:05:41 2006
@@ -21,7 +21,6 @@
 import com.opensymphony.webwork.interceptor.ApplicationAware;
 import com.opensymphony.webwork.interceptor.SessionAware;
 import com.opensymphony.xwork.ActionSupport;
-import com.opensymphony.xwork.ModelDriven;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.struts.apps.mailreader.dao.ExpiredPasswordException;
@@ -32,13 +31,16 @@
 import java.util.Map;
 
 /**
- * <p> Base Action for MailreaderSupport application. </p><p> All the BaseAction
helper methods are prefixed with "do"
- * so that they can be easily distinguished from Struts and Servlet API methods. BaseAction
subclasses may also have
- * prive "do" helpers of their own. </p><p> Methods are kept in alphabetical
order, to make them easier to find. </p>
+ * <p> Base Action for MailreaderSupport application. </p>
+ *
+ * <p> Note that this class does NOT implement model driven because of issues with
the pre-existing model. The
+ * MailReader DAO does not provide a setter for username and does not provide a default constructor,
making it difficult
+ * to use as a POJO or to extend. As an alternative, the username and password properties
are provided on the Action and
+ * then passed to the user class as needed. </p>
  *
  * @version $Rev: 360442 $ $Date: 2005-12-31 15:10:04 -0500 (Sat, 31 Dec 2005) $
  */
-public abstract class MailreaderSupport extends ActionSupport implements ModelDriven, SessionAware,
ApplicationAware {
+public class MailreaderSupport extends ActionSupport implements SessionAware, ApplicationAware
{
 
     // ---- ApplicationAware ----
 
@@ -64,10 +66,92 @@
         return session;
     }
 
-    // ---- ModelDriven ----
+    // ---- Task property (utilized by UI) ----
+
+    /**
+     * <p>The task input field.</p>
+     */
+    private String task = null;
+
+
+    /**
+     * @return Returns the task.
+     */
+    public String getTask() {
+        return this.task;
+    }
+
+    /**
+     * @param task The task to set.
+     */
+    public void setTask(String task) {
+        this.task = task;
+    }
+
+    // ---- Password property ----
+
+    /**
+     * <p>The password input field.</p>
+     */
+    private String password = null;
+
+
+    /**
+     * @return Returns the password.
+     */
+    public String getPassword() {
+        return this.password;
+    }
+
+    /**
+     * @param password The password to set.
+     */
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    // ---- Password2 property (confirmation) ----
+
+    /**
+     * <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;
+    }
+
+    // ---- Username property ----
+
+    /**
+     * <p>The username input field.</p>
+     */
+    private String username = null;
+
+
+    /**
+     * @return Returns the username.
+     */
+    public String getUsername() {
+        return this.username;
+    }
 
-    public Object getModel() {
-        return getSession().get(Constants.USER_KEY);
+    /**
+     * @param username The username to set.
+     */
+    public void setUsername(String username) {
+        this.username = username;
     }
 
     // ---- Database property ----
@@ -92,7 +176,7 @@
     // ---- User property ----
 
     public User getUser() {
-        return (User) getModel();
+        return (User) getSession().get(Constants.USER_KEY);
     }
 
     public void setUser(User user) {
@@ -148,26 +232,6 @@
 
     protected void getSubscriprtion(Subscription subscription) {
         getSession().put(Constants.SUBSCRIPTION_KEY, subscription);
-    }
-
-    /**
-     * <p>The task input field.</p>
-     */
-    private String task = null;
-
-
-    /**
-     * @return Returns the task.
-     */
-    public String getTask() {
-        return this.task;
-    }
-
-    /**
-     * @param task The task to set.
-     */
-    public void setTask(String task) {
-        this.task = task;
     }
 
 

Modified: 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=387725&r1=387724&r2=387725&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Registration-validation.xml
(original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Registration-validation.xml
Tue Mar 21 21:05:41 2006
@@ -14,7 +14,7 @@
         </field-validator>
         <field-validator type="stringlength">
             <param name="trim">true</param>
-            <param name="minLength">5</param>
+            <param name="minLength">4</param>
             <param name="maxLength">10</param>
             <message key="errors.range"/>
         </field-validator>
@@ -26,13 +26,13 @@
         </field-validator>
     </field>
 
-    <field name="fullname">
+    <field name="user.fullName">
         <field-validator type="requiredstring">
             <message key="error.fullName.required"/>
         </field-validator>
     </field>
 
-    <field name="fromaddress">
+    <field name="user.fromAddress">
         <field-validator type="requiredstring">
             <message key="error.fromAddress.required"/>
         </field-validator>
@@ -41,15 +41,17 @@
         </field-validator>
     </field>
 
-    <field name="replytoaddress">
+    <field name="user.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>

Modified: 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=387725&r1=387724&r2=387725&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Registration.java (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Registration.java Tue
Mar 21 21:05:41 2006
@@ -14,47 +14,6 @@
  */
 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 ----
 
     /**
@@ -86,13 +45,9 @@
 
     // ----- Public Methods ----
 
-
     private boolean isCreating() {
         User user = getUser();
-        if (null == user) {
-            return true;
-        }
-        return (null == user.getDatabase());
+        return (null == user) || (null == user.getDatabase());
     }
 
     /**
@@ -110,6 +65,9 @@
             setTask(Constants.CREATE);
         } else {
             setTask(Constants.EDIT);
+            setUsername(getUser().getUsername());
+            setPassword(getUser().getPassword());
+            setPassword2(getUser().getPassword());
         }
 
         return INPUT;
@@ -125,16 +83,17 @@
     public String execute()
             throws Exception {
 
-        boolean editing = Constants.EDIT.equals(getTask());
-        // Double check for user and database
-        editing = editing && (null != getUser()) && (null != getUser().getDatabase());
+        boolean creating = Constants.CREATE.equals(getTask());
+        creating = creating && isCreating(); // trust but verify
 
         User user;
-        if (!editing) {
+        if (creating) {
             User input = getUser();
-            // Since user.username is immutable, we have to use a local property
-            user = createUser(getUsername(), input.getPassword());
+            // Since user.username is immutable, we have to use some local properties
+            user = createUser(getUsername(), getPassword());
+            input.setPassword(getPassword());
             BeanUtils.setValues(user, input, null);
+            setUser(user);
         }
 
         saveUser();

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=387725&r1=387724&r2=387725&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 21:05:41 2006
@@ -25,7 +25,7 @@
             <result>/pages/ChangePassword.jsp</result>
         </action>
 
-        <action name="MainMenu" class="mailreader2.MainMenu">
+        <action name="MainMenu" class="mailreader2.MailreaderSupport">
             <result>/pages/MainMenu.jsp</result>
             <result name="input">/pages/MainMenu.jsp</result>
         </action>

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=387725&r1=387724&r2=387725&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 21:05:41 2006
@@ -12,7 +12,7 @@
 
 <body>
 
-<ww:form method="POST" validate="true">
+<ww:form method="POST" validate="false">
     <ww:hidden name="task"/>
     <ww:if test="task == 'Create'">
         <ww:textfield label="%{getText('prompt.username')}" name="username"/>
@@ -26,17 +26,22 @@
 
     <ww:textfield label="%{getText('prompt.password2')}" name="password2"/>
 
-    <ww:textfield label="%{getText('prompt.fullName')}" name="fullName"/>
+    <ww:textfield label="%{getText('prompt.fullName')}" name="user.fullName"/>
 
-    <ww:textfield label="%{getText('prompt.fromAddress')}" name="fromAddress"/>
+    <ww:textfield label="%{getText('prompt.fromAddress')}" name="user.fromAddress"/>
 
-    <ww:textfield label="%{getText('prompt.replyToAddress')}" name="replyToAddress"/>
+    <ww:textfield label="%{getText('prompt.replyToAddress')}" name="user.replyToAddress"/>
 
     <ww:submit/>
 
     <ww:reset/>
 
-    <ww:submit action="Welcome" value="%{getText('button.cancel')}" onclick="form.onsubmit=null"/>
+    <ww:if test="task == 'Create'">
+        <ww:submit action="Welcome" value="%{getText('button.cancel')}" onclick="form.onsubmit=null"/>
+    </ww:if>
+    <ww:else>
+        <ww:submit action="MainMenu" value="%{getText('button.cancel')}" onclick="form.onsubmit=null"/>
+    </ww:else>
 
 </ww:form>
 



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


Mime
View raw message