cancel
Showing results for 
Search instead for 
Did you mean: 

Write file to client...........browser error

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

This post is in reference to this post.....

I am able to "generate" a text file and have a dialog box where the user can "Open" or "Save" the file. Problem is that when clicking save and then going back to the iview, none of the navigation works, unless you refresh. I am getting some kind of broswer error in the lower left hand corner of IE. Can anyone point me in the right direction? Much Appreciation.

Regards,

Rich Heilman

Accepted Solutions (1)

Accepted Solutions (1)

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

I have the following class.



package com.rl.woa.orderstatus;

import java.io.*;
import javax.servlet.http.*;
import com.sapportals.portal.prt.component.*;

public class ExtractPC extends AbstractPortalComponent {

public OrderExtract orderExtract;

	public void doContent( 
		IPortalComponentRequest request,
		IPortalComponentResponse response) {

		HttpServletResponse res = request.getServletResponse(true);

		try {

			//		res.setContentType("attachment;file="Test.txt");
			res.setHeader(
				"Content-Disposition",
				"attachment;	filename="Test.txt"");
			//		res.setHeader ("Content-Disposition", "attachment;	filename="Test.csv"");

			try {

				PrintWriter out = res.getWriter();

				for (int i = 1; i <= 100; i++) {
					out.println( 
						"LineA " + i + "," + 
                        "LineB " + i + "," + 
					    "LineC " + i + "," + 
					    "LineD " + i + "," + 
					    "LineE " + i + "," + 
				    	"LineF " + i + ",");

				}
				out.flush();
				out.close();
			} catch (Exception e) {
				System.out.println(e);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

	}


// this is where you will pass the data from the OrderStatusNav class
   public void passExtractData(OrderExtract imOrderExtract){
   
	orderExtract = imOrderExtract;
   
   }
   	

}


In my main iView driver class, I have the this method which is connected to a button on the JSP.



		public void onDownloadClick(Event event) throws PageException {

			// Grab selections from screen elements
			setUserSelectionInputExtractTab();
			retrieveExtractData();

			// Perform extract to client
			ExtractPC epc = new ExtractPC();

			request = (IPortalComponentRequest) this.getRequest();
			response = (IPortalComponentResponse) this.getResponse();

		    epc.passExtractData(orderStatusUI.getOrderExtract());
			epc.doContent(request, response);

			state = INITIAL_STATE;

		}

I'm not sure on how to handle this.

Regards,

Rich Heilman

Former Member
0 Kudos

Hi Rich,

You can do all of these via javascript. Post your JSP and i will show you the changes you need in you JSP.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Here is my jsp, this is an include jsp.



  <hbj:formLayout id="ES1" marginTop="15px" marginRight="3px" marginBottom="0px"
	    marginLeft="5px" width="100%" >

	 <hbj:formLayoutRow id="ESRow1" paddingTop="5px" >
	 
			<hbj:formLayoutCell id="ES11" align="LEFT" paddingLeft="3" paddingTop="1" paddingRight="10" width="29%">
                 <hbj:label  id="label_InputName1" text="Customer Sold-To" labelFor="InputName"
                             required="TRUE" design="LABEL" tooltip="Customer Sold-To" width="25" />
			</hbj:formLayoutCell> 

			<hbj:formLayoutCell id="ES12" align="LEFT" paddingLeft="3" paddingTop="1" paddingRight="10" width="70%">
			     <hbj:dropdownListBox id="CUSTNOX"  tooltip="Customer Number"  width="230"
			                        model="orderStatusUI.SoldToDlModel" selection="<%=orderStatusUI.getCustomerNumberX()%>"
                                    disabled="false" nameOfKeyColumn="KeyCol"  nameOfValueColumn="KeyVal">
              </hbj:dropdownListBox>
			</hbj:formLayoutCell>
			
    </hbj:formLayoutRow>

    <hbj:formLayoutRow id="ESRow2" paddingTop="5px" >
	 
			<hbj:formLayoutCell id="ES21" align="LEFT" paddingLeft="3" paddingTop="1" paddingRight="10" width="20%">
                 <hbj:label  id="label_InputName2" text="Yorktowne Order Number" labelFor="InputName"
                             required="FALSE" design="LABEL" tooltip="Yorktowne Sales Order Number" width="25" />
			</hbj:formLayoutCell> 

			<hbj:formLayoutCell id="ES22" align="LEFT" paddingLeft="3" paddingTop="1" paddingRight="10" width="20%">
                 <hbj:inputField id="SALEDCX" type="STRING" maxlength="10"
                                 design="STANDARD"  size="10" tooltip="Yorktowne Sales Order Number" 
                                 value="<%=orderStatusUI.getSalesDocNumberX()%>"/>
			</hbj:formLayoutCell>
			
     </hbj:formLayoutRow>

	 <hbj:formLayoutRow id="ESRow3" paddingTop="5px" >
	 
			<hbj:formLayoutCell id="ES31" align="LEFT" paddingLeft="3" paddingTop="1" paddingRight="10" width="20%">
                 <hbj:label  id="label_InputName3" text="Customer P.O. Number" labelFor="InputName"
                             required="FALSE" design="LABEL" tooltip="Customer P.O. Number" width="25" />
			</hbj:formLayoutCell> 

			<hbj:formLayoutCell id="ES32" align="LEFT" paddingLeft="3" paddingTop="1" paddingRight="10" width="20%">
                 <hbj:inputField id="CUSTPOX" type="STRING" maxlength="10"
                                 design="STANDARD"  size="10" tooltip="Customer P.O. Number"
                                 value="<%=orderStatusUI.getCustPoNumberX()%>" />
			</hbj:formLayoutCell>
			
     </hbj:formLayoutRow>

  </hbj:formLayout>

  <hbj:formLayout id="ES2" marginTop="0px" marginRight="3px" marginBottom="5px"
	    marginLeft="5px" width="40%" >

	 <hbj:formLayoutRow id="ESRow4" paddingTop="5px" >
	 
			<hbj:formLayoutCell id="ES41" align="LEFT" paddingLeft="3" paddingTop="1" paddingRight="10" width="20%">
                 <hbj:label  id="label_InputName4" text="Order Entry Date" labelFor="InputName"
                             required="FALSE" design="LABEL" tooltip="Order Entry Date" width="25" />
			</hbj:formLayoutCell> 

			<hbj:formLayoutCell id="ES42" align="LEFT" paddingLeft="47" paddingTop="1" paddingRight="10" width="20%">
                 <hbj:inputField id="SENTDATX" type="DATE" maxlength="10" showHelp="True"
                                 design="STANDARD"  size="10" tooltip="Order Entry Date - Low" 
                                 value="<%=orderStatusUI.getSOrderEntDateX()%>" />
			</hbj:formLayoutCell>

			<hbj:formLayoutCell id="ES43" align="LEFT" paddingLeft="3" paddingTop="1" paddingRight="10" width="20%">
                                <hbj:textView id="Text1" text="To" />
			</hbj:formLayoutCell> 

			<hbj:formLayoutCell id="ES44" align="LEFT" paddingLeft="3" paddingTop="1" paddingRight="10" width="20%">
                 <hbj:inputField id="EENTDATX" type="DATE" maxlength="10" showHelp="True"
                                 design="STANDARD"  size="10" tooltip="Order Entry Date - High" 
                                 value="<%=orderStatusUI.getEOrderEntDateX()%>" />
			</hbj:formLayoutCell>

     </hbj:formLayoutRow>	

	 <hbj:formLayoutRow id="ESRow5" paddingTop="5px" >

			<hbj:formLayoutCell id="ES51" align="LEFT" paddingLeft="3" paddingTop="1" paddingRight="10" width="20%">
                 <hbj:label  id="label_InputName3" text="Order Status" labelFor="InputName"
                             required="FALSE" design="LABEL" tooltip="Order Status" width="25" />
			</hbj:formLayoutCell> 

			<hbj:formLayoutCell id="ES52" align="LEFT" paddingLeft="47" paddingTop="1" paddingRight="10" width="20%">
            
               <hbj:dropdownListBox id="ORDSTSX"  tooltip="Order Status"  selection="<%=orderStatusUI.getOrderStatusX()%>"
                                    disabled="false" nameOfKeyColumn="KeyCol"  nameOfValueColumn="KeyVal">
                   <hbj:listBoxItem key=" " value=" "    />
                   <hbj:listBoxItem key="SH" value="Shipped"    />
                   <hbj:listBoxItem key="IP" value="In Production"    />
                   <hbj:listBoxItem key="AC" value="Accepted"      />
               </hbj:dropdownListBox>

			</hbj:formLayoutCell>
			
     </hbj:formLayoutRow>

  </hbj:formLayout>

<br>

<hbj:button	id="btnDownload" encode="FALSE" tooltip="Download Now" onClick="DownloadClick">
		<%
		btnDownload.setText("<img src=""+componentRequest.getWebResourcePath() + "/images/download.gif" align="left" border=0>&nbspDownload");
		%>
</hbj:button>

Regards,

Rich Heilman

Former Member
0 Kudos

add the following lines to your JSP code.

<b>

<script>
function openfile()
{
  <%
  IPortalComponentURI componentURI = componentRequest.createPortalComponentURI ();
  componentURI.setContextName("com.rl.woa.orderstatus.ExtractPC");
  String searchComponentURI = componentURI.toString();
  %>
 var url = "<%=searchComponentURI%>";
 window.open( url, "_blank");
}
</script>

</b>

Modify your button tag so that it does client side event but not the server side.

<hbj:button	id="btnDownload" encode="FALSE" tooltip="Download Now"  <b>onClientClick="openfile()"></b>
		<%
		btnDownload.setText("<img src=""+componentRequest.getWebResourcePath() + "/images/download.gif" align="left" border=0>&nbspDownload");
		%>
</hbj:button>

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

I'm getting an error saying that it can't find the iview "com.rl.woa.orderstatus.ExtractPC"

Regards,

Rich Heilman

Former Member
0 Kudos

Your portalapp.xml is missing the definition for ExtractPC. Post your portalapp.xml for com.rl.woa.orderstatus par.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

We only have one portalapp.xml file for our company, one .par for our company, its big. Here is the order status part of it.



<component name="OrderStatus">
<component-config>
<property name="ClassName" value="com.rl.woa.orderstatus.OrderStatusNav"/>
<property name="SecurityZone" value="com.sap.portal.ep50/ep50_safety"/>
</component-config>
<component-profile>
<property name="visibleRowCount" value="13">
<property name="personalization" value="dialog"/>
</property>
<property name="rowCount" value="13">
<property name="personalization" value="dialog"/>
</property>
<property name="visibleFirstRow" value="1">
<property name="personalization" value="dialog"/>
</property>
<property name="visibleFirstRowD" value="1">
<property name="personalization" value="dialog"/>
</property>
<property name="navigationMode" value="BYPAGE">
<property name="personalization" value="dialog"/>
<property name="type" value="select[BYPAGE,BYLINE]"/>
</property>
</component-profile>
</component>

Regards,

Rich Heilman

Former Member
0 Kudos

Hi Rich,

This is not your complete portalapp.xml but add the following lines to your portalapp.xml. Put it underneath </component> line.

<component name="ExtractPC">
<component-config>
<property name="ClassName" value="com.rl.woa.orderstatus.ExtractPC"/>
<property name="SecurityZone" value="com.sap.portal.ep50/ep50_safety"/>
</component-config>
<component-profile/>
</component>

Message was edited by: Prakash Singh

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Seems to work if i trigger the ExtractPC from the portalapp.xml, but when triggering from my orderstatus iview via button, it opens up a new browser window and gives the following error.

Portal Runtime Error

An exception occurred while processing a request for :

iView : N/A

Component Name : N/A

iView not found: com.rl.woa.orderstatus.ExtractPC.

Exception id: 10:19_26/04/05_0055_5082050

See the details for the exception ID in the log file

Regards,

Rich Heilman

Former Member
0 Kudos

Did you upload the par after modifying the portalapp.xml.

Try running your component via url in IE and see if you get the same error.

http://your portal/irj/servlet/prt/portal/prtroot/com.rl.woa.orderstatus.ExtractPC

If it doesn't work then send me the par at psingh@ust.net, i will take a quick glance at it to see what is wrong with it.

Message was edited by: Prakash Singh

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

It still doesn't work....sending the par.

Regards,

Rich Heilman

Former Member
0 Kudos

Hi Rich,

I see your problem now.

change the com.rl.woa.orderstatus.ExtractPC to YORKTOWNE.ExtractPC

<script>
function openfile()
{
  <%
  IPortalComponentURI componentURI = componentRequest.createPortalComponentURI ();
  <b>componentURI.setContextName("YORKTOWNE.ExtractPC");</b>
  String searchComponentURI = componentURI.toString();
  %>
 var url = "<%=searchComponentURI%>";
 window.open( url, "_blank");
}
</script>

PS: Please don't forget to reward points. Thank you:)

Message was edited by: Prakash Singh

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Cool....almost there. I still have one thing that I need to take care of. When the OPEN/SAVE dialog appears, so does a blank window, when clicking save, it works, but then that blank window stays there. Anyway to get rid of it programmically.

Regards,

Rich Heilman

Message was edited by: Rich Heilman

Former Member
0 Kudos

Modify your ExtractPC code and add the following lines at the bottom your code.

response.write("<script>window.close();</script>")

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

I put that statment at the end of my doContent method in the ExtractPC class, but it didn't do the job.

Any other ideas.

Also, now implementing your way, I can not pass data from my JSPDynpage Class to the ExtractPC class. How can I pass this data to be downloaded.

Regards,

Rich Heilman

Message was edited by: Rich Heilman

Former Member
0 Kudos

Hi Rich,

The solution i suggest earlier can use a bean to transfer information from one component to another. Forget about that solution. I will give you a an easier solution. I should have thought of this earlier. The following solution will take care of your popup as well as passing the data because everything will stay in one component.

1. Put the event

onDownloadClick

back into button control and delet the client event. Put it back the way it was before.

<hbj:button	id="btnDownload" encode="FALSE" tooltip="Download Now" onClick="DownloadClick">
		<%
		btnDownload.setText("<img src=""+componentRequest.getWebResourcePath() + "/images/download.gif" align="left" border=0> Download");
		%>
</hbj:button>

2. Modify the following code in method

"onDownloadClick".

You should modify it so that actual data is being writing to writer.

public void onDownloadClick(Event event) throws PageException {
 
// Grab selections from screen elements
    setUserSelectionInputExtractTab();
    retrieveExtractData();
       
 
    request = (IPortalComponentRequest) this.getReques();

   HttpServletResponse res = request.getServletResponse(true);
 
   try {
 
    res.setHeader("Content-Disposition","attachment;	filename="Test.txt"");
    
     try {
 
	PrintWriter out = res.getWriter();
 
	for (int i = 1; i <= 100; i++) {
	out.println( "LineA " + i + "," + "LineB " + i + "," + "LineC " + i + "," + "LineD " + i + "," + "LineE " + i + "," + "LineF " + i + ",");
 
	}
	out.flush();
	out.close();
	} catch (Exception e) {
		System.out.println(e);
	}
 
   } catch (Exception e) {
      e.printStackTrace();
   }

   state = INITIAL_STATE;
 }

3. Delet the

ExtractPC

because you don't need it. Delete it from portalapp.xml as well.

Message was edited by: Prakash Singh

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Rich,

could u send here some code snipplets from ur app?

i think that when u are downloading that file the portal is loosing his control over driving ur application(getServletResponse(true)). I think that u are using some component(button) which is sending event directly to the server and from this event u are sending that file? right??

Better way(or working for me) i think is to send request to downloading to another component(e.g. from javascript function attached to button).

Only for inspiration in last project i used this code:

IPortalComponentURI componentURI = request.createPortalComponentURI();
			componentURI.setContextName(pcdURL);//in pcdURL is st like pcd://blablabla
			String url = componentURI.toString();
String graphURL = url + "?" + PictureStore.REQ_PARAM_HASH + "=" + hash;
...
Button saveB = new Button("save");
saveB.setOnClientClick(
				"window.location='" + graphURL)

try this solution. i hope that it will works

JJ