0

I have reportCriteria.jsp as follows:

<s:form action="showPdf" theme="css_xhtml" cssClass="form1small" name="reportgenerationform">
        <div id="searchHeaderReport">Generate Report</div>
        <div id="searchForm1">
            <s:select list="#application.proList" headerValue="Select" headerKey="select" label="Provider" id="providerId" name="providerName"></s:select>
            <div id="wwgrp_flightId" class="wwgrp">

                <div id="wwerr_showPdf_flightId" class="wwerr">
                    <div class="errorMessage">

                    </div>
                </div>
                <div id="wwlbl_flightId" class="wwlbl">
                    <label class="label" for="flightId"> Flight ID: </label>
                </div>
                <div id="wwctrl_flightId" class="wwctrl">
                    <select id="flightId" name="flightId">
                        <option selected="selected">select</option>
                    </select>   
                </div>
            </div>


            <div id="wwgrp_scheduleId" class="wwgrp">
                <div id="wwerr_showPdf_flightId" class="wwerr">
                    <div class="errorMessage">
                    </div>
                </div>
                <div id="wwlbl_flightId" class="wwlbl">
                    <label class="label" for="scheduleId"> Schedule ID: </label>
                </div>
                <div id="wwctrl_flightId" class="wwctrl">
                    <select id="scheduleId" name="scheduleId">
                        <option selected="selected">select</option>
                    </select>
                </div>
            </div>
            </div>
            <div id="submitdivid">
                    <sj:submit value="Generate Report" cssClass="orangebuttonsmall"/>
            </div>  
    </s:form>  

The struts.xml mapping is as follows:

    <action name="showPdf" class="com.view.ReportAction" method="showReport">
                        <result name="report" type="stream">
                            <param name="inputName">fileStream</param>
                            <param name="contentType">application/pdf</param>
                            <param name="contentDisposition">attachment;filename="PDF_Report.pdf"</param>
                        </result>
                        <result name="input">/reportCriteria.jsp</result>
                    </action>
<action name="flightMgmt" class="com.view.AdminAction" method="flightMgmt">
                <result name="flightMgmtClicked">/flightMgmt.jsp</result>
            </action>
<action name="reportGeneration" class="com.view.AdminAction" method="reportGeneration">
            <result name="reportGenerationClicked">/reportCriteria.jsp</result>
        </action>

Now if the method showReport returns "report", then the pdf content is loaded in encrypted form in div with id as "report_generation". When the method returns input, then it loads reportCriteria.jsp with errors in the div with id as "report_generation".

What i want to do is that when it returns error then the jsp must be loaded into that div but if the method returns "report" which it returns on success, then the file download box must appear as shown in result type="report" in struts.xml.

The following is "loginSuccessAdmin.jsp" that contains "report_generation" div :*

<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

    <s:url var="remoteurl1" action="flightMgmt"/>
    <s:url var="remoteurl2" action="reportGeneration"/>
    <s:url var="remoteurl3" action="dealMgmt"/>
    <sj:tabbedpanel id="remotetabs" selectedTab="0" collapsible="true">
        <sj:tab id="tab1" href="%{remoteurl1}" label="Flight Management"/>
        <sj:tab id="tab2" href="%{remoteurl2}" label="Report Generation"/>
        <sj:tab id="tab3" href="%{remoteurl3}" label="Deal Management"/>
    </sj:tabbedpanel>

</div>

The line <sj:tab id="tab2"> itself creates a div with id as report_generation.

Is there anything possible, that may accomplish my purpose.. Thanks in advance

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
Gaurav Kumar
  • 1,091
  • 13
  • 31
  • Where is `report_generation` div and how do you load content in there? – Aleksandr M Nov 13 '13 at 11:55
  • @AleksandrM Please check I have uploaded the edited code.. – Gaurav Kumar Nov 13 '13 at 12:19
  • Why not you request for file in the simple HTTP request? The response object is accommodated in the Javascript code, how would you like to send it to the browser? – Roman C Nov 13 '13 at 19:45
  • @RomanC If i request for file through a simple request then my file download purpose is resolved but if suppose any server side validation error occurs then a new jsp is loaded with those errors .. I want the error jsp to be loaded here in the same div only. – Gaurav Kumar Nov 14 '13 at 05:06
  • @GauravKumar You can use some interceptors to curry the validation errors with the action and then complete a request. – Roman C Nov 14 '13 at 09:01

1 Answers1

1

That's not possible.

Javascript can't download files to a user's computer unless you code some workaround. Like this guy here.

Don't use the same action for fileDownload and error, instead split in two with the first one telling whether the fileDownload will work and then accordingly you can call the second one with sureity of receiving a file or it can show you the errors which you can push in a div like you're doing now.

Community
  • 1
  • 1
coding_idiot
  • 13,526
  • 10
  • 65
  • 116