From 082c6a69b64f79b7c81a78f4b7bbf7a31d11cb74 Mon Sep 17 00:00:00 2001 From: Florian Zschocke Date: Tue, 1 Nov 2022 19:31:45 +0100 Subject: [PATCH] Replace key feedback with label instead of FeedbackMessage Since it is a pest to get rid of a Wicket FeedbackMessage in an AJAX target, change the code to use an extra label that can provide feedback if the key could not be parsed or was empty. --- .../com/gitblit/wicket/pages/BasePage.java | 2 +- .../gitblit/wicket/panels/SshKeysPanel.html | 3 ++- .../gitblit/wicket/panels/SshKeysPanel.java | 19 +++++++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/gitblit/wicket/pages/BasePage.java b/src/main/java/com/gitblit/wicket/pages/BasePage.java index bb97ee8c..0d99f5e5 100644 --- a/src/main/java/com/gitblit/wicket/pages/BasePage.java +++ b/src/main/java/com/gitblit/wicket/pages/BasePage.java @@ -251,7 +251,7 @@ public abstract class BasePage extends SessionPage { add(rootLink); // Feedback panel for info, warning, and non-fatal error messages - add(new FeedbackPanel("feedback").setOutputMarkupId(true)); + add(new FeedbackPanel("feedback")); add(new Label("gbVersion", "v" + Constants.getVersion())); if (app().settings().getBoolean(Keys.web.aggressiveHeapManagement, false)) { diff --git a/src/main/java/com/gitblit/wicket/panels/SshKeysPanel.html b/src/main/java/com/gitblit/wicket/panels/SshKeysPanel.html index d67b704a..b6ae3ea1 100644 --- a/src/main/java/com/gitblit/wicket/panels/SshKeysPanel.html +++ b/src/main/java/com/gitblit/wicket/panels/SshKeysPanel.html @@ -37,7 +37,8 @@
- +
+
diff --git a/src/main/java/com/gitblit/wicket/panels/SshKeysPanel.java b/src/main/java/com/gitblit/wicket/panels/SshKeysPanel.java index 9bcb2127..e653a64f 100644 --- a/src/main/java/com/gitblit/wicket/panels/SshKeysPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/SshKeysPanel.java @@ -19,6 +19,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import com.gitblit.wicket.WicketUtils; +import org.apache.wicket.Component; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.AjaxLink; import org.apache.wicket.ajax.markup.html.form.AjaxButton; @@ -63,6 +65,7 @@ public class SshKeysPanel extends BasePanel { setOutputMarkupId(true); + final IModel keyFeedback = Model.of(""); final List keys = new ArrayList(app().keys().getKeys(user.username)); final ListDataProvider dp = new ListDataProvider(keys); final DataView keysView = new DataView("keys", dp) { @@ -90,6 +93,7 @@ public class SshKeysPanel extends BasePanel { // update the panel target.addComponent(SshKeysPanel.this); } + keyFeedback.setObject(""); } }; if (!canWriteKeys) { @@ -123,6 +127,10 @@ public class SshKeysPanel extends BasePanel { "span5", keyComment)); + Component addKeyFeedback = new Label("addKeyFeedback", keyFeedback).setOutputMarkupId(true); + WicketUtils.setCssStyle(addKeyFeedback, "color: red; font-weight: bold;"); + addKeyForm.add(addKeyFeedback); + addKeyForm.add(new AjaxButton("addKeyButton") { private static final long serialVersionUID = 1L; @@ -134,8 +142,8 @@ public class SshKeysPanel extends BasePanel { String data = keyData.getObject(); if (StringUtils.isEmpty(data)) { // do not submit empty key - error(getString("gb.addSshKeyErrorEmpty")); - target.addComponent(getPage().get("feedback")); + keyFeedback.setObject(getString("gb.addSshKeyErrorEmpty")); + target.addComponent(addKeyFeedback); return; } @@ -144,8 +152,8 @@ public class SshKeysPanel extends BasePanel { key.getPublicKey(); } catch (Exception e) { // failed to parse the key - error(getString("gb.addSshKeyErrorFormat")); - target.addComponent(getPage().get("feedback")); + keyFeedback.setObject(getString("gb.addSshKeyErrorFormat")); + target.addComponent(addKeyFeedback); return; } @@ -167,9 +175,12 @@ public class SshKeysPanel extends BasePanel { keys.clear(); keys.addAll(app().keys().getKeys(user.username)); + keyFeedback.setObject(""); + // update the panel target.addComponent(SshKeysPanel.this); } + else keyFeedback.setObject("Key not added."); } }); -- 2.39.5