
October 2009
August 2009
April 2009
March 2009
December 2008
October 2008
September 2008
August 2008
July 2008
June 2008
I’ve been spending a lot of time on Wicket lately for some exciting things that will be coming soon from Me.dium. One cool trick I started using the ListView. If you’ve come from PHP or any other web language, you know the drill– display query data from the database on a web page.
Here’s a simple implementation of the ListView to help you get started. I’m going to take a list of employees and output them to the screen. This tutorial assumes you know the basics of how Wicket works. This is the portion where we’re adding components to the display piece.
EmployeesPage.java
//Now I’ll populate the ListView with the query results
add(new ListView(“employeesRptr”, employees) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(ListItem item) {
User employee = (User) item.getModelObject();
// image display
item.add(new StaticImage(“profilePic”, new Model(employee.getPicture())));
// name display
StringBuilder name = new StringBuilder();
name.append(employee.getFirstName());
name.append(” “);
name.append(employee.getLastName());
item.add(new Label(“profileName”, name.toString()));
// location display
item.add(new Label(“profileLocation”, employee.getLocation()));
}
});
Now for the display:
EmployeesPage.html
<span wicket:id=”employeesRptr”>
<img wicket:id=”profilePic” border=”0″ />
<p class=”name” wicket:id=”profileName”>Joe Schmo</p>
<p class=”location” wicket:id=”profileLocation”>location</p>
</span>
Enjoy!
Tags: frameworks, Java, reference, wicket
Although it is tempting to write your own javascript or use external javascript libraries such as jquery, Wicket has its own built in dojo integration.
This integration makes using dojo pretty easy, but styling your UI is not so straight forward. In this example, I implement the DojoTooltip on a form text field on the hover action. The use of the standard DojoTooltip as well as other dojo/wicket examples can be found here.
I highly recommend installing the Jad decompiler for Eclipse if you are going to delve into this as documentation is very light and having the decompiler will help you understand what is available to you in the libraries.
Here is a screenshot of the wicket example I started from, note the black border–this is not acceptable for my UI:

I need something that looks more like this:

The key to getting exactly what you want is overriding the CSS that comes with the framework.
public class MyTooltipPage extends MyPageTemplate
{
private WebMarkupContainer hoverTarget;
public MyTooltipPage()
{
super();
hoverTarget = new WebMarkupContainer("hoverTarget");
add(hoverTarget);
DojoTooltip hoverTooltip = new DojoTooltip("hoverTooltip", hoverTarget);
add(hoverTooltip);
hoverTooltip.add(new TooltipPanel("tooltipPanel"));
}
}
Next I create the panel that will display the tooltip upon the hover:
public class TooltipPanel extends Panel
{
private Page page;
public TooltipPanel(String id)
{
super(id);
}
}
Here is the HTML snippet for the input–this is the page where my form field lives that I want to apply the over state on.
<span wicket:id="hoverTooltip"><span wicket:id="tooltipPanel "/></span>
<div wicket:id="hoverTarget">
<form>
<input type=”text”>
</form>
</div>
Here is the HTML for the panel that will pop up on the hover state.
<div id="searchTooltip">
<div class="tooltipPointer"><img src="/images/darkPointerUp.gif" alt="" /></div>
It's a search box you know you want to try it.
enter anything you like and let us find it for you
</div>
Finally, the most important piece of this puzzle is overriding the .dojoTooltip class which is contained in the framework CSS. Using the !important designations will ensure that your attributes are used rather than the default despite the ordering of the CSS files themselves:
.dojoTooltip {
background-color: #ffffff !important;
border: 2px solid #ff6d04 !important;
position: fixed !important;
left: 35px !important;
top: 130px !important;
}
#searchTooltip {
margin: 0 5px 10px 5px;
font-weight:bold;
size:14px;
position:relative;
top: -10px;
}
#searchTooltip .tooltipPointer {
position: relative;
z-index: 1000;
top:-3px;
left: 30px;
}
Hope this saves someone some time, enjoy!