Add feedback to SSH Key Form. #1226

if key is empty of can not be parsed, form did provide any feedback to
user before
diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
index c46bd63..d8a5894 100644
--- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
+++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
@@ -739,6 +739,8 @@
 gb.sshKeys = SSH Keys
 gb.sshKeysDescription = SSH public key authentication is a secure alternative to password authentication
 gb.addSshKey = Add SSH Key
+gb.addSshKeyErrorEmpty = SSH public key empty. Please provide a valid SSH public key
+gb.addSshKeyErrorFormat = Not a valid SSH public key format. Please provide a valid SSH public key
 gb.key = Key
 gb.comment = Comment
 gb.sshKeyCommentDescription = Enter an optional comment. If blank, the comment will be extracted from the key data.
diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp_de.properties b/src/main/java/com/gitblit/wicket/GitBlitWebApp_de.properties
index 9599f7e..3f873cc 100644
--- a/src/main/java/com/gitblit/wicket/GitBlitWebApp_de.properties
+++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp_de.properties
@@ -736,6 +736,8 @@
 gb.sshKeys = SSH Keys
 gb.sshKeysDescription = SSH Public Key Authentifizierung ist eine sichere Alternative zur Authentifizierung mit Passwort
 gb.addSshKey = SSH Key hinzuf\u00fcgen
+gb.addSshKeyErrorEmpty = SSH Public Key leer. Bitte geben Sie einen g\u00fltigen SSH Public Key an
+gb.addSshKeyErrorFormat = SSH Public Key Format ungültig. Bitte geben Sie einen g\u00fltigen SSH Public Key an
 gb.key = Key
 gb.comment = Kommentar
 gb.sshKeyCommentDescription = Geben Sie optional einen Kommentar ein. Falls Sie dies nicht tun, wird der Kommentar aus dem Key extrahiert.
diff --git a/src/main/java/com/gitblit/wicket/pages/BasePage.java b/src/main/java/com/gitblit/wicket/pages/BasePage.java
index 0d99f5e..bb97ee8 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 @@
 		add(rootLink);

 

 		// Feedback panel for info, warning, and non-fatal error messages

-		add(new FeedbackPanel("feedback"));

+		add(new FeedbackPanel("feedback").setOutputMarkupId(true));

 

 		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.java b/src/main/java/com/gitblit/wicket/panels/SshKeysPanel.java
index 4b87876..629c58e 100644
--- a/src/main/java/com/gitblit/wicket/panels/SshKeysPanel.java
+++ b/src/main/java/com/gitblit/wicket/panels/SshKeysPanel.java
@@ -24,6 +24,7 @@
 import org.apache.wicket.ajax.markup.html.form.AjaxButton;

 import org.apache.wicket.markup.html.basic.Label;

 import org.apache.wicket.markup.html.form.Form;

+import org.apache.wicket.markup.html.panel.FeedbackPanel;

 import org.apache.wicket.markup.repeater.Item;

 import org.apache.wicket.markup.repeater.data.DataView;

 import org.apache.wicket.markup.repeater.data.ListDataProvider;

@@ -123,6 +124,9 @@
 				"span5",

 				keyComment));

 

+//		final FeedbackPanel feedback = new FeedbackPanel("feedback");

+//		feedback.setOutputMarkupId(true);

+//		addKeyForm.add(feedback);

 		addKeyForm.add(new AjaxButton("addKeyButton") {

 

 			private static final long serialVersionUID = 1L;

@@ -134,6 +138,8 @@
 				String data = keyData.getObject();

 				if (StringUtils.isEmpty(data)) {

 					// do not submit empty key

+					error(getString("gb.addSshKeyErrorEmpty"));

+					target.addComponent(getPage().get("feedback"));

 					return;

 				}

 

@@ -142,6 +148,8 @@
 					key.getPublicKey();

 				} catch (Exception e) {

 					// failed to parse the key

+					error(getString("gb.addSshKeyErrorFormat"));

+					target.addComponent(getPage().get("feedback"));

 					return;

 				}