Hello,
I try to modify the header of a table. So according to the advice of this
mailing list, I write
public class DataTableFilterToolbarPage extends WebPage
{
/**
* constructor
*/
public DataTableFilterToolbarPage()
{
List<IColumn<Contact, String>> columns = new ArrayList<IColumn<Contact,
String>>();
columns.add(new PropertyColumn<Contact, String>(new
Model<String>("ID"), "id")
{ private static final long serialVersionUID = 1L;
@Override
public Component getHeader(final String componentId)
{ X1 x = new X1(componentId,"id") ; // My own panel instead of a
label
return x;
}
});
As I want to set the sortable link in a part of X1, I modify HeadersToolbar
public <T> HeadersToolbar(final DataTable<T, S> table, final
ISortStateLocator<S> stateLocator)
{
super(table);
RefreshingView<IColumn<T, S>> headers = new RefreshingView<IColumn<T,
S>>("headers")
{
private static final long serialVersionUID = 1L;
@Override
protected Iterator<IModel<IColumn<T, S>>> getItemModels()
....
@Override
protected void populateItem(Item<IColumn<T, S>> item)
{
if (column.isSortable())
{
header = newSortableHeader("header",
column.getSortProperty(), stateLocator);
}
else
{
header = new WebMarkupContainer("header");
}
if (column instanceof IStyledColumn)
{ .... }
item.add(header);
item.setRenderBodyOnly(true)
((X1)column.getHeader("panel")).ajout() ; // action on X1
header.add(column.getHeader("panel"));
Where X1 is
public class X1 extends Panel
{
public X1(String id, String ColumnTilte) //, TextField<String> x)
{
super(id) ;
lbl = new Label("labelx", ColumnTilte) ;
add(lbl) ;
}
public Label getLabel() { return lbl ; }
public void ajout()
{
add(new Label("phl","added by headersTools")) ;
}
}
Run this code, I get
Unexpected RuntimeException
Last cause: Unable to find component with id 'phl' in [X1 [Component id =
panel]]
Expected:
'filterForm:tableWithFilterForm:topToolbars:toolbars:3:headers:1:header:panel:phl'.
Found with similar names: ''
Markup
The problem is in
"file:/home/phl/apache-tomcat-7.0.47/webapps/phlwick/WEB-INF/classes/xxx/X1.html":
<wicket:panel xmlns:wicket="http://wicket.apache.org">
1<br />
<span style="color: Blue;">
<span wicket:id="labelx" id="labelx">The Title of the column
goes here</span>
</span>
<br/>
<span wicket:id="phl">Action from HeadersTools goes here</span> <br />
</wicket:panel>
I was expecting that the action ((X1)column.getHeader("panel")).ajout() ; will
define phl in X1
If I change the X.java to
public class X1 extends Panel
{
public X1(String id, String ColumnTilte) //, TextField<String> x)
{
super(id) ;
lbl = new Label("labelx", ColumnTilte) ;
add(lbl) ;
add(new Label("phl","added by constructor")) ;
}
public Label getLabel() { return lbl ; }
public void ajout()
{
add(new Label("phl","added by headersTools")) ;
}
}
So I don't understand why the some time the id phl is not declared and sometime
is it already declared.
This is probably due to the fact that I don't clearly understand the render
mechanism.
Pointers or ideas are welcome.
Thanks,
PHL.
Then I get :
Last cause: A child with id 'phl' already exists:
[X1 [Component id = panel]]
WicketMessage: Error attaching this container for rendering: [HeadersToolbar
[Component id = 3]]