summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit
diff options
context:
space:
mode:
authorFlorian Zschocke <f.zschocke+git@gmail.com>2022-11-01 19:31:45 +0100
committerFlorian Zschocke <f.zschocke+git@gmail.com>2022-11-01 19:31:45 +0100
commit082c6a69b64f79b7c81a78f4b7bbf7a31d11cb74 (patch)
tree2d5db6d982848404f18f0e6acb1b8696749fba39 /src/main/java/com/gitblit
parent0e344ae98ebccc734d7142682bee0d488ea65c9d (diff)
downloadgitblit-082c6a69b64f79b7c81a78f4b7bbf7a31d11cb74.tar.gz
gitblit-082c6a69b64f79b7c81a78f4b7bbf7a31d11cb74.zip
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.
Diffstat (limited to 'src/main/java/com/gitblit')
-rw-r--r--src/main/java/com/gitblit/wicket/pages/BasePage.java2
-rw-r--r--src/main/java/com/gitblit/wicket/panels/SshKeysPanel.html3
-rw-r--r--src/main/java/com/gitblit/wicket/panels/SshKeysPanel.java19
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 @@
<div wicket:id="addKeyData"></div>
<div wicket:id="addKeyPermission"></div>
<div wicket:id="addKeyComment"></div>
-
+ <div wicket:id="addKeyFeedback"></div>
+
<div class="form-actions"><input class="btn btn-appmenu" type="submit" value="Add" wicket:message="value:gb.add" wicket:id="addKeyButton" /></div>
</form>
</div>
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<String> keyFeedback = Model.of("");
final List<SshKey> keys = new ArrayList<SshKey>(app().keys().getKeys(user.username));
final ListDataProvider<SshKey> dp = new ListDataProvider<SshKey>(keys);
final DataView<SshKey> keysView = new DataView<SshKey>("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.");
}
});