Our Blog

Let us find tech solutions together

Aug 21

Qwicket is an easy and fast solution for creating your next project with Wicket. Right from the website, you can create an account (if you’d like to save your work as you go), and add beans to your project directly from the UI.

Qwicket 0.4 was just recently released by Justin Lee, and it features some patches I sent over to the project for integration with Jetty and HSQLDB. So when you’re looking to start your new project with wicket, your options are:

  • Download the wicket dependencies and write all your own boilerplate code
  • Use the Qwicket website, create your domain model and download the boilerplate code.

Now with the Jetty and HSQLDB additions, all the dependencies needed are handled by the Ant Maven plugin, so you can get to whats important, writing the next web 2.0 app.

Items that are planned for the future: multiple persistence framework selection (JPA, iBatis), portlet support, scaffolding, and maybe someone to help with the UI :)

Read more
Aug 21

After much loss of sleep trying to use DatePicker in wicket-extensions, I’ve instead opted to create a simple component with date selectable dropdowns of month, day, year. This little pet project was great, in that it helped me really get a better understanding of how Model’s work with Wicket, and what it takes to make a component. So instead of the javascript date chooser, we have this:

DateChooser Component Screenshot

And the only thing you pass it, is a Date in a Model, and it does the rest of the setting up. So I’ll give you a quick overview of the source and what it does, and include the code as attachments to this post.

First things first, initialization:

1
public class DateChooser extends FormComponent {

as this is going to be a component, it should extend FormComponent, if we were adding extra functionality onto an existing form element, rather than a collection of them, we could just extend that class, easy.

1
2
public DateChooser(final MarkupContainer parent, final String id, IModel model) {
super(parent, id);

This is the constructor from DateChooser, as you can see, its not a 1.x constructor, but written against the new changes in 2.0. It would be fairly simple to convert this to a 1.2 implementation.

1
2
3
new DropDownChoice(this, "month", new DateModel(model, Calendar.MONTH), getMonths(), new IChoiceRenderer() { ... }
new DropDownChoice(this, "day", new DateModel(model, Calendar.DAY_OF_MONTH), getDays());
new DropDownChoice(this, "year", new DateModel(model, Calendar.YEAR), getYears());

And here are the dropdowns, as you can see from the first dropdown, there is an added IChoiceRenderer, which in the implementation basically grabs the numeric value passed in for the choices Collection, and using SimpleDateFormat, gives the text for that month.

1
private class DateModel extends AbstractModel {

…on to the implementation of the model, making some simple use of generics here.

1
public DateModel(IModel dateModel, int calendarField) {

we create a DateModel instance, and pass it the model that is being passed to this component, and in addition we pass the calendarField value, so we know what to modify in our setObject() method.

1
2
3
4
if (dateModel.getObject() == null) return null;
Calendar cal = Calendar.getInstance();
cal.setTime((Date) dateModel.getObject());
return cal.get(calendarField);

Here we implement the getObject() method, returning the numeric value for the supplied calendarField.

1
2
3
4
5
6
7
8
9
Date date = (Date)dateModel.getObject();
if(date==null) {
    date = new Date();
}

Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(calendarField, object.intValue());
dateModel.setObject(cal.getTime());

and here’s the setObject() method, where during the submission of the form, if a Date hasn’t been added to the model yet, for us to start setting field values on, it gets created, and then using the value passed in for Object, we set each calendarField in turn as the FormComponent get processed.

There are a few different things that can be done to enhance this:

  • The days dropdown always shows 31 days, whether its got 30, 31, 28, 29, etc.
  • The ordering of the dropdowns is in M/d/y, which definitely isn't the only way to do it.

Would love comments on how to improve this, code attached.

DateChooser Component

Read more
Apr 20

With a little help from freenode folks in ##java and #awk .. I’ve got a one liner which will give you a word count for your resource bundle files:

1
grep -vE '^#' YourResourceBundle.properties | cut -d = -f 2 | wc -w

whew.

Read more