Code
"ExamplePanel.java"
public class ExamplePanel extends Panel {
/*
* constructor here
*/
public ExamplePanel(String id,Date fromDate,Date toDate) {
super(id);
/*
* created Resource for a pdf document named "abcd.pdf"
*/
Resource pdfResource = new WebResource() {
@overrides
public IResourceStream getResourceStream() {
/*
* created File object named "pdfFile" by passing the full path of the pdf document * in the constructor. ( Here my "abcd.pdf" is in C drive.)
*/
File pdfFile = new File("C:\\abcd.pdf");
// created FileResourceStream object by passing the above File object name "pdfFile".
IResourceStream stream = new FileResourceStream(pdfFile);
//finally returns the stream
return stream;
}
};
/*
* Created PopupSettings object named "popupSettings" by passing some parameters in the * constructor and also setted the width and height for popup window.
*/
PopupSettings popupSettings = new PopupSettings(PopupSettings.RESIZABLE | PopupSettings.SCROLLBARS).setHeight(500).setWidth(700);
/*
* Created ResourceLink object named "resourceLink" by passing above Resource object * named "pdfResource" as second parameters.The first parameter is "wicket:id" by which * markup identifies the component and renders it on web page.
*/
ResourceLink resourceLink = (ResourceLink) new ResourceLink("resourceLink",pdfResource);
//Setted the popupSettings properties of "resourceLink".
resourceLink.setPopupSettings(popupSettings);
//added resourceLink to panel finally
add(resourceLink);
}
}
Now its time to write matkup for above java file:-
One important thing to remember that "wicket:id" should be same for "ResourceLink" component in java file and html file.
"ExamplePanel.html"
<wicket:panel>
<a href="#" wicket:id="resourceLink">Click here to open the pdf</a>
</wicket:panel>
Now this is done. In this way you can open any document not only pdf. I used this approach to open pdf in my project so I took the example for pdf here. Hope will be helpful who is new in Wicket or will get a chance to play around this Wicket framework in future.