X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FEditProfileFieldPage.java;h=a71abdc013b84dcc2d1704fd9b94336e78184e09;hb=e01ceeed92f226bf74c9f516bce882b5cd816a62;hp=d4510e7a736257446cf9fa4db6db10d18f7e9d30;hpb=109f75c6995d2b673d5dcabe5c8b522722ba0635;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/EditProfileFieldPage.java b/src/main/java/net/pterodactylus/sone/web/EditProfileFieldPage.java index d4510e7..a71abdc 100644 --- a/src/main/java/net/pterodactylus/sone/web/EditProfileFieldPage.java +++ b/src/main/java/net/pterodactylus/sone/web/EditProfileFieldPage.java @@ -25,6 +25,8 @@ import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; import net.pterodactylus.util.web.Method; +import com.google.common.base.Optional; + /** * Page that lets the user edit the name of a profile field. * @@ -56,8 +58,8 @@ public class EditProfileFieldPage extends SoneTemplatePage { /* get parameters from request. */ String fieldId = request.getHttpRequest().getParam("field"); - Field field = profile.getFieldById(fieldId); - if (field == null) { + Optional field = profile.getFieldById(fieldId); + if (!field.isPresent()) { throw new RedirectException("invalid.html"); } @@ -68,13 +70,13 @@ public class EditProfileFieldPage extends SoneTemplatePage { } fieldId = request.getHttpRequest().getPartAsStringFailsafe("field", 36); field = profile.getFieldById(fieldId); - if (field == null) { + if (!field.isPresent()) { throw new RedirectException("invalid.html"); } String name = request.getHttpRequest().getPartAsStringFailsafe("name", 256); - Field existingField = profile.getFieldByName(name); - if ((existingField == null) || (existingField.equals(field))) { - profile.renameField(field, name); + Optional existingField = profile.getFieldByName(name); + if (!existingField.isPresent() || existingField.equals(field)) { + profile.renameField(field.get(), name); currentSone.setProfile(profile); throw new RedirectException("editProfile.html#profile-fields"); } @@ -82,7 +84,7 @@ public class EditProfileFieldPage extends SoneTemplatePage { } /* store current values in template. */ - templateContext.set("field", field); + templateContext.set("field", field.get()); } }