You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Stanczak Group <ju...@stanczakgroup.com> on 2007/10/04 23:19:27 UTC

Adding to response header (filename)?

How can I do this in Wicket? I'm writing a csv generated file to the 
output, but I don't know how to tell the client what file name to use. 
This is what I was using before, is there another way?

getResponse().setHeader("Content-Disposition", 
"attachment;filename=\"export_" + 
formatFile.format(Calendar.getInstance().getTime()) + ".csv\"");

############################Code##############################################
                            getResponse().setContentType("text/csv");
                            
getResponse().setHeader("Content-Disposition", 
"attachment;filename=\"export_" + 
formatFile.format(Calendar.getInstance().getTime()) + ".csv\"");
                            OutputStream cout = 
getResponse().getOutputStream();
                            cout.write(out.toString().getBytes());
                            cout.flush();
                            cout.close();

-- 
Justin Stanczak
Stanczak Group
812-735-3600

"All that is necessary for the triumph of evil is that good men do nothing."
Edmund Burke


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Yanıt: Re: Yanıt: Re: Adding to response header (filename)?

Posted by Ramazan Pekin <ra...@yahoo.com>.
No, There is no error at logs. I have tried to do with wicket but I cant. So I have done with this way. This link is org.apache.wicket.markup.html.link.Link and in the org.apache.wicket.markup.html.panel.Panel. And the panel in the org.apache.wicket.markup.html.WebPage

Stanczak Group <ju...@stanczakgroup.com> wrote:
  That's what I used to use, but it gives the same error. Do you not get 
the error in the logs. The error doesn't stop it from working, but I 
still would like to do it correctly according to Wicket.

Ramazan Pekin wrote:
> I dont know the subject, I didnt follow up, but this code is working.
> 
> downloadLink = new Link("downloadFile"){
> private static final long serialVersionUID = 1L;
> public void onClick(){
> String tableCode = sourceCode;
> BufferedInputStream bis = null;
> BufferedOutputStream bos = null;
> try {
> String ContentType = "text";
> getResponse().setContentType(ContentType);
> ((WebResponse)getResponse()).setHeader("Content-Disposition","inline; filename=\""+fileName+".java\"");
> ByteArrayInputStream bais = new ByteArrayInputStream(tableCode.getBytes());
> bis = new BufferedInputStream(bais);
> bos=new BufferedOutputStream(getResponse().getOutputStream());
> byte[] buff=new byte[2048];
> int bytesread;
> while((bytesread=bis.read(buff,0,buff.length)) != -1) {
> bos.write(buff,0,bytesread);
> }
> bos.flush();
> } catch (Exception e) {
> e.printStackTrace();
> } finally{
> try {
> bos.close();bos=null;
> bis.close();bis=null;
> } catch (Exception e) {
> 
> }
> }
> }
> };
>
> Eelco Hillenius wrote:
> On 10/6/07, Stanczak Group wrote:
> 
>> Well, I still don't see a way to get around this error. I'll have to
>> live with it for now until I can look into it deeper. Has anyone else
>> had this error?
>> 
>
> But you shouldn't call respond yourself. That's for Wicket to do. The
> only thing you should do is the the request target on the request
> cycle.
>
> Eelco
>
> 
>> Stanczak Group wrote:
>> 
>>> Instead of "setRequestTarget(rsrt)" I use this
>>> "rsrt.respond(getRequestCycle());", is that correct? It does work, but
>>> I get this in the logs "08:53:03,277 ERROR WebResponse:190 - Unable to
>>> redirect to: ?wicket:interface=:2::::, HTTP Response has already been
>>> committed.". It works, but I wouldn't mind fixing that error, just to
>>> keep things clean.
>>>
>>>
>>> Johan Compagner wrote:
>>> 
>>>> or something like this:
>>>>
>>>> new Link()
>>>> {
>>>> onclick()
>>>> {
>>>> CharSequence discounts = DataBase.getInstance()
>>>> .exportDiscounts();
>>>>
>>>>
>>>> ResourceStreamRequestTarget rsrt = new ResourceStreamRequestTarget(new
>>>> StringResourceStream(discounts, "text/csv"));
>>>> rsrt.setFileName(name);
>>>> setRequestTarget(rsrt)
>>>> }
>>>> }
>>>>
>>>> Maybe we should give ResourceStreanRequestTarget 1 extra constructor
>>>> with
>>>> the file name..
>>>>
>>>> setRequestTarget(new ResourceStreamRequestTarget(new
>>>> StringResourceStream(discounts, "text/csv",name)))
>>>>
>>>>
>>>> On 10/5/07, Eelco Hillenius wrote:
>>>>
>>>> 
>>>>> On 10/5/07, Eelco Hillenius wrote:
>>>>>
>>>>> 
>>>>>> What do you use for the export? You probably should use a resource.
>>>>>> For instance:
>>>>>>
>>>>>> public class DiscountsExport extends WebResource {
>>>>>>
>>>>>> public static class Initializer implements IInitializer {
>>>>>>
>>>>>> public void init(Application application) {
>>>>>> SharedResources res = application.getSharedResources();
>>>>>> res.add("discounts", new DiscountsExport());
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> public DiscountsExport() {
>>>>>>
>>>>>> setCacheable(false);
>>>>>> }
>>>>>>
>>>>>> @Override
>>>>>> public IResourceStream getResourceStream() {
>>>>>> CharSequence discounts = DataBase.getInstance().exportDiscounts();
>>>>>> return new StringResourceStream(discounts, "text/plain");
>>>>>> }
>>>>>>
>>>>>> @Override
>>>>>> protected void setHeaders(WebResponse response) {
>>>>>> super.setHeaders(response);
>>>>>> response.setAttachmentHeader("discounts.csv");
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> 
>>>>> Sorry, this might be easier to understand:
>>>>>
>>>>> WebResource export = new WebResource() {
>>>>>
>>>>> @Override
>>>>> public IResourceStream getResourceStream() {
>>>>> CharSequence discounts = DataBase.getInstance()
>>>>> .exportDiscounts();
>>>>> return new StringResourceStream(discounts, "text/csv");
>>>>> }
>>>>>
>>>>> @Override
>>>>> protected void setHeaders(WebResponse response) {
>>>>> super.setHeaders(response);
>>>>> response.setAttachmentHeader("discounts.csv");
>>>>> }
>>>>> };
>>>>> export.setCacheable(false);
>>>>>
>>>>> add(new ResourceLink("exportLink", export));
>>>>>
>>>>>
>>>>> Eelco
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>>>
>>>>> 
>>>> 
>> --
>> Justin Stanczak
>> Stanczak Group
>> 812-735-3600
>>
>> "All that is necessary for the triumph of evil is that good men do nothing."
>> Edmund Burke
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>> 
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>
> 
> ---------------------------------
> Yahoo! kullaniyor musunuz?
> Istenmeyen postadan biktiniz mi? Istenmeyen postadan en iyi korunma Yahoo! Posta'da
> http://tr.mail.yahoo.com
> 

-- 
Justin Stanczak
Stanczak Group
812-735-3600

"All that is necessary for the triumph of evil is that good men do nothing."
Edmund Burke


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org



       
---------------------------------
Yahoo! kullaniyor musunuz?
Istenmeyen postadan biktiniz mi? Istenmeyen postadan en iyi korunma Yahoo! Posta'da
http://tr.mail.yahoo.com

Re: Yanıt: Re: Adding to response header (filename)?

Posted by Stanczak Group <ju...@stanczakgroup.com>.
That's what I used to use, but it gives the same error. Do you not get 
the error in the logs. The error doesn't stop it from working, but I 
still would like to do it correctly according to Wicket.

Ramazan Pekin wrote:
> I dont know the subject, I didnt follow up, but this code is working.
>    
>   downloadLink = new Link("downloadFile"){
>  private static final long serialVersionUID = 1L;
>  public void onClick(){
>   String tableCode = sourceCode;
>   BufferedInputStream bis = null;
>   BufferedOutputStream bos = null;
>   try {
>    String ContentType = "text";
>    getResponse().setContentType(ContentType);
>    ((WebResponse)getResponse()).setHeader("Content-Disposition","inline; filename=\""+fileName+".java\"");
>    ByteArrayInputStream bais = new ByteArrayInputStream(tableCode.getBytes());
>    bis = new BufferedInputStream(bais);
>    bos=new BufferedOutputStream(getResponse().getOutputStream());
>    byte[] buff=new byte[2048];
>    int bytesread;
>    while((bytesread=bis.read(buff,0,buff.length)) != -1) {
>     bos.write(buff,0,bytesread);
>    }
>    bos.flush();
>   } catch (Exception e) {
>    e.printStackTrace();
>   } finally{
>    try {
>     bos.close();bos=null;
>     bis.close();bis=null;
>    } catch (Exception e) {
>     
>    }
>   }
>  }
> };
>
> Eelco Hillenius <ee...@gmail.com> wrote:
>   On 10/6/07, Stanczak Group wrote:
>   
>> Well, I still don't see a way to get around this error. I'll have to
>> live with it for now until I can look into it deeper. Has anyone else
>> had this error?
>>     
>
> But you shouldn't call respond yourself. That's for Wicket to do. The
> only thing you should do is the the request target on the request
> cycle.
>
> Eelco
>
>   
>> Stanczak Group wrote:
>>     
>>> Instead of "setRequestTarget(rsrt)" I use this
>>> "rsrt.respond(getRequestCycle());", is that correct? It does work, but
>>> I get this in the logs "08:53:03,277 ERROR WebResponse:190 - Unable to
>>> redirect to: ?wicket:interface=:2::::, HTTP Response has already been
>>> committed.". It works, but I wouldn't mind fixing that error, just to
>>> keep things clean.
>>>
>>>
>>> Johan Compagner wrote:
>>>       
>>>> or something like this:
>>>>
>>>> new Link()
>>>> {
>>>> onclick()
>>>> {
>>>> CharSequence discounts = DataBase.getInstance()
>>>> .exportDiscounts();
>>>>
>>>>
>>>> ResourceStreamRequestTarget rsrt = new ResourceStreamRequestTarget(new
>>>> StringResourceStream(discounts, "text/csv"));
>>>> rsrt.setFileName(name);
>>>> setRequestTarget(rsrt)
>>>> }
>>>> }
>>>>
>>>> Maybe we should give ResourceStreanRequestTarget 1 extra constructor
>>>> with
>>>> the file name..
>>>>
>>>> setRequestTarget(new ResourceStreamRequestTarget(new
>>>> StringResourceStream(discounts, "text/csv",name)))
>>>>
>>>>
>>>> On 10/5/07, Eelco Hillenius wrote:
>>>>
>>>>         
>>>>> On 10/5/07, Eelco Hillenius wrote:
>>>>>
>>>>>           
>>>>>> What do you use for the export? You probably should use a resource.
>>>>>> For instance:
>>>>>>
>>>>>> public class DiscountsExport extends WebResource {
>>>>>>
>>>>>> public static class Initializer implements IInitializer {
>>>>>>
>>>>>> public void init(Application application) {
>>>>>> SharedResources res = application.getSharedResources();
>>>>>> res.add("discounts", new DiscountsExport());
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> public DiscountsExport() {
>>>>>>
>>>>>> setCacheable(false);
>>>>>> }
>>>>>>
>>>>>> @Override
>>>>>> public IResourceStream getResourceStream() {
>>>>>> CharSequence discounts = DataBase.getInstance().exportDiscounts();
>>>>>> return new StringResourceStream(discounts, "text/plain");
>>>>>> }
>>>>>>
>>>>>> @Override
>>>>>> protected void setHeaders(WebResponse response) {
>>>>>> super.setHeaders(response);
>>>>>> response.setAttachmentHeader("discounts.csv");
>>>>>> }
>>>>>> }
>>>>>>
>>>>>>             
>>>>> Sorry, this might be easier to understand:
>>>>>
>>>>> WebResource export = new WebResource() {
>>>>>
>>>>> @Override
>>>>> public IResourceStream getResourceStream() {
>>>>> CharSequence discounts = DataBase.getInstance()
>>>>> .exportDiscounts();
>>>>> return new StringResourceStream(discounts, "text/csv");
>>>>> }
>>>>>
>>>>> @Override
>>>>> protected void setHeaders(WebResponse response) {
>>>>> super.setHeaders(response);
>>>>> response.setAttachmentHeader("discounts.csv");
>>>>> }
>>>>> };
>>>>> export.setCacheable(false);
>>>>>
>>>>> add(new ResourceLink("exportLink", export));
>>>>>
>>>>>
>>>>> Eelco
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>>>
>>>>>           
>>>>         
>> --
>> Justin Stanczak
>> Stanczak Group
>> 812-735-3600
>>
>> "All that is necessary for the triumph of evil is that good men do nothing."
>> Edmund Burke
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>
>        
> ---------------------------------
> Yahoo! kullaniyor musunuz?
> Istenmeyen postadan biktiniz mi? Istenmeyen postadan en iyi korunma Yahoo! Posta'da
> http://tr.mail.yahoo.com
>   

-- 
Justin Stanczak
Stanczak Group
812-735-3600

"All that is necessary for the triumph of evil is that good men do nothing."
Edmund Burke


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Yanıt: Re: Adding to response header (filename)?

Posted by Ramazan Pekin <ra...@yahoo.com>.
I dont know the subject, I didnt follow up, but this code is working.
   
  downloadLink = new Link("downloadFile"){
 private static final long serialVersionUID = 1L;
 public void onClick(){
  String tableCode = sourceCode;
  BufferedInputStream bis = null;
  BufferedOutputStream bos = null;
  try {
   String ContentType = "text";
   getResponse().setContentType(ContentType);
   ((WebResponse)getResponse()).setHeader("Content-Disposition","inline; filename=\""+fileName+".java\"");
   ByteArrayInputStream bais = new ByteArrayInputStream(tableCode.getBytes());
   bis = new BufferedInputStream(bais);
   bos=new BufferedOutputStream(getResponse().getOutputStream());
   byte[] buff=new byte[2048];
   int bytesread;
   while((bytesread=bis.read(buff,0,buff.length)) != -1) {
    bos.write(buff,0,bytesread);
   }
   bos.flush();
  } catch (Exception e) {
   e.printStackTrace();
  } finally{
   try {
    bos.close();bos=null;
    bis.close();bis=null;
   } catch (Exception e) {
    
   }
  }
 }
};

Eelco Hillenius <ee...@gmail.com> wrote:
  On 10/6/07, Stanczak Group wrote:
> Well, I still don't see a way to get around this error. I'll have to
> live with it for now until I can look into it deeper. Has anyone else
> had this error?

But you shouldn't call respond yourself. That's for Wicket to do. The
only thing you should do is the the request target on the request
cycle.

Eelco

> Stanczak Group wrote:
> > Instead of "setRequestTarget(rsrt)" I use this
> > "rsrt.respond(getRequestCycle());", is that correct? It does work, but
> > I get this in the logs "08:53:03,277 ERROR WebResponse:190 - Unable to
> > redirect to: ?wicket:interface=:2::::, HTTP Response has already been
> > committed.". It works, but I wouldn't mind fixing that error, just to
> > keep things clean.
> >
> >
> > Johan Compagner wrote:
> >> or something like this:
> >>
> >> new Link()
> >> {
> >> onclick()
> >> {
> >> CharSequence discounts = DataBase.getInstance()
> >> .exportDiscounts();
> >>
> >>
> >> ResourceStreamRequestTarget rsrt = new ResourceStreamRequestTarget(new
> >> StringResourceStream(discounts, "text/csv"));
> >> rsrt.setFileName(name);
> >> setRequestTarget(rsrt)
> >> }
> >> }
> >>
> >> Maybe we should give ResourceStreanRequestTarget 1 extra constructor
> >> with
> >> the file name..
> >>
> >> setRequestTarget(new ResourceStreamRequestTarget(new
> >> StringResourceStream(discounts, "text/csv",name)))
> >>
> >>
> >> On 10/5/07, Eelco Hillenius wrote:
> >>
> >>> On 10/5/07, Eelco Hillenius wrote:
> >>>
> >>>> What do you use for the export? You probably should use a resource.
> >>>> For instance:
> >>>>
> >>>> public class DiscountsExport extends WebResource {
> >>>>
> >>>> public static class Initializer implements IInitializer {
> >>>>
> >>>> public void init(Application application) {
> >>>> SharedResources res = application.getSharedResources();
> >>>> res.add("discounts", new DiscountsExport());
> >>>> }
> >>>> }
> >>>>
> >>>> public DiscountsExport() {
> >>>>
> >>>> setCacheable(false);
> >>>> }
> >>>>
> >>>> @Override
> >>>> public IResourceStream getResourceStream() {
> >>>> CharSequence discounts = DataBase.getInstance().exportDiscounts();
> >>>> return new StringResourceStream(discounts, "text/plain");
> >>>> }
> >>>>
> >>>> @Override
> >>>> protected void setHeaders(WebResponse response) {
> >>>> super.setHeaders(response);
> >>>> response.setAttachmentHeader("discounts.csv");
> >>>> }
> >>>> }
> >>>>
> >>> Sorry, this might be easier to understand:
> >>>
> >>> WebResource export = new WebResource() {
> >>>
> >>> @Override
> >>> public IResourceStream getResourceStream() {
> >>> CharSequence discounts = DataBase.getInstance()
> >>> .exportDiscounts();
> >>> return new StringResourceStream(discounts, "text/csv");
> >>> }
> >>>
> >>> @Override
> >>> protected void setHeaders(WebResponse response) {
> >>> super.setHeaders(response);
> >>> response.setAttachmentHeader("discounts.csv");
> >>> }
> >>> };
> >>> export.setCacheable(false);
> >>>
> >>> add(new ResourceLink("exportLink", export));
> >>>
> >>>
> >>> Eelco
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >>> For additional commands, e-mail: users-help@wicket.apache.org
> >>>
> >>>
> >>>
> >>
> >>
> >
>
> --
> Justin Stanczak
> Stanczak Group
> 812-735-3600
>
> "All that is necessary for the triumph of evil is that good men do nothing."
> Edmund Burke
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org



       
---------------------------------
Yahoo! kullaniyor musunuz?
Istenmeyen postadan biktiniz mi? Istenmeyen postadan en iyi korunma Yahoo! Posta'da
http://tr.mail.yahoo.com

Re: Adding to response header (filename)?

Posted by Stanczak Group <ju...@stanczakgroup.com>.
I've changed it to that below, but still get "18:22:47,185 ERROR 
WebResponse:190 - Unable to redirect to: ?wicket:interface=:2::::, HTTP 
Response has already been committed." in the logs. Isn't this the same 
as what's in the link you posted? I can post all the code, but all it is 
is a Link inside a Form. The code before what I've posted below simple 
appends text to the out, which is a StringBuilder. This is the only part 
where I send the request. I'm using 1.3 Wicket, and Apache Tomcat 6, if 
that helps.

SimpleDateFormat formatFile = new SimpleDateFormat("MM-dd-yyyy");
ResourceStreamRequestTarget rsrt = new ResourceStreamRequestTarget(new 
StringResourceStream(out, "text/csv"));
rsrt.setFileName("export_" + 
formatFile.format(Calendar.getInstance().getTime()) + ".csv");
getRequestCycle().setRequestTarget(rsrt);






Jan Kriesten wrote:
> hi,
>
> see here:
>
> http://www.nabble.com/Download-link-from-DynamicWebResource--tf4353363.html#a12404601
>
> regards, --- jan.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>   

-- 
Justin Stanczak
Stanczak Group
812-735-3600

"All that is necessary for the triumph of evil is that good men do nothing."
Edmund Burke


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Adding to response header (filename)?

Posted by Jan Kriesten <ja...@renitence.de>.
hi,

see here:

http://www.nabble.com/Download-link-from-DynamicWebResource--tf4353363.html#a12404601

regards, --- jan.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Adding to response header (filename)?

Posted by Stanczak Group <ju...@stanczakgroup.com>.
Oh, then what should I do? Sorry if I'm missing the obvious here.

Eelco Hillenius wrote:
> On 10/6/07, Stanczak Group <ju...@stanczakgroup.com> wrote:
>   
>> What do you mean? This is all I'm doing, but still get the "HTTP
>> Response has already been committed." error. Is there something there
>> that wrong?
>>
>> SimpleDateFormat formatFile = new SimpleDateFormat("MM-dd-yyyy-HH-MM");
>>                         ResourceStreamRequestTarget rsrt = new
>> ResourceStreamRequestTarget(new StringResourceStream(out, "text/csv"));
>>                         rsrt.setFileName("export_" +
>> formatFile.format(Calendar.getInstance().getTime()) + ".csv");
>>                         rsrt.respond(getRequestCycle());
>>     
>
> This last line, rsrt.respond is what you shouldn't do.
>
> Eelco
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>   

-- 
Justin Stanczak
Stanczak Group
812-735-3600

"All that is necessary for the triumph of evil is that good men do nothing."
Edmund Burke


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Adding to response header (filename)?

Posted by Eelco Hillenius <ee...@gmail.com>.
On 10/6/07, Stanczak Group <ju...@stanczakgroup.com> wrote:
> What do you mean? This is all I'm doing, but still get the "HTTP
> Response has already been committed." error. Is there something there
> that wrong?
>
> SimpleDateFormat formatFile = new SimpleDateFormat("MM-dd-yyyy-HH-MM");
>                         ResourceStreamRequestTarget rsrt = new
> ResourceStreamRequestTarget(new StringResourceStream(out, "text/csv"));
>                         rsrt.setFileName("export_" +
> formatFile.format(Calendar.getInstance().getTime()) + ".csv");
>                         rsrt.respond(getRequestCycle());

This last line, rsrt.respond is what you shouldn't do.

Eelco

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Adding to response header (filename)?

Posted by Stanczak Group <ju...@stanczakgroup.com>.
What do you mean? This is all I'm doing, but still get the "HTTP 
Response has already been committed." error. Is there something there 
that wrong?

SimpleDateFormat formatFile = new SimpleDateFormat("MM-dd-yyyy-HH-MM");
                        ResourceStreamRequestTarget rsrt = new 
ResourceStreamRequestTarget(new StringResourceStream(out, "text/csv"));
                        rsrt.setFileName("export_" + 
formatFile.format(Calendar.getInstance().getTime()) + ".csv");
                        rsrt.respond(getRequestCycle());

Eelco Hillenius wrote:
> On 10/6/07, Stanczak Group <ju...@stanczakgroup.com> wrote:
>   
>> Well, I still don't see a way to get around this error. I'll have to
>> live with it for now until I can look into it deeper. Has anyone else
>> had this error?
>>     
>
> But you shouldn't call respond yourself. That's for Wicket to do. The
> only thing you should do is the the request target on the request
> cycle.
>
> Eelco
>
>   
>> Stanczak Group wrote:
>>     
>>> Instead of "setRequestTarget(rsrt)" I use this
>>> "rsrt.respond(getRequestCycle());", is that correct? It does work, but
>>> I get this in the logs "08:53:03,277 ERROR WebResponse:190 - Unable to
>>> redirect to: ?wicket:interface=:2::::, HTTP Response has already been
>>> committed.". It works, but I wouldn't mind fixing that error, just to
>>> keep things clean.
>>>
>>>
>>> Johan Compagner wrote:
>>>       
>>>> or something like this:
>>>>
>>>> new Link()
>>>> {
>>>> onclick()
>>>> {
>>>> CharSequence discounts = DataBase.getInstance()
>>>>            .exportDiscounts();
>>>>
>>>>
>>>> ResourceStreamRequestTarget rsrt = new ResourceStreamRequestTarget(new
>>>> StringResourceStream(discounts, "text/csv"));
>>>> rsrt.setFileName(name);
>>>> setRequestTarget(rsrt)
>>>> }
>>>> }
>>>>
>>>> Maybe we should give ResourceStreanRequestTarget 1 extra constructor
>>>> with
>>>> the file name..
>>>>
>>>>  setRequestTarget(new ResourceStreamRequestTarget(new
>>>> StringResourceStream(discounts, "text/csv",name)))
>>>>
>>>>
>>>> On 10/5/07, Eelco Hillenius <ee...@gmail.com> wrote:
>>>>
>>>>         
>>>>> On 10/5/07, Eelco Hillenius <ee...@gmail.com> wrote:
>>>>>
>>>>>           
>>>>>> What do you use for the export? You probably should use a resource.
>>>>>> For instance:
>>>>>>
>>>>>> public class DiscountsExport extends WebResource {
>>>>>>
>>>>>>   public static class Initializer implements IInitializer {
>>>>>>
>>>>>>     public void init(Application application) {
>>>>>>       SharedResources res = application.getSharedResources();
>>>>>>       res.add("discounts", new DiscountsExport());
>>>>>>     }
>>>>>>   }
>>>>>>
>>>>>>   public DiscountsExport() {
>>>>>>
>>>>>>     setCacheable(false);
>>>>>>   }
>>>>>>
>>>>>>   @Override
>>>>>>   public IResourceStream getResourceStream() {
>>>>>>     CharSequence discounts = DataBase.getInstance().exportDiscounts();
>>>>>>     return new StringResourceStream(discounts, "text/plain");
>>>>>>   }
>>>>>>
>>>>>>   @Override
>>>>>>   protected void setHeaders(WebResponse response) {
>>>>>>     super.setHeaders(response);
>>>>>>     response.setAttachmentHeader("discounts.csv");
>>>>>>   }
>>>>>> }
>>>>>>
>>>>>>             
>>>>> Sorry, this might be easier to understand:
>>>>>
>>>>>    WebResource export = new WebResource() {
>>>>>
>>>>>      @Override
>>>>>      public IResourceStream getResourceStream() {
>>>>>        CharSequence discounts = DataBase.getInstance()
>>>>>            .exportDiscounts();
>>>>>        return new StringResourceStream(discounts, "text/csv");
>>>>>      }
>>>>>
>>>>>      @Override
>>>>>      protected void setHeaders(WebResponse response) {
>>>>>        super.setHeaders(response);
>>>>>        response.setAttachmentHeader("discounts.csv");
>>>>>      }
>>>>>    };
>>>>>    export.setCacheable(false);
>>>>>
>>>>>    add(new ResourceLink("exportLink", export));
>>>>>
>>>>>
>>>>> Eelco
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>>>
>>>>>           
>>>>         
>> --
>> Justin Stanczak
>> Stanczak Group
>> 812-735-3600
>>
>> "All that is necessary for the triumph of evil is that good men do nothing."
>> Edmund Burke
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>   

-- 
Justin Stanczak
Stanczak Group
812-735-3600

"All that is necessary for the triumph of evil is that good men do nothing."
Edmund Burke


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Adding to response header (filename)?

Posted by Eelco Hillenius <ee...@gmail.com>.
On 10/6/07, Stanczak Group <ju...@stanczakgroup.com> wrote:
> Well, I still don't see a way to get around this error. I'll have to
> live with it for now until I can look into it deeper. Has anyone else
> had this error?

But you shouldn't call respond yourself. That's for Wicket to do. The
only thing you should do is the the request target on the request
cycle.

Eelco

> Stanczak Group wrote:
> > Instead of "setRequestTarget(rsrt)" I use this
> > "rsrt.respond(getRequestCycle());", is that correct? It does work, but
> > I get this in the logs "08:53:03,277 ERROR WebResponse:190 - Unable to
> > redirect to: ?wicket:interface=:2::::, HTTP Response has already been
> > committed.". It works, but I wouldn't mind fixing that error, just to
> > keep things clean.
> >
> >
> > Johan Compagner wrote:
> >> or something like this:
> >>
> >> new Link()
> >> {
> >> onclick()
> >> {
> >> CharSequence discounts = DataBase.getInstance()
> >>            .exportDiscounts();
> >>
> >>
> >> ResourceStreamRequestTarget rsrt = new ResourceStreamRequestTarget(new
> >> StringResourceStream(discounts, "text/csv"));
> >> rsrt.setFileName(name);
> >> setRequestTarget(rsrt)
> >> }
> >> }
> >>
> >> Maybe we should give ResourceStreanRequestTarget 1 extra constructor
> >> with
> >> the file name..
> >>
> >>  setRequestTarget(new ResourceStreamRequestTarget(new
> >> StringResourceStream(discounts, "text/csv",name)))
> >>
> >>
> >> On 10/5/07, Eelco Hillenius <ee...@gmail.com> wrote:
> >>
> >>> On 10/5/07, Eelco Hillenius <ee...@gmail.com> wrote:
> >>>
> >>>> What do you use for the export? You probably should use a resource.
> >>>> For instance:
> >>>>
> >>>> public class DiscountsExport extends WebResource {
> >>>>
> >>>>   public static class Initializer implements IInitializer {
> >>>>
> >>>>     public void init(Application application) {
> >>>>       SharedResources res = application.getSharedResources();
> >>>>       res.add("discounts", new DiscountsExport());
> >>>>     }
> >>>>   }
> >>>>
> >>>>   public DiscountsExport() {
> >>>>
> >>>>     setCacheable(false);
> >>>>   }
> >>>>
> >>>>   @Override
> >>>>   public IResourceStream getResourceStream() {
> >>>>     CharSequence discounts = DataBase.getInstance().exportDiscounts();
> >>>>     return new StringResourceStream(discounts, "text/plain");
> >>>>   }
> >>>>
> >>>>   @Override
> >>>>   protected void setHeaders(WebResponse response) {
> >>>>     super.setHeaders(response);
> >>>>     response.setAttachmentHeader("discounts.csv");
> >>>>   }
> >>>> }
> >>>>
> >>> Sorry, this might be easier to understand:
> >>>
> >>>    WebResource export = new WebResource() {
> >>>
> >>>      @Override
> >>>      public IResourceStream getResourceStream() {
> >>>        CharSequence discounts = DataBase.getInstance()
> >>>            .exportDiscounts();
> >>>        return new StringResourceStream(discounts, "text/csv");
> >>>      }
> >>>
> >>>      @Override
> >>>      protected void setHeaders(WebResponse response) {
> >>>        super.setHeaders(response);
> >>>        response.setAttachmentHeader("discounts.csv");
> >>>      }
> >>>    };
> >>>    export.setCacheable(false);
> >>>
> >>>    add(new ResourceLink("exportLink", export));
> >>>
> >>>
> >>> Eelco
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >>> For additional commands, e-mail: users-help@wicket.apache.org
> >>>
> >>>
> >>>
> >>
> >>
> >
>
> --
> Justin Stanczak
> Stanczak Group
> 812-735-3600
>
> "All that is necessary for the triumph of evil is that good men do nothing."
> Edmund Burke
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Adding to response header (filename)?

Posted by Stanczak Group <ju...@stanczakgroup.com>.
Well, I still don't see a way to get around this error. I'll have to 
live with it for now until I can look into it deeper. Has anyone else 
had this error?

Stanczak Group wrote:
> Instead of "setRequestTarget(rsrt)" I use this 
> "rsrt.respond(getRequestCycle());", is that correct? It does work, but 
> I get this in the logs "08:53:03,277 ERROR WebResponse:190 - Unable to 
> redirect to: ?wicket:interface=:2::::, HTTP Response has already been 
> committed.". It works, but I wouldn't mind fixing that error, just to 
> keep things clean.
>
>
> Johan Compagner wrote:
>> or something like this:
>>
>> new Link()
>> {
>> onclick()
>> {
>> CharSequence discounts = DataBase.getInstance()
>>            .exportDiscounts();
>>
>>
>> ResourceStreamRequestTarget rsrt = new ResourceStreamRequestTarget(new
>> StringResourceStream(discounts, "text/csv"));
>> rsrt.setFileName(name);
>> setRequestTarget(rsrt)
>> }
>> }
>>
>> Maybe we should give ResourceStreanRequestTarget 1 extra constructor 
>> with
>> the file name..
>>
>>  setRequestTarget(new ResourceStreamRequestTarget(new
>> StringResourceStream(discounts, "text/csv",name)))
>>
>>
>> On 10/5/07, Eelco Hillenius <ee...@gmail.com> wrote:
>>  
>>> On 10/5/07, Eelco Hillenius <ee...@gmail.com> wrote:
>>>    
>>>> What do you use for the export? You probably should use a resource.
>>>> For instance:
>>>>
>>>> public class DiscountsExport extends WebResource {
>>>>
>>>>   public static class Initializer implements IInitializer {
>>>>
>>>>     public void init(Application application) {
>>>>       SharedResources res = application.getSharedResources();
>>>>       res.add("discounts", new DiscountsExport());
>>>>     }
>>>>   }
>>>>
>>>>   public DiscountsExport() {
>>>>
>>>>     setCacheable(false);
>>>>   }
>>>>
>>>>   @Override
>>>>   public IResourceStream getResourceStream() {
>>>>     CharSequence discounts = DataBase.getInstance().exportDiscounts();
>>>>     return new StringResourceStream(discounts, "text/plain");
>>>>   }
>>>>
>>>>   @Override
>>>>   protected void setHeaders(WebResponse response) {
>>>>     super.setHeaders(response);
>>>>     response.setAttachmentHeader("discounts.csv");
>>>>   }
>>>> }
>>>>       
>>> Sorry, this might be easier to understand:
>>>
>>>    WebResource export = new WebResource() {
>>>
>>>      @Override
>>>      public IResourceStream getResourceStream() {
>>>        CharSequence discounts = DataBase.getInstance()
>>>            .exportDiscounts();
>>>        return new StringResourceStream(discounts, "text/csv");
>>>      }
>>>
>>>      @Override
>>>      protected void setHeaders(WebResponse response) {
>>>        super.setHeaders(response);
>>>        response.setAttachmentHeader("discounts.csv");
>>>      }
>>>    };
>>>    export.setCacheable(false);
>>>
>>>    add(new ResourceLink("exportLink", export));
>>>
>>>
>>> Eelco
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>     
>>
>>   
>

-- 
Justin Stanczak
Stanczak Group
812-735-3600

"All that is necessary for the triumph of evil is that good men do nothing."
Edmund Burke


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Adding to response header (filename)?

Posted by Stanczak Group <ju...@stanczakgroup.com>.
Instead of "setRequestTarget(rsrt)" I use this 
"rsrt.respond(getRequestCycle());", is that correct? It does work, but I 
get this in the logs "08:53:03,277 ERROR WebResponse:190 - Unable to 
redirect to: ?wicket:interface=:2::::, HTTP Response has already been 
committed.". It works, but I wouldn't mind fixing that error, just to 
keep things clean.


Johan Compagner wrote:
> or something like this:
>
> new Link()
> {
> onclick()
> {
> CharSequence discounts = DataBase.getInstance()
>            .exportDiscounts();
>
>
> ResourceStreamRequestTarget rsrt = new ResourceStreamRequestTarget(new
> StringResourceStream(discounts, "text/csv"));
> rsrt.setFileName(name);
> setRequestTarget(rsrt)
> }
> }
>
> Maybe we should give ResourceStreanRequestTarget 1 extra constructor with
> the file name..
>
>  setRequestTarget(new ResourceStreamRequestTarget(new
> StringResourceStream(discounts, "text/csv",name)))
>
>
> On 10/5/07, Eelco Hillenius <ee...@gmail.com> wrote:
>   
>> On 10/5/07, Eelco Hillenius <ee...@gmail.com> wrote:
>>     
>>> What do you use for the export? You probably should use a resource.
>>> For instance:
>>>
>>> public class DiscountsExport extends WebResource {
>>>
>>>   public static class Initializer implements IInitializer {
>>>
>>>     public void init(Application application) {
>>>       SharedResources res = application.getSharedResources();
>>>       res.add("discounts", new DiscountsExport());
>>>     }
>>>   }
>>>
>>>   public DiscountsExport() {
>>>
>>>     setCacheable(false);
>>>   }
>>>
>>>   @Override
>>>   public IResourceStream getResourceStream() {
>>>     CharSequence discounts = DataBase.getInstance().exportDiscounts();
>>>     return new StringResourceStream(discounts, "text/plain");
>>>   }
>>>
>>>   @Override
>>>   protected void setHeaders(WebResponse response) {
>>>     super.setHeaders(response);
>>>     response.setAttachmentHeader("discounts.csv");
>>>   }
>>> }
>>>       
>> Sorry, this might be easier to understand:
>>
>>    WebResource export = new WebResource() {
>>
>>      @Override
>>      public IResourceStream getResourceStream() {
>>        CharSequence discounts = DataBase.getInstance()
>>            .exportDiscounts();
>>        return new StringResourceStream(discounts, "text/csv");
>>      }
>>
>>      @Override
>>      protected void setHeaders(WebResponse response) {
>>        super.setHeaders(response);
>>        response.setAttachmentHeader("discounts.csv");
>>      }
>>    };
>>    export.setCacheable(false);
>>
>>    add(new ResourceLink("exportLink", export));
>>
>>
>> Eelco
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>     
>
>   

-- 
Justin Stanczak
Stanczak Group
812-735-3600

"All that is necessary for the triumph of evil is that good men do nothing."
Edmund Burke


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Adding to response header (filename)?

Posted by Stanczak Group <ju...@stanczakgroup.com>.
Ya, I like that. I'll give all these a shot. Here's what I setup thus 
far, before reading these posts. But what you have is much simpler. Thanks.

############################################################################
        mount(new URIRequestTargetUrlCodingStrategy("/cvs") {

            @Override
            public IRequestTarget decode(RequestParameters param) {
                return new CVSRequestTarget();
            }
        });
############################################################################
class CVSRequestTarget implements IRequestTarget {

    public CVSRequestTarget() {
    }

    public void respond(RequestCycle requestCycle) {
        WebResponse response = (WebResponse) requestCycle.getResponse();
        boolean includeArchived = 
Boolean.getBoolean(requestCycle.getRequest().getParameter("includeArchived"));
        Long divisionId = 
Long.getLong(requestCycle.getRequest().getParameter("divisionId"));
            Logger.getLogger(getClass()).error(includeArchived + "\n\n");
            Logger.getLogger(getClass()).error(divisionId + "\n\n");
        Session session = ((RequestCycleImpl) 
requestCycle).getHibernateSession();
        Transaction tx = session.beginTransaction();
        try {
            StringBuilder out = new StringBuilder();
            SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
            List divisions = session.createCriteria(Division.class).list();
            out.append("Address,City,Country,Email,First 
Name,Key,Identification,Last Name,Middle Name,Phone,Special 
Needs,State,Zip,Division,Major,Visit Date\n");
            for (Object object : divisions) {
                Division div = (Division) object;
                for (Major major : div.getMajors()) {
                    for (VisitDate visitDate : major.getVisitDates()) {
                        if (visitDate.isArchived() && !includeArchived) {
                            break;
                        }
                        for (Student student : visitDate.getStudents()) {
                            out.append(student.getAddress());
                            out.append(",");
                            out.append(student.getCity());
                            out.append(",");
                            out.append(student.getCountry());
                            out.append(",");
                            out.append(student.getEmail());
                            out.append(",");
                            out.append(student.getFname());
                            out.append(",");
                            out.append(student.getId());
                            out.append(",");
                            out.append(student.getIdentification());
                            out.append(",");
                            out.append(student.getLname());
                            out.append(",");
                            out.append(student.getMname());
                            out.append(",");
                            out.append(student.getPhone());
                            out.append(",");
                            out.append(student.getSpecial());
                            out.append(",");
                            out.append(student.getState());
                            out.append(",");
                            out.append(student.getZip());
                            out.append(",");
                            out.append(div.getName());
                            out.append(",");
                            out.append(major.getName());
                            out.append(",");
                            out.append(format.format(visitDate.getDate()));
                            out.append("\n");
                        }
                    }
                }
            }
            tx.commit();
            SimpleDateFormat formatFile = new 
SimpleDateFormat("MM-dd-yyyy-HH-MM");
            response.setContentType("text/csv");
            response.setHeader("Content-Disposition", 
"attachment;filename=\"export_" + 
formatFile.format(Calendar.getInstance().getTime()) + ".csv\"");
            OutputStream cout = response.getOutputStream();
            cout.write(out.toString().getBytes());
            cout.flush();
            cout.close();
        } catch (IOException e) {
            Logger.getLogger(getClass()).error(e);
        }
    }

    public void detach(RequestCycle requestCycle) {
    }
############################################################################

Johan Compagner wrote:
> or something like this:
>
> new Link()
> {
> onclick()
> {
> CharSequence discounts = DataBase.getInstance()
>            .exportDiscounts();
>
>
> ResourceStreamRequestTarget rsrt = new ResourceStreamRequestTarget(new
> StringResourceStream(discounts, "text/csv"));
> rsrt.setFileName(name);
> setRequestTarget(rsrt)
> }
> }
>
> Maybe we should give ResourceStreanRequestTarget 1 extra constructor with
> the file name..
>
>  setRequestTarget(new ResourceStreamRequestTarget(new
> StringResourceStream(discounts, "text/csv",name)))
>
>
> On 10/5/07, Eelco Hillenius <ee...@gmail.com> wrote:
>   
>> On 10/5/07, Eelco Hillenius <ee...@gmail.com> wrote:
>>     
>>> What do you use for the export? You probably should use a resource.
>>> For instance:
>>>
>>> public class DiscountsExport extends WebResource {
>>>
>>>   public static class Initializer implements IInitializer {
>>>
>>>     public void init(Application application) {
>>>       SharedResources res = application.getSharedResources();
>>>       res.add("discounts", new DiscountsExport());
>>>     }
>>>   }
>>>
>>>   public DiscountsExport() {
>>>
>>>     setCacheable(false);
>>>   }
>>>
>>>   @Override
>>>   public IResourceStream getResourceStream() {
>>>     CharSequence discounts = DataBase.getInstance().exportDiscounts();
>>>     return new StringResourceStream(discounts, "text/plain");
>>>   }
>>>
>>>   @Override
>>>   protected void setHeaders(WebResponse response) {
>>>     super.setHeaders(response);
>>>     response.setAttachmentHeader("discounts.csv");
>>>   }
>>> }
>>>       
>> Sorry, this might be easier to understand:
>>
>>    WebResource export = new WebResource() {
>>
>>      @Override
>>      public IResourceStream getResourceStream() {
>>        CharSequence discounts = DataBase.getInstance()
>>            .exportDiscounts();
>>        return new StringResourceStream(discounts, "text/csv");
>>      }
>>
>>      @Override
>>      protected void setHeaders(WebResponse response) {
>>        super.setHeaders(response);
>>        response.setAttachmentHeader("discounts.csv");
>>      }
>>    };
>>    export.setCacheable(false);
>>
>>    add(new ResourceLink("exportLink", export));
>>
>>
>> Eelco
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>     
>
>   

-- 
Justin Stanczak
Stanczak Group
812-735-3600

"All that is necessary for the triumph of evil is that good men do nothing."
Edmund Burke


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Adding to response header (filename)?

Posted by Johan Compagner <jc...@gmail.com>.
or something like this:

new Link()
{
onclick()
{
CharSequence discounts = DataBase.getInstance()
           .exportDiscounts();


ResourceStreamRequestTarget rsrt = new ResourceStreamRequestTarget(new
StringResourceStream(discounts, "text/csv"));
rsrt.setFileName(name);
setRequestTarget(rsrt)
}
}

Maybe we should give ResourceStreanRequestTarget 1 extra constructor with
the file name..

 setRequestTarget(new ResourceStreamRequestTarget(new
StringResourceStream(discounts, "text/csv",name)))


On 10/5/07, Eelco Hillenius <ee...@gmail.com> wrote:
>
> On 10/5/07, Eelco Hillenius <ee...@gmail.com> wrote:
> > What do you use for the export? You probably should use a resource.
> > For instance:
> >
> > public class DiscountsExport extends WebResource {
> >
> >   public static class Initializer implements IInitializer {
> >
> >     public void init(Application application) {
> >       SharedResources res = application.getSharedResources();
> >       res.add("discounts", new DiscountsExport());
> >     }
> >   }
> >
> >   public DiscountsExport() {
> >
> >     setCacheable(false);
> >   }
> >
> >   @Override
> >   public IResourceStream getResourceStream() {
> >     CharSequence discounts = DataBase.getInstance().exportDiscounts();
> >     return new StringResourceStream(discounts, "text/plain");
> >   }
> >
> >   @Override
> >   protected void setHeaders(WebResponse response) {
> >     super.setHeaders(response);
> >     response.setAttachmentHeader("discounts.csv");
> >   }
> > }
>
>
> Sorry, this might be easier to understand:
>
>    WebResource export = new WebResource() {
>
>      @Override
>      public IResourceStream getResourceStream() {
>        CharSequence discounts = DataBase.getInstance()
>            .exportDiscounts();
>        return new StringResourceStream(discounts, "text/csv");
>      }
>
>      @Override
>      protected void setHeaders(WebResponse response) {
>        super.setHeaders(response);
>        response.setAttachmentHeader("discounts.csv");
>      }
>    };
>    export.setCacheable(false);
>
>    add(new ResourceLink("exportLink", export));
>
>
> Eelco
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Adding to response header (filename)?

Posted by Eelco Hillenius <ee...@gmail.com>.
On 10/5/07, Eelco Hillenius <ee...@gmail.com> wrote:
> What do you use for the export? You probably should use a resource.
> For instance:
>
> public class DiscountsExport extends WebResource {
>
>   public static class Initializer implements IInitializer {
>
>     public void init(Application application) {
>       SharedResources res = application.getSharedResources();
>       res.add("discounts", new DiscountsExport());
>     }
>   }
>
>   public DiscountsExport() {
>
>     setCacheable(false);
>   }
>
>   @Override
>   public IResourceStream getResourceStream() {
>     CharSequence discounts = DataBase.getInstance().exportDiscounts();
>     return new StringResourceStream(discounts, "text/plain");
>   }
>
>   @Override
>   protected void setHeaders(WebResponse response) {
>     super.setHeaders(response);
>     response.setAttachmentHeader("discounts.csv");
>   }
> }


Sorry, this might be easier to understand:

    WebResource export = new WebResource() {

      @Override
      public IResourceStream getResourceStream() {
        CharSequence discounts = DataBase.getInstance()
            .exportDiscounts();
        return new StringResourceStream(discounts, "text/csv");
      }

      @Override
      protected void setHeaders(WebResponse response) {
        super.setHeaders(response);
        response.setAttachmentHeader("discounts.csv");
      }
    };
    export.setCacheable(false);

    add(new ResourceLink("exportLink", export));


Eelco

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Adding to response header (filename)?

Posted by Eelco Hillenius <ee...@gmail.com>.
What do you use for the export? You probably should use a resource.
For instance:

public class DiscountsExport extends WebResource {

  public static class Initializer implements IInitializer {

    public void init(Application application) {
      SharedResources res = application.getSharedResources();
      res.add("discounts", new DiscountsExport());
    }
  }

  public DiscountsExport() {

    setCacheable(false);
  }

  @Override
  public IResourceStream getResourceStream() {
    CharSequence discounts = DataBase.getInstance().exportDiscounts();
    return new StringResourceStream(discounts, "text/plain");
  }

  @Override
  protected void setHeaders(WebResponse response) {
    super.setHeaders(response);
    response.setAttachmentHeader("discounts.csv");
  }
}


Eelco

On 10/4/07, Stanczak Group <ju...@stanczakgroup.com> wrote:
> This works:
>
> getWebRequestCycle().getWebResponse().setContentType("text/csv");
>
> getWebRequestCycle().getWebResponse().setHeader("Content-Disposition",
> "attachment;filename=\"export_" +
> formatFile.format(Calendar.getInstance().getTime()) + ".csv\"");
>                             OutputStream cout =
> getWebRequestCycle().getWebResponse().getOutputStream();
>                             cout.write(out.toString().getBytes());
>                             cout.flush();
>                             cout.close();
>
> But I get this in the logs. How can I do this better?
>
> 16:31:45,391 ERROR WebResponse:190 - Unable to redirect to:
> ?wicket:interface=:2::::, HTTP Response has already been committed.
>
>
> Stanczak Group wrote:
> > This maybe? Should I be using "getWebRequestCycle().getWebResponse()"
> > instead of "getResponse()."?
> > getWebRequestCycle().getWebResponse().setHeader()
> >
> > Stanczak Group wrote:
> >> How can I do this in Wicket? I'm writing a csv generated file to the
> >> output, but I don't know how to tell the client what file name to
> >> use. This is what I was using before, is there another way?
> >>
> >> getResponse().setHeader("Content-Disposition",
> >> "attachment;filename=\"export_" +
> >> formatFile.format(Calendar.getInstance().getTime()) + ".csv\"");
> >>
> >> ############################Code##############################################
> >>
> >>                            getResponse().setContentType("text/csv");
> >>
> >> getResponse().setHeader("Content-Disposition",
> >> "attachment;filename=\"export_" +
> >> formatFile.format(Calendar.getInstance().getTime()) + ".csv\"");
> >>                            OutputStream cout =
> >> getResponse().getOutputStream();
> >>                            cout.write(out.toString().getBytes());
> >>                            cout.flush();
> >>                            cout.close();
> >>
> >
>
> --
> Justin Stanczak
> Stanczak Group
> 812-735-3600
>
> "All that is necessary for the triumph of evil is that good men do nothing."
> Edmund Burke
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Adding to response header (filename)?

Posted by Stanczak Group <ju...@stanczakgroup.com>.
This works:

getWebRequestCycle().getWebResponse().setContentType("text/csv");
                            
getWebRequestCycle().getWebResponse().setHeader("Content-Disposition", 
"attachment;filename=\"export_" + 
formatFile.format(Calendar.getInstance().getTime()) + ".csv\"");
                            OutputStream cout = 
getWebRequestCycle().getWebResponse().getOutputStream();
                            cout.write(out.toString().getBytes());
                            cout.flush();
                            cout.close();

But I get this in the logs. How can I do this better?

16:31:45,391 ERROR WebResponse:190 - Unable to redirect to: 
?wicket:interface=:2::::, HTTP Response has already been committed.


Stanczak Group wrote:
> This maybe? Should I be using "getWebRequestCycle().getWebResponse()" 
> instead of "getResponse()."?
> getWebRequestCycle().getWebResponse().setHeader()
>
> Stanczak Group wrote:
>> How can I do this in Wicket? I'm writing a csv generated file to the 
>> output, but I don't know how to tell the client what file name to 
>> use. This is what I was using before, is there another way?
>>
>> getResponse().setHeader("Content-Disposition", 
>> "attachment;filename=\"export_" + 
>> formatFile.format(Calendar.getInstance().getTime()) + ".csv\"");
>>
>> ############################Code############################################## 
>>
>>                            getResponse().setContentType("text/csv");
>>                            
>> getResponse().setHeader("Content-Disposition", 
>> "attachment;filename=\"export_" + 
>> formatFile.format(Calendar.getInstance().getTime()) + ".csv\"");
>>                            OutputStream cout = 
>> getResponse().getOutputStream();
>>                            cout.write(out.toString().getBytes());
>>                            cout.flush();
>>                            cout.close();
>>
>

-- 
Justin Stanczak
Stanczak Group
812-735-3600

"All that is necessary for the triumph of evil is that good men do nothing."
Edmund Burke


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Adding to response header (filename)?

Posted by Stanczak Group <ju...@stanczakgroup.com>.
This maybe? Should I be using "getWebRequestCycle().getWebResponse()" 
instead of "getResponse()."?
getWebRequestCycle().getWebResponse().setHeader()

Stanczak Group wrote:
> How can I do this in Wicket? I'm writing a csv generated file to the 
> output, but I don't know how to tell the client what file name to use. 
> This is what I was using before, is there another way?
>
> getResponse().setHeader("Content-Disposition", 
> "attachment;filename=\"export_" + 
> formatFile.format(Calendar.getInstance().getTime()) + ".csv\"");
>
> ############################Code############################################## 
>
>                            getResponse().setContentType("text/csv");
>                            
> getResponse().setHeader("Content-Disposition", 
> "attachment;filename=\"export_" + 
> formatFile.format(Calendar.getInstance().getTime()) + ".csv\"");
>                            OutputStream cout = 
> getResponse().getOutputStream();
>                            cout.write(out.toString().getBytes());
>                            cout.flush();
>                            cout.close();
>

-- 
Justin Stanczak
Stanczak Group
812-735-3600

"All that is necessary for the triumph of evil is that good men do nothing."
Edmund Burke


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org