|
Hi Nathan,
My previous description of the problem was not very accurate, but now I've managed to workaround the problem by calling the second SearchPanel constructor, anyway I guess the current code still has problems, see (untouched code):
public abstract class SearchPanel extends Panel {
private TextField search;
/**
* @param id Wicket id
*/
public SearchPanel(String id) {
super(id, new Model());
add(new SearchForm("searchForm"));
}
/** Use the given model (must not be read-only ) for the search string */
public SearchPanel(String id, IModel searchModel) {
super(id, searchModel);
add(new SearchForm("searchForm"));
}
@Override
/** Sets model to search component. */
public MarkupContainer setDefaultModel(IModel model) {
return search.setDefaultModel(model);
}
As you can see, calling the second constructor sets the SearchPanel's model by calling super constructor, but if you use the first constructor and then call setDefaultModel, then the SearchPanel's own model is never set to the same model as search TextField.
One possible fix would be like this:
@Override
/** Sets model to search component. */
public MarkupContainer setDefaultModel(IModel model) {
++ super.setDefautlModel(model);
return search.setDefaultModel(model);
}
But then you would still need to call setDefaultModel even if you use the second constructor. A better solution would require some refactoring of both constructors and setDefaultModel method.
Hope this helps,
Daniel
|