Assign a name to the save button, react only to that name.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 12 Jan 2011 11:19:51 +0000 (12:19 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 12 Jan 2011 11:19:51 +0000 (12:19 +0100)
src/main/java/net/pterodactylus/sone/web/EditProfilePage.java
src/main/resources/templates/editProfile.html

index 87f7aef..1183100 100644 (file)
@@ -63,18 +63,20 @@ public class EditProfilePage extends SoneTemplatePage {
                Integer birthMonth = profile.getBirthMonth();
                Integer birthYear = profile.getBirthYear();
                if (request.getMethod() == Method.POST) {
-                       firstName = request.getHttpRequest().getPartAsStringFailsafe("first-name", 256).trim();
-                       middleName = request.getHttpRequest().getPartAsStringFailsafe("middle-name", 256).trim();
-                       lastName = request.getHttpRequest().getPartAsStringFailsafe("last-name", 256).trim();
-                       birthDay = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("birth-day", 256).trim());
-                       birthMonth = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("birth-month", 256).trim());
-                       birthYear = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("birth-year", 256).trim());
-                       profile.setFirstName(firstName.length() > 0 ? firstName : null);
-                       profile.setMiddleName(middleName.length() > 0 ? middleName : null);
-                       profile.setLastName(lastName.length() > 0 ? lastName : null);
-                       profile.setBirthDay(birthDay).setBirthMonth(birthMonth).setBirthYear(birthYear);
-                       currentSone.setProfile(profile);
-                       throw new RedirectException("index.html");
+                       if (request.getHttpRequest().getPartAsStringFailsafe("saveProfile", 4).equals("true")) {
+                               firstName = request.getHttpRequest().getPartAsStringFailsafe("first-name", 256).trim();
+                               middleName = request.getHttpRequest().getPartAsStringFailsafe("middle-name", 256).trim();
+                               lastName = request.getHttpRequest().getPartAsStringFailsafe("last-name", 256).trim();
+                               birthDay = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("birth-day", 256).trim());
+                               birthMonth = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("birth-month", 256).trim());
+                               birthYear = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("birth-year", 256).trim());
+                               profile.setFirstName(firstName.length() > 0 ? firstName : null);
+                               profile.setMiddleName(middleName.length() > 0 ? middleName : null);
+                               profile.setLastName(lastName.length() > 0 ? lastName : null);
+                               profile.setBirthDay(birthDay).setBirthMonth(birthMonth).setBirthYear(birthYear);
+                               currentSone.setProfile(profile);
+                               throw new RedirectException("index.html");
+                       }
                }
                template.set("firstName", firstName);
                template.set("middleName", middleName);
index d1d5943..d2dc61a 100644 (file)
@@ -71,7 +71,7 @@
                </div>
 
                <div>
-                       <button type="submit"><%= Page.EditProfile.Button.Save|l10n|html></button>
+                       <button type="submit" name="saveProfile" value="true"><%= Page.EditProfile.Button.Save|l10n|html></button>
                </div>
 
        </form>