简体   繁体   中英

Wicket: create a link to a PDF file

I have to re-do a page which contains links to pdf files.

So far the page looks something like this:

NewsPanel.html

<wicket:fragment wicket:id="news">
    [...]
    <ul>
        <li><a href="res/pdf/NewsAugust.pdf" target="_blank">August</a></li>        
        <li><a href="res/pdf/NewsSeptember.pdf" target="_blank">September</a></li>    
    </ul>
    [...]
</wicket:fragment>

And now I have to build the links with information from the Data Base.

I have tried something like this:

NewsPanel.java

[...]
Resource pdfResource = new WebResource() {

    private static final long serialVersionUID = 1L;

    @Override
    public IResourceStream getResourceStream() {
        File pdf = new File("res/newsletter/September.pdf");
        IResourceStream stream = new FileResourceStream(pdf);
        return stream;
    }
};
ResourceLink<Void> resourceLink = new ResourceLink<Void>("pdf", pdfResource);
add(resourceLink);
resourceLink.add(new Label("label", new Model<String>("September")));
[...]

NewsPanel.html

<wicket:fragment wicket:id="news">
    [...]
    <ul>
        <li><a href="#" wicket:id="pdf"><wicket:container wicket:id="label"></wicket:container></a></li>  
    </ul>

</wicket:fragment>

But when I click the link, it shows a 404 error...

What's the correct way to do this?

And as always, as soon as I post a question here, I realize the answer, it was as simple as this: NewsPanel.java

ExternalLink link = new ExternalLink("pdf", "res/newsletter/September.pdf", "September");
add(link);

NewsPanel.html

<a href="#" wicket:id="pdf">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM