or even easier (if you dont need a bookmarkable url)

abstract class ByteArrayLink extends Link {

protected abstract byte[] getbytes();
protected abstract String getfilename();

public void onclick() {
getRequestCycle().setRequestTarget(new IRequestTarget() {
  void detach(RequestCycle rc) {}
  Object getLock(RequestCycle rc) { return ByteArrayLink.this; }
  void respond(RequestCycle rc) {
               WebResponse r = (WebResponse)requestCycle.getResponse();
               r.setAttachmentHeader(getfilename());
               response.getOuptutStream().write(getbytes());
   }}
}


-igor


On 1/3/07, Janos Cserep <[EMAIL PROTECTED]> wrote:

Very short, very quick DynamicWebResource tutorial:)

1. Subclass DynamicWebResource

public class MyResource extends DynamicWebResource {

@Override
protected DynamicWebResource.ResourceState getResourceState() {

  return new ResourceState() {

    public byte[] getData() {
      return "Example".toBytes("UTF-8");
    }

    public String getContentType() {
      return "text/plain";
    }
   };
}
}

2. Open your Application class and append your init() method with the
following two lines:

getSharedResources().add("myResource", new MyResource( );
mountSharedResource("/my/resource/url", new
ResourceReference("myResource").getSharedResourceKey());

3. Browse to the http://server/context/.../my/resource/url URL and it
should show the "Example" string

4. modify getContentType() and getData() to return your objects (you can
get any HTTP parameter with the getParameter() call of the Resource class in
getData() so you could pass arguments to theURL like
http://server/context/.../my/resource/url?id=XkdfG12


Janos

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to