By James, on December 6th, 2010
I recently came across a situation where I have to serve some static html files in a wicket application. Though it’s pretty simple, thanks to the ultra easy way wicket offers to write components, things can get tricky especially with the request path.
So I thought of documenting this for my own future reference and for the sake of the community.
Without wasting time, let me quickly explain how to serve static files with wicket (blatantly copied from wicket-examples).
Assumptions
I assume that you are using wicket 1.4.x as that’s the latest stable version at the time of writing this post.
Component
First let us write a reusable component class called “StaticLink”.
private class StaticLink extends WebMarkupContainer {
public StaticLink(String id, IModel model) {
super(id, model);
add(new AttributeModifier("href", true, model));
}
}
Html
In the html file where you want to put this link, add something like this:
<a> My static link</a>
Java
In the respective java file, all you need to do is this:
String contextPath = RequestUtils.toAbsolutePath(RequestCycle.get().
getRequest().getRelativePathPrefixToWicketHandler());
add(new StaticLink("myStaticLink", new Model(contextPath + "docs/index.html")));
Here were are resolving the absolute url of the static page which will free you from the hassles of using a relative url especially for static pages. The “contextPath” which we are constructing here will have the trailing “/” so you need not add it.
By James, on October 11th, 2010 I recently had a need where I had to get only the date portion from a column whose data type is “timestamp” (which is mapped using @TimeStamp annotation). After hours of investigation, I found a way to do that using standard jpa/hql queries and hence thought of documenting it in this post. MySQL has a simple “date() function” that would just give the date part from a date time expression. Microsoft SQL Server offers a couple of ways to achieve the same. Unfortunately, I couldn’t find any standard ways provided by jpa/hibernate to achieve this. Interestingly, the closest thing that can be considered as “standard” is the “cast function” which many databases seem to support. This prompted me to go for this solution because I felt this might be clean, as the syntax across different databases are pretty much similar. . . . → Read More: Extracting only date part of a date time column using JPA/Hibernate
By James, on September 26th, 2010 A few months ago, I was reading the book “Wicket in Action”. I was new to Wicket and Maven then. I followed the instructions given in the book to create a maven project. The book went one step further and explained how to create eclipse and idea projects from the pom, but nothing was mentioned about NetBeans. I felt sad that there is no maven plugin out there to create projects that NetBeans can understand.
But later when I realized that there is no such need to create Netbeans projects from Maven pom, I was thrilled. Maven, is a . . . → Read More: NetBeans and Maven – A quick start guide
By James, on September 10th, 2010 NetBeans has been my IDE of choice for the past few years and to my pleasure, I recently received a copy of NetBeans Platform 6.9 Developers Guide from Packt. So, I thought of coming out with a review of this book.
A bit about the NetBeans Platform
“The NetBeans Platform is a generic framework for Swing applications. It provides the “plumbing” that, before, every developer had to write themselves—saving state, connecting actions to menu items, toolbar items and keyboard shortcuts; window management, and so on. The NetBeans Platform provides all of these out of the box. You don’t . . . → Read More: Book Review: NetBeans Platform 6.9 Developers Guide
By James, on June 28th, 2010 Dear readers, Thanks for your patience. I’ve successfully moved my blog from my old hosting provider.
Still something might be broken. I’m working them out one by one. Thanks for your support.
By James, on June 24th, 2010 Dear readers,
Sorry for the down time. I’m in the process of changing to a different hosting provider. The blog should be up in a couple of days.
By James, on February 17th, 2010 I received a mail from Microsoft today morning about Windows 7 expiration. Here is the essence of the mail:
It’s time to upgrade from the Windows 7 Release Candidate
While most people who tested Windows 7 have now moved to the final version, some are still running the Release Candidate. If you haven’t moved yet, it’s time to replace the RC.
Starting on March 1, 2010 your PC will begin shutting down every two hours. Your work will not be saved during the shutdown.
The Windows 7 RC will fully expire on June 1, 2010. Your PC running the . . . → Read More: Windows 7 RC Expiration
By James, on November 9th, 2009 Quite some time back, I read an article titled “20+ Free Look and Feel Libraries For Java Swing“. I have evaluated most of the libraries mentioned in that article. Personally, I prefer the System look and feel that is bundled in the JRE. However, I like Substance, PGS and JGoodies as well. Which one do you use? Curious to know.
What Java Look and Feel do you use?
Metal System Look and Feel Nimbus JGoodies Substance Alloy JTattoo Synthetica Liquid PGS Other (Please mention your choice in the comments)
View Results
Loading …
By James, on November 4th, 2009 Introduction Spring is a powerful application framework that can be used across any layer in your application. For example, you can use Spring to manage only your data access layer or you can use Spring to provide remote services for your swing client. In this article, I will explain how to get started with Spring by developing a simple java application.
Requirements 1. Your favorite IDE 2. Latest Spring framework.
(Note: This article makes use of Spring framework 2.5.6 which is the current production release)
The Application We are going to develop a simple application that fetches and display . . . → Read More: Developing A Simple Java Application With Spring
By James, on September 20th, 2009 Most of the applications we use on daily basis are pluggable. Popular applications like Firefox, Eclipse, NetBeans, JEdit, WordPress, Hudson are all pluggable. In fact, pluggability has played a major part in the success of most of these applications. Why not make the Java applications we develop pluggable as well? Yes, we get pluggability out of the box, if our applications are based on a rich client platform like NetBeans or Eclipse. But for some reasons if you decide not to use those platforms, it doesn’t mean that they should not be pluggable. In this article, we will learn . . . → Read More: Developing A Simple Pluggable Java Application
|
|
Recent Comments