Ok, so this is my code (works, irrelevant striped):

public class PageIndex extends PageBase{
...
...
...
  final Integer fileDbIdTmp = (Integer) oneResult.get("fileId");
  final byte[] bytes = new String("content of the created file for 
download").getBytes();
  ResourceLink<Void> downloadLink = new ResourceLink<Void>("downloadLink", new 
AbstractResource()
  {
    private Integer fileDbId = fileDbIdTmp;
    @Override
    protected ResourceResponse newResourceResponse(Attributes attributes)
    {
      ResourceResponse r = new ResourceResponse();
      r.setFileName("mypdf.pdf");
      r.setContentType("application/pdf");
      r.setContentDisposition(ContentDisposition.ATTACHMENT);
      r.setContentLength(bytes.length);
      r.setWriteCallback(new WriteCallback()
      {
        @Override
        public void writeData(Attributes attributes)
        {
          //here, the data for .pdf should be loaded on-demand from DB with 
some appropriate model...
          MyDAOObject myDBData = new MyDAOObject(fileDbIdTmp);//just pseudo-code
          attributes.getResponse().write(myDBData.loadData());
        }
      });
      return r;
    }
  });
panelEvent.add(downloadLink);
this.add(panelEvent);
...
...
...
}

Now I would like construct LoadableDetachableModel (using this model for 
loading strings for same panels) or something similar
so I can construct data from DB based on some id (I have DB id of the element - 
in this case .pdf file stored in DB).

After consult doc:
http://wicket.apache.org/apidocs/1.5/org/apache/wicket/markup/html/link/ResourceLink.html
I can't see where to put model, or where to hook model into ResourceLink.

In my code in writeData() there is line for loading data but I think this is 
ugly solution...


Any help appreciated.

MJ


On 15.10.2012 8:06, Michael Jaruska wrote:
Yes, thank you, this example helps.


On 15.10.2012 3:42, Dan Retzlaff wrote:
This should get you going:
new ResourceLink<Void>("pdf", new AbstractResource() {
@Override
protected ResourceResponse newResourceResponse(Attributes attributes) {
final byte[] pdfBytes = getPdfBytes();
ResourceResponse r = new ResourceResponse();
r.setFileName("yourpdf.pdf");
r.setContentType("application/pdf");
r.setContentDisposition(ContentDisposition.ATTACHMENT);
r.setContentLength(pdfBytes.length);
r.setWriteCallback(new WriteCallback() {
@Override
public void writeData(Attributes attributes) throws IOException {
attributes.getResponse().write(pdfBytes);
}
});
return r;
}
}
On Sun, Oct 14, 2012 at 8:14 PM, Michael Jaruska
<michael.jaru...@gmail.com>wrote:

Is there more complex example? Do you build link with DownloadLink or
ResourceLink? -I suppouse you use ResourceLink. And yes, I would like to
build response data at the link click moment, no temp file if possible
(in fact I have data as byte[] from database).



On 14.10.2012 21:59, Dan Retzlaff wrote:

I usually wrap a custom AbstractResource instance in a ResourceReference,
and put that into the ResourceLink. AbstractResource#**
newResourceResponse()
is called when the link is clicked. You can query for the bytes there, and
write them to the response in your ResourceResponse's WriteCallback. For a
download, the relevant setters are:

ResourceResponse response = new ResourceResponse();
response.setFileName(...);
response.setContentType(...);
response.setContentLength(...)**;
response.**setContentDisposition(**ContentDisposition.ATTACHMENT)**;
response.setWriteCallback(new WriteCallback() {...});

On Sun, Oct 14, 2012 at 7:45 PM, Michael Jaruska
<michael.jaru...@gmail.com>**wrote:

  Dan, thank you for links and points.

The true is that I have data in database so I would like streaming them.
Is the right
way put them in temp file first and then send it into browser with
DownloadLink?

After some googling I noticed that ResourceLink should be like
DownloadLink but for me
better - it's for streamed data. But can't find any example for wicket
1.5
:-(

MJ



On 14.10.2012 21:00, Dan Retzlaff wrote:

  Michael, check out the DownloadLink example here:
http://www.wicket-library.com/****wicket-examples/linkomatic/****home<http://www.wicket-library.com/**wicket-examples/linkomatic/**home>
<http://www.wicket-**library.com/wicket-examples/**linkomatic/home<http://www.wicket-library.com/wicket-examples/linkomatic/home>



Also check out the code for DownloadLink itself, and you'll see
1. Your IModel must return a File, but yours returns bytes.
2. The download is initiated in DownloadLink#onClick, which you have
blocked with your subclass.

Hope that helps,
Dan

On Sun, Oct 14, 2012 at 5:09 PM, Michael Jaruska
<michael.jaru...@gmail.com>****wrote:

   Hi,


what to add into onClick() in DownloadLink if I need return to client
generated .pdf
stream as a .pdf file?

My code:

IModel pdfStreamModel = new AbstractReadOnlyModel()
{
           public Object getObject()
           {
                   return getPdfStreamBytes();
           }
};
DownloadLink downloadLink = new DownloadLink("downloadLink",
pdfStreamModel, getPdfDocumentName())
{
           public void onClick()
           {
                   System.out.println("clicking works");
           }
};

Model works, DownloadLink is added into my markup. But I can't find any
example how to deal
code into onClick() in DownloadLink in a way it will return my
generated
.pdf stream in model.

Thank folks,

MJ

------------------------------******--------------------------**--**
--**---------
To unsubscribe, e-mail: users-unsubscribe@wicket.****apa**che.org<
http://apache.org**>
<users-unsubscribe@**wicket.**apache.org <http://wicket.apache.org><
users-unsubscribe@**wicket.apache.org<users-unsubscr...@wicket.apache.org>




For additional commands, e-mail: users-h...@wicket.apache.org




  ------------------------------****----------------------------**
--**---------
To unsubscribe, e-mail: 
users-unsubscribe@wicket.**apa**che.org<http://apache.org>
<users-unsubscribe@**wicket.apache.org<users-unsubscr...@wicket.apache.org>

For additional commands, e-mail: users-h...@wicket.apache.org




------------------------------**------------------------------**---------
To unsubscribe, e-mail: 
users-unsubscribe@wicket.**apache.org<users-unsubscr...@wicket.apache.org>
For additional commands, e-mail: users-h...@wicket.apache.org




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

Reply via email to