Dear Wicket users, I'm seeking your advice on designing a small Wicket application. I'm new to the list, hope I'm not violating any rules with such newbie questions. I've studied the examples, the sample phonebook app and the mailing list archive on Nabble, yet I haven't find the best practices for what I'm trying to achieve. Please feel free to point me to an appropriate example if I'm asking too much questions.
Basically, I'd like to have one form, used to search POJOs, shared by several pages, each showing the set of POJOs in a different way, e.g. as a number of JFreeChart images, as a ListView with limited number of items, as a DataView with paging. The Form seems pretty straightforward: public class TasksFilterForm extends Form<TasksFilter> > > { > > public TasksFilterForm(String id, IModel<TasksFilter> tasksFilterModel) > > { > > super(id, new CompoundPropertyModel<TasksFilter>(tasksFilterModel)); > > >> > > add(new DateTimeField("beginDate")); > > add(new DateTimeField("endDate")); > > /*skipped the rest of fields > > } > > } > > In order to reuse it, I've created a Panel: public class TasksFilterPanel extends Panel { private IModel<ArrayList<CleoTask>> tasksModel; > public TasksFilterPanel(String id, final TasksDAO tasksDAO, > IModel<TasksFilter> tasksFilterModel, final IModel<ArrayList<CleoTask>> > tasksModel) { super(id, tasksModel); this.tasksModel = tasksModel; add(new TasksFilterForm("tasksform", tasksFilterModel) { @Override protected void onSubmit() { tasksModel.setObject(tasksDAO.findByFilter(getModelObject())); } }); } 1)I'm passing the IModel<ArrayList<CleoTask>> tasksModel as the constructor argument for the panel, is this correct? 2)And what is the most appropriate model for a list of POJOs? Can you show me an example with an LDM, perhaps? What if I'd like to access it from the DataView? 3)I'm not using any ORM, just simple DAOs. Which is the most elegant way to inject them? I've checked the Spring+Wicket entry in the wiki, the approach described there works for pages, not for panels. The TasksFilterPanel is in turn used in a number of pages like this one: > public class ClusterPage extends SVAStartPage > > { > > private TasksFilter tasksFilter = new TasksFilter(); > > ArrayList<CleoTask> tasks; > > private PropertyModel<ArrayList<CleoTask>> tasksModel; > > >> public ClusterPage() throws SQLException > > { > > ArrayList<String> users = getDB().getCleoUsersArray(); > > tasksFilter.setUsers(users); > > >> tasksModel = new PropertyModel<ArrayList<CleoTask>>(this, "tasks"); > > add(new TasksFilterPanel("tasksformpanel", new TasksDAO(getDB()), new >> PropertyModel<TasksFilter>(this, "tasksFilter"), tasksModel)); > > add(new TasksChartPanel("taskschartpanel", tasksModel)); > > } > > } > > 4)Should I hold a reference to the tasksModel and tasksFilter from the TasksPage (declare it as a field, as above) ? 5)Where should I populate the tasksFilter with default values (e.g. existing users) - in the page? But then I'd have to copy/paste the code across pages... In order to display the POJOs, I've created a Panel that shows JFreeChart images. > public class TasksChartPanel extends Panel { private IModel<ArrayList<CleoTask>> tasksModel; private JFreeChartImage cImage; > > public TasksChartPanel(String id, IModel<ArrayList<CleoTask>> tasksModel) { super(id, tasksModel); this.tasksModel = tasksModel; } > @Override protected void onBeforeRender() { super.onBeforeRender(); > ArrayList<CleoTask> tasks = tasksModel.getObject(); > IntervalXYDataset ds = ... /* produce a dataset from tasks */ JFreeChart chart = ChartFactory.createScatterPlot(/* plot parameters */) if (cImage != null) remove(cImage); > cImage = new JFreeChartImage("cImage", chart, 1500, 550); add(cImage); } > @Override public boolean isVisible() { return tasksModel.getObject() != null; } } 6) I don't have a solid understanding of the request cycle yet, so I'm doing all the processing in the onBeforeRender - is this correct? 7)With this approach, I have to manually remove and re-add the image every time the set of POJOs changes - perhaps Wicket can take care of this, I just didn't find a way? That's it for now, I've tried to pinpoint the questions and not be too vague. Thank you in advance! Anatoliy.