Pergunta

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

Foi útil?

Solução

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();
      }
    }
  }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top