Thanks to the great help I got from the Atlassian Developer Community here, I am able to connect to a SQL server DB using JDBC.
The connection and displaying values from SQL Server works fine already.
Now comes the next difficulty:
In my Jira Plugin, I would like to have
- a basic form
- with a visible text area,
- some hidden inputs and
- a submit button
By submitting I would like to
- INSERT INTO a new record into my DB and then
- call again the main action of the plugin which displays the values from the DB (including the newly created)
The form itself gets already displayed correctly.
Also to execute the INSERT INTO statement successfully from Eclipse works already.
Questions:
What I am currently struggling to understand is the following:
- How to pass values from the form to an action (my INSERT-INTO-action that then executes the SQL query)?
- How to redirect from one action to another action (from the INSERT-INTO-action to the main action that displays the content from the SQL DB)?
I’m used to ASP.NET where this is rather straight forward.
My form currently looks like this:
<form class="aui" name="commentForm" id="commentForm" action="postComment" method="post">
<input type="hidden" name="jiraKey" id="jiraKey" value=$jiraKey />
<input type="hidden" name="userName" id="userName" value=$user.displayName />
<textarea name="commentTextInput" id="commentTextInput" cols="60" rows="5" style="max-width: 100%;" value=$newComment></textarea>
<br />
<br />
<input type="submit" value="Post Comment"/>
</form>
My postComment Action looks like this:
public class postComment {
protected String userName;
protected String jiraKey;
protected String newComment;
protected String query;
protected String conUrl;
protected String timeStamp;
protected Boolean queryResult;
public postComment(String userName, String jiraKey, String newComment) {
this.userName = userName;
this.jiraKey = jiraKey;
this.newComment = newComment;
this.timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new java.util.Date());
if(jiraKey != null && !jiraKey.isEmpty())
{
try
{
conUrl = ConString.generateConString();
query = "INSERT INTO [dbo].[Comments] ([JiraKey],[UserID],[UserComment],[UserCommentDate],[UserCommentType]) VALUES ("
+ "'" + this.jiraKey + "',"
+ "'" + this.userName + "',"
+ "'" + this.newComment + "',"
+ "'" + this.timeStamp + "',"
+ "'1');";
queryResult = CommentToSQL.postComment(conUrl, query);
//YourAction.YourAction();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
And my main Action like this (ignore the default-naming :D):
public class YourAction extends AbstractIssueAction {
protected Issue issue;
protected ApplicationUser remoteUser;
protected String jiraKey;
protected ArrayList<Map<String, Object>> queryResult;
public YourAction(IssueTabPanelModuleDescriptor descriptor, Issue issue, ApplicationUser remoteUser) {
super(descriptor);
this.issue = issue;
this.remoteUser = remoteUser;
this.jiraKey = issue.getKey();
try
{
this.queryResult = CommentsArrayMap.getComments(this.jiraKey);
}
catch (SQLException e)
{
e.printStackTrace();
}
}
public Date getTimePerformed() {
return issue.getCreated();
}
protected void populateVelocityParams(Map params) {
params.put("action", this);
params.put("issue", issue);
params.put("user", remoteUser);
params.put("jiraKey", jiraKey);
params.put("queryResult", queryResult);
}
}