Martin,

I'm looking into mounting the resource but there is something that I don't 
understand. 
Currently I am creating the resource in my panel and passing the pdf I want to 
display into the constructor of the resource. If I mount the resource, how do I 
provide it with the dynamically generated pdf? I don't even see a way of 
getting a hold of the resourceReference object created and mounted in the  
WebApplication init() method. Perhaps I need to also register it as an 
application-shared resource, then access it in my panel constructor and add the 
pdf there?

Bruce

-----Original Message-----
From: Martin Grigorov [mailto:mgrigo...@apache.org] 
Sent: Friday, March 13, 2015 12:53 PM
To: users@wicket.apache.org
Subject: Re: PDF viewed in panel via ResourceReference works in 6.12 but not in 
6.13

Hi,

I think I see what happens.
The ResRef is created as a local variable to create the url and then discarded.
Wicket has something called ResourceReferenceRegistry. When a ResRef is used to 
create an url to it it is automatically registered in the registry.
It seems after 6.13 there is no such auto-registration for your ResRef for some 
reason.
You should have some WARNs in the logs.

I see nothing component specific in your ResRef so I'd #mountResource() it.
This way it will be always available.


Martin Grigorov
Freelancer, available for hire!
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Fri, Mar 13, 2015 at 6:40 PM, Bruce Lombardi <brlom...@gmail.com> wrote:

> I have a PdfViewer page that contains a panel that displays a 
> dynamically generated PDF using a resource reference. This works fine 
> in Wicket 6.12.0, but when I upgrade to 6.13.0 it stops working (just 
> changed Maven dependency
> - no code changes). No errors are displayed and the html is generated 
> exactly as it is with 6.12, but the pdf does not show up in the page.
>
> By setting a breakpoint in Eclipse I have determined that code in the 
> resource that produces the response (newResourceResponse) is never 
> called in 6.13. After migrating to the latest version (6.19) I still 
> get the problem.
> I've looked at the release notes for version 6.13 and see some changes 
> related to IResource but nothing that looks related to this problem.
>
> I'm hoping someone has seen something similar. Here is some of the 
> relevant
> code:
>
> PdfViewer .html - just has reference to panel
>
>        <div wicket:id="pdfPanel"></div>
>
>
>
> PdfPane.html - just has object reference
>
> Raw HTML
>
>        <object wicket:id="pdf" data="" border="1" width="80%"
> height="80%"></object>
>
>
>
> Generated HTML - seen with view source in browser
>
>         <object data="./resource/org.apache.wicket.Application/pdfProducer"
>
>                border="1" width="80%" height="80%"></object>
>
>
>
> PdfPanel.java - has setup for resource reference
>
> public class PdfPanel extends Panel {
>
>
>
>        private static final long serialVersionUID = 1L;
>
>
>
>        public PdfPanel(String id) {
>
>               super(id);
>
>
>
>               ResourceReference resourceReference = new 
> ResourceReference(
>
>                            "pdfProducer") {
>
>                      private static final long serialVersionUID = 1L;
>
>
>
>                      @Override
>
>                      public IResource getResource() {
>
>                            WebDocsSession session = 
> (WebDocsSession)getSession();
>
>
>
>                            final byte[] pdf = session.getPdf();
>
>
>
>                            if(pdf == null)
>
> System.out.println("PdfPanel session.getPdf returned null");
>
>
>
> PdfResourceProducer pdfResourceProducer =
>
> new PdfResourceProducer(pdf);
>
>
>
>                            return pdfResourceProducer;
>
>                      }
>
>               };
>
>
>
>         String url = 
> (String)RequestCycle.get().urlFor(resourceReference,
> null);
>
>
>
>         MarkupContainer wmc = new WebMarkupContainer("pdf");
>
>         wmc.add(new AttributeModifier("data", url));
>
>         add(wmc);
>
>        }
>
>
>
> PdfProducer.java - implements the Resource
>
>                 public class PdfResourceProducer extends 
> AbstractResource {
>
>
>
>        private static final long serialVersionUID = 
> -2245331056747467763L;
>
>        final byte[] pdfByteArray;
>
>
>
>
>
>        public PdfResourceProducer(byte[] pdfByteArray) {
>
>               super();
>
>               this.pdfByteArray = pdfByteArray;
>
>               if(pdfByteArray == null) {
>
>                      System.out.println("PdfResourceProducer 
> constructor called with
>
> null byte array.");
>
>               }
>
>        }
>
>
>
>        @Override
>
>        protected ResourceResponse newResourceResponse(Attributes
> attributes)
> {
>
>               ResourceResponse resourceResponse = new 
> ResourceResponse();
>
>               resourceResponse.setContentType("application/pdf");
>
>               // resourceResponse.setTextEncoding("utf-8");
>
>
>
>               
> resourceResponse.setContentLength((int)pdfByteArray.length);
>
>
>
>               resourceResponse.disableCaching(); //do not allow 
> resource to be cached.
>
>
>
>               resourceResponse.setWriteCallback(new WriteCallback() {
>
>                      @Override
>
>                      public void writeData(Attributes attributes) 
> throws IOException {
>
>                            try {
>
>                                   OutputStream outputStream =
> attributes.getResponse()
>
>                                                 .getOutputStream();
>
>                                   outputStream.write(pdfByteArray);
>
>                                   outputStream.flush();
>
>                            } catch (IOException e) {
>
>                                   throw new WicketRuntimeException(
>
>                                                 "Problems writing pdf 
> to response...");
>
>                            }
>
>                      }
>
>               });
>
>
>
>               return resourceResponse;
>
>        }
>
>
>
> Bruce
>
>
>
>


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

Reply via email to