0

In my application, I select the user's name (using check box) and click "Export Data" button, which will open a pop-up (asking whether to export in PDF or CSV). I used jQueryUI to get the modal-dialog

the checkbox is in different form and the "Export Data" is out of that form, So when i hit an action-class using document.location.href am not able to get the checkbox values

This is how the checkbox is formed in JSP

<s:form action="dashboard" theme="simple">

<s:checkbox name="selectedStudents[%{#status.index}].studentId" id="student%{#status.index}" fieldValue="%{studentId}" value="0"/>

</s:form>

on click of "Export Data" button, i call the method (written in struts-2 action) from jquery. Please look the jquery code below

$(function() {
        $("#exportStudentReports").click(function(){
            $( "#exportModalWindow" ).dialog({
                resizable: false,
                height: 50,
                width: 200,
                modal: true,
                hide: "explode",
                buttons:{
                    "Export": function() {
                        var link = "/web/teacher/exportReport!exportStudentReports.action?exportType=pdf" ;
                        document.location.href=link;
                        $("#exportModalWindow").dialog("close");
                    }
                }
            });
            var isOpened = $("#exportModalWindow").dialog("isOpen") ;
            if (!isOpened) {
                $("#exportModalWindow").dialog("open");
            }
            $("#exportStuReportPDF").attr("checked","checked") ;
        });

    });

This is how my struts-action-configuration is

<action name="exportReport" class="com.hmco.ssms.action.teacher.ExportReportAction">
            <result name="studentReportPDF" type="stream">
                <param name="inputName">inputStream</param>
                <param name="contentType">application/pdf</param>
                <param name="contentDisposition">attachment;filename="sample.pdf"</param>
                <param name="bufferSize">1024</param>
            </result>
        </action>

Please help me on this. Thanks

Yotam Omer
  • 15,310
  • 11
  • 62
  • 65
Arun
  • 3,440
  • 11
  • 60
  • 108
  • 1
    on your jquery function I didn't see anything about the `selectedStudent`, how should it work. I'm not sure, but you should maybe make your `Export` button to submit a form, which contains the student id and call your export function. – Jaiwo99 Sep 03 '12 at 15:13
  • yes exactly jai. I should make that "Export" button to submit the form. But as you see, I couldn't configure the action's method and then submit the form. Mentoning strut's action-method before submitting the form, through javascript, is what am looking for – Arun Sep 03 '12 at 15:24
  • Basically, my student checkbox is in a form and i should submit that form from a button, which is not in that form. – Arun Sep 03 '12 at 15:26
  • Generally you should be able to formulate your question in a way that either is only struts2 related or only client related. Create some urls to send data from the browser and see what happens on the server, and what you get back (logging is your friend). If you know the server side to work, hide those details and you will find a much larger audience which can help. – Quaternion Sep 03 '12 at 19:32

1 Answers1

1

It seems simple:

JSP:

<s:form id="exportForm" action="exportStudentReports.action" theme="simple">
    <s:checkbox name="studentId" value="%{}"/>
</s:form>

<a onclick="openDialog()"/>

jQuery:

function openDialog(){
  $('#dialogWindow').dialog(){
    buttons: {
      "Export" : function(){
        $('#exportForm').submit();
      }
    }
  }
}
Jaiwo99
  • 9,687
  • 3
  • 36
  • 53