mardi 8 novembre 2016

Redirect a HTML form POST submit for whole page

I am developing a plugin for JIRA with the Atlassian Plugin SDK. The first module of this plugin shows an additional panel in the user profile view of JIRA. It also provides the possibility to open a dialog to edit the information in shown in the mentioned panel. Therefor I created a servlet, which offers a GET and a POST method. At the moment, the GET method provides the HTML form to alter the information and I planned to use the POST method to receive the new data. This all works fine.

Now I want to imitate the look and feel of the JIRA platform. The user profile opens the forms for editing the regular panels in dialogs (on top of the profile page) and these dialogs disappear, when you click either OK or Cancel. I achieved to show my form in a dialog, too (with an ugly hack so far), but when I click OK on my form, the user profile is loaded a second time in the dialog area. When I click the Cancel button, the dialog disappears and I see the profile page (desired behaviour).

How can I achieve to load the result of the form POST submit on the whole page?

My servlet:

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // Reading parameters and validation stuff
    ...
    // Render the HTML for edits
    String html = this.TemplateRenderer.getBody("view/", "profile-edit.vm", templateContext);
    // Send response
    response.setStatus(SC_OK);
    response.setContentType("text/html");
    response.getWriter().write(html);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // Reading parameters and validation stuff
    ...
    // Actually work with the data
    ...
    // Return to the user profile
    response.sendRedirect("/jira/secure/ViewProfile.jspa?username=" + username);
}

My Velocity template for the form:

<form class="aui" method="post" action="/jira/plugins/servlet/EditTTC">
<div class="form-body">
    <h2>Zeitabgleichsdaten aktualisieren</h2>
    <div class="field-group">
        <label for="update-ttc-number">Personalnummer</label>
        <input type="hidden" name="username" value="$username">
        <input id="update-ttc-number" class="text" maxlength="10" name="ttcNumber" value="#if($ttcNumber)$ttcNumber#end" type="text" />
    </div>
</div>
<div class="buttons-container form-footer">
    <div class="buttons">
        <input id="update-submit" class="aui-button" value="Aktualisieren" type="submit" value="Submit" />
        <a id="update-cancel" class="aui-button aui-button-link cancel" href="/jira/secure/ViewProfile.jspa?username=$username">Abbrechen</a>
    </div>
</div>
</form>

When submitting (update-submit) the data and then redirecting over the servlet, the profile page is loaded into the dialog, but the Cancel button (update-cancel) causes the profile page to be loaded in the whole browser window.

I'm gonna add an image of the two different behaviors, but JIRA takes a huge amount of time to load ...




Aucun commentaire:

Enregistrer un commentaire