Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WICKET-6941 Add visible attribute to AbstractColumn to hide/show columns in DataTable/DataGridView #491

Open
wants to merge 12 commits into
base: wicket-9.x
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
@@ -149,21 +149,23 @@ protected final void populateItem(final Item<T> item)
for (int i = 0; i < populatorsNumber; i++)
{
ICellPopulator<T> populator = populators.get(i);
IModel<ICellPopulator<T>> populatorModel = new Model<>(populator);
Item<ICellPopulator<T>> cellItem = newCellItem(cells.newChildId(), i, populatorModel);
cells.add(cellItem);

populator.populateItem(cellItem, CELL_ITEM_ID, item.getModel());

if (cellItem.get("cell") == null)
if (populator.isVisible())
{
throw new WicketRuntimeException(
populator.getClass().getName() +
".populateItem() failed to add a component with id [" +
CELL_ITEM_ID +
"] to the provided [cellItem] object. Make sure you call add() on cellItem and make sure you gave the added component passed in 'componentId' id. ( *cellItem*.add(new MyComponent(*componentId*, rowModel) )");
IModel<ICellPopulator<T>> populatorModel = new Model<>(populator);
Item<ICellPopulator<T>> cellItem = newCellItem(cells.newChildId(), i, populatorModel);
cells.add(cellItem);

populator.populateItem(cellItem, CELL_ITEM_ID, item.getModel());

if (cellItem.get("cell") == null)
{
throw new WicketRuntimeException(
populator.getClass().getName() +
".populateItem() failed to add a component with id [" +
CELL_ITEM_ID +
"] to the provided [cellItem] object. Make sure you call add() on cellItem and make sure you gave the added component passed in 'componentId' id. ( *cellItem*.add(new MyComponent(*componentId*, rowModel) )");
}
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,74 +1,84 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.wicket.extensions.markup.html.repeater.data.grid;

import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IDetachable;
import org.apache.wicket.model.IModel;
import org.apache.wicket.util.io.IClusterable;

/**
* Represents an object that is capable of populating an {@link Item} container representing a cell
* in a {@link DataGridView} with components.
* <p>
* Example
* <p>
*
* <pre>
* class NamePopulator implements ICellPopulator
* {
* void populateItem(final Item cellItem, final String componentId, final IModel rowModel) {
* User user=(User)rowModel.getObject(cellItem);
* String name=user.getFirstName()+&quot; &quot;+user.getLastName();
* cellItem.add(new Label(componentId, name);
* }}
* </pre>
*
* In this example the IDataProvider assigned to the DataGridView retrieves User objects from the
* database. The cell populator adds a label to the cell that will display the full name of the
* user.
*
* @see DataGridView
* @see Item
*
* @author Igor Vaynberg (ivaynberg)
*
* @param <T>
* Model object type
*/
public interface ICellPopulator<T> extends IClusterable, IDetachable
{
/**
* Method used to populate a cell in the {@link DataGridView}
*
* <b>Implementation MUST add a component to the cellItem using the component id provided by
* componentId argument, otherwise a WicketRuntimeException will be thrown</b>
*
* @param cellItem
* the item representing the current table cell being rendered
* @param componentId
* the id of the component used to render the cell (only one component should be
* added to the cell)
* @param rowModel
* the model of the row item being rendered. this model usually contains the model
* provided by the data provider.
*
* @see Item
*/
void populateItem(final Item<ICellPopulator<T>> cellItem, final String componentId,
final IModel<T> rowModel);
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.wicket.extensions.markup.html.repeater.data.grid;

import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IDetachable;
import org.apache.wicket.model.IModel;
import org.apache.wicket.util.io.IClusterable;

/**
* Represents an object that is capable of populating an {@link Item} container representing a cell
* in a {@link DataGridView} with components.
* <p>
* Example
* <p>
*
* <pre>
* class NamePopulator implements ICellPopulator
* {
* void populateItem(final Item cellItem, final String componentId, final IModel rowModel) {
* User user=(User)rowModel.getObject(cellItem);
* String name=user.getFirstName()+&quot; &quot;+user.getLastName();
* cellItem.add(new Label(componentId, name);
* }}
* </pre>
*
* In this example the IDataProvider assigned to the DataGridView retrieves User objects from the
* database. The cell populator adds a label to the cell that will display the full name of the
* user.
*
* @see DataGridView
* @see Item
*
* @author Igor Vaynberg (ivaynberg)
*
* @param <T>
* Model object type
*/
public interface ICellPopulator<T> extends IClusterable, IDetachable
{
/**
* Method used to populate a cell in the {@link DataGridView}
*
* <b>Implementation MUST add a component to the cellItem using the component id provided by
* componentId argument, otherwise a WicketRuntimeException will be thrown</b>
*
* @param cellItem
* the item representing the current table cell being rendered
* @param componentId
* the id of the component used to render the cell (only one component should be
* added to the cell)
* @param rowModel
* the model of the row item being rendered. this model usually contains the model
* provided by the data provider.
*
* @see Item
*/
void populateItem(final Item<ICellPopulator<T>> cellItem, final String componentId,
final IModel<T> rowModel);

/**
* Gets whether this column is visible in a {@link DataGridView}
*
* @return true if column is visible
*/
default boolean isVisible()
{
return true;
};
}
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.wicket.extensions.markup.html.repeater.data.grid;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

/**
* A convenience implementation of {@link ICellPopulator} that adds a label that will display the
* value of the specified property. Non-string properties will be converted to a string before
* display.
* <p>
* Example
*
* <pre>
* ICellPopulator cityPopulator = new PropertyPopulator(&quot;address.city&quot;);
* </pre>
*
* @param <T>
* @author Igor Vaynberg (ivaynberg)
*/
public class PropertyPopulator<T> implements ICellPopulator<T>
{
private static final long serialVersionUID = 1L;
private final String property;

/**
* Constructor
*
* @param property
* property whose value will be displayed in the cell. uses wicket's
* {@link PropertyModel} notation.
*/
public PropertyPopulator(final String property)
{
if (property == null)
{
throw new IllegalArgumentException("argument [property] cannot be null");
}
this.property = property;
}

/**
* @see org.apache.wicket.model.IDetachable#detach()
*/
@Override
public void detach()
{
}

/**
* @see org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator#populateItem(org.apache.wicket.markup.repeater.Item,
* java.lang.String, org.apache.wicket.model.IModel)
*/
@Override
public void populateItem(final Item<ICellPopulator<T>> cellItem, final String componentId,
final IModel<T> rowModel)
{
cellItem.add(new Label(componentId, new PropertyModel<>(rowModel, property)));
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.wicket.extensions.markup.html.repeater.data.grid;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
/**
* A convenience implementation of {@link ICellPopulator} that adds a label that will display the
* value of the specified property. Non-string properties will be converted to a string before
* display.
* <p>
* Example
*
* <pre>
* ICellPopulator cityPopulator = new PropertyPopulator(&quot;address.city&quot;);
* </pre>
*
* @param <T>
* @author Igor Vaynberg (ivaynberg)
*/
public class PropertyPopulator<T> implements ICellPopulator<T>
{
private static final long serialVersionUID = 1L;
private final String property;
/**
* Constructor
*
* @param property
* property whose value will be displayed in the cell. uses wicket's
* {@link PropertyModel} notation.
*/
public PropertyPopulator(final String property)
{
if (property == null)
{
throw new IllegalArgumentException("argument [property] cannot be null");
}
this.property = property;
}
/**
* @see org.apache.wicket.model.IDetachable#detach()
*/
@Override
public void detach()
{
}
/**
* @see org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator#populateItem(org.apache.wicket.markup.repeater.Item,
* java.lang.String, org.apache.wicket.model.IModel)
*/
@Override
public void populateItem(final Item<ICellPopulator<T>> cellItem, final String componentId,
final IModel<T> rowModel)
{
cellItem.add(new Label(componentId, new PropertyModel<>(rowModel, property)));
}
}
Original file line number Diff line number Diff line change
@@ -1,95 +1,95 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.wicket.extensions.markup.html.repeater.data.table;

import org.apache.wicket.Component;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;

/**
* A helper implementation for the IColumn interface
*
* @author Igor Vaynberg ( ivaynberg )
* @param <T>
* the type of the object that will be rendered in this column's cells
* @param <S>
* the type of the sort property
*/
public abstract class AbstractColumn<T, S> implements IStyledColumn<T, S>
{
private static final long serialVersionUID = 1L;

private final IModel<String> displayModel;

private final S sortProperty;

/**
* @param displayModel
* model used to generate header text
* @param sortProperty
* sort property this column represents
*/
public AbstractColumn(final IModel<String> displayModel, final S sortProperty)
{
this.displayModel = displayModel;
this.sortProperty = sortProperty;
}

/**
* @param displayModel
* model used to generate header text
*/
public AbstractColumn(final IModel<String> displayModel)
{
this(displayModel, null);
}

/**
* @return returns display model to be used for the header component
*/
public IModel<String> getDisplayModel()
{
return displayModel;
}

@Override
public S getSortProperty()
{
return sortProperty;
}

@Override
public Component getHeader(final String componentId)
{
return new Label(componentId, getDisplayModel());
}

@Override
public void detach()
{
if (displayModel != null)
{
displayModel.detach();
}
}

@Override
public String getCssClass()
{
return null;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.wicket.extensions.markup.html.repeater.data.table;

import org.apache.wicket.Component;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;

/**
* A helper implementation for the IColumn interface
*
* @author Igor Vaynberg ( ivaynberg )
* @param <T>
* the type of the object that will be rendered in this column's cells
* @param <S>
* the type of the sort property
*/
public abstract class AbstractColumn<T, S> implements IStyledColumn<T, S>
{
private static final long serialVersionUID = 1L;

private final IModel<String> displayModel;

private final S sortProperty;

/**
* @param displayModel
* model used to generate header text
* @param sortProperty
* sort property this column represents
*/
public AbstractColumn(final IModel<String> displayModel, final S sortProperty)
{
this.displayModel = displayModel;
this.sortProperty = sortProperty;
}

/**
* @param displayModel
* model used to generate header text
*/
public AbstractColumn(final IModel<String> displayModel)
{
this(displayModel, null);
}

/**
* @return returns display model to be used for the header component
*/
public IModel<String> getDisplayModel()
{
return displayModel;
}

@Override
public S getSortProperty()
{
return sortProperty;
}

@Override
public Component getHeader(final String componentId)
{
return new Label(componentId, getDisplayModel());
}

@Override
public void detach()
{
if (displayModel != null)
{
displayModel.detach();
}
}

@Override
public String getCssClass()
{
return null;
}
}
Original file line number Diff line number Diff line change
@@ -71,7 +71,10 @@ protected Iterator<IModel<IColumn<T, S>>> getItemModels()

for (IColumn<T, S> column : table.getColumns())
{
columnsModels.add(Model.of(column));
if (column.isVisible())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is the only involved toolbar that needs to be fixed... Did you run

mvn clean install

?

{
columnsModels.add(Model.of(column));
}
}

return columnsModels.iterator();
Original file line number Diff line number Diff line change
@@ -1,152 +1,163 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.wicket.extensions.markup.html.repeater.data.table.filter;

import java.util.LinkedList;
import java.util.List;

import org.apache.wicket.Component;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractToolbar;
import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IStyledColumn;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.string.Strings;


/**
* Toolbar that creates a form to hold form components used to filter data in the data table. Form
* components are provided by columns that implement IFilteredColumn.
*
* @author Igor Vaynberg (ivaynberg)
*/
public class FilterToolbar extends AbstractToolbar
{
private static final String FILTER_ID = "filter";
private static final long serialVersionUID = 1L;

/**
* Constructor
*
* @param table
* data table this toolbar will be added to
* @param form
* the filter form
* @param <T>
* the type of the DataTable's model object
* @param <S>
* the type of the DataTable's sorting parameter
* @param <F>
* the type of filter state object
*
*/
public <T, S, F> FilterToolbar(final DataTable<T, S> table, final FilterForm<F> form)
{
super(table);

Args.notNull(table, "table");

IModel<List<IColumn<T, S>>> model = new IModel<>() {
private static final long serialVersionUID = 1L;

@Override
public List<IColumn<T, S>> getObject() {
return new LinkedList<>(table.getColumns());
}
};

// populate the toolbar with components provided by filtered columns
ListView<IColumn<T, S>> filters = new ListView<>("filters", model)
{
private static final long serialVersionUID = 1L;

@Override
protected void populateItem(ListItem<IColumn<T, S>> item)
{
final IColumn<T, S> col = item.getModelObject();
item.setRenderBodyOnly(true);

Component filter = null;

if (col instanceof IFilteredColumn)
{
IFilteredColumn<T, S> filteredCol = (IFilteredColumn<T, S>)col;
filter = filteredCol.getFilter(FILTER_ID, form);
}

if (filter == null)
{
filter = new NoFilter(FILTER_ID);
}
else
{
if (!filter.getId().equals(FILTER_ID))
{
throw new IllegalStateException(
"filter component returned with an invalid component id. invalid component id [" +
filter.getId() +
"] required component id [" +
getId() +
"] generating column [" + col + "] ");
}
}

if (col instanceof IStyledColumn)
{
filter.add(new Behavior()
{
private static final long serialVersionUID = 1L;

/**
* @see Behavior#onComponentTag(Component, ComponentTag)
*/
@Override
public void onComponentTag(final Component component, final ComponentTag tag)
{
String className = ((IStyledColumn<?, S>)col).getCssClass();
if (!Strings.isEmpty(className))
{
tag.append("class", className, " ");
}
}
});
}

item.add(filter);
}
};
filters.setReuseItems(true);

add(filters);
}

@Override
protected void onBeforeRender()
{
if (findParent(FilterForm.class) == null)
{
throw new IllegalStateException("FilterToolbar must be contained within a FilterForm");
}
super.onBeforeRender();
}

}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.wicket.extensions.markup.html.repeater.data.table.filter;

import java.util.LinkedList;
import java.util.List;

import org.apache.wicket.Component;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractToolbar;
import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IStyledColumn;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.string.Strings;


/**
* Toolbar that creates a form to hold form components used to filter data in the data table. Form
* components are provided by columns that implement IFilteredColumn.
*
* @author Igor Vaynberg (ivaynberg)
*/
public class FilterToolbar extends AbstractToolbar
{
private static final String FILTER_ID = "filter";
private static final long serialVersionUID = 1L;

/**
* Constructor
*
* @param table
* data table this toolbar will be added to
* @param form
* the filter form
* @param <T>
* the type of the DataTable's model object
* @param <S>
* the type of the DataTable's sorting parameter
* @param <F>
* the type of filter state object
*
*/
public <T, S, F> FilterToolbar(final DataTable<T, S> table, final FilterForm<F> form)
{
super(table);

Args.notNull(table, "table");

IModel<List<IColumn<T, S>>> model = new IModel<>() {
private static final long serialVersionUID = 1L;

@Override
public List<IColumn<T, S>> getObject() {

List<IColumn<T, S>> columnsModels = new LinkedList<>();

for (IColumn<T, S> column : table.getColumns())
{
if (column.isVisible())
{
columnsModels.add(column);
}
}

return columnsModels;
}
};

// populate the toolbar with components provided by filtered columns
ListView<IColumn<T, S>> filters = new ListView<>("filters", model)
{
private static final long serialVersionUID = 1L;

@Override
protected void populateItem(ListItem<IColumn<T, S>> item)
{
final IColumn<T, S> col = item.getModelObject();
item.setRenderBodyOnly(true);

Component filter = null;

if (col instanceof IFilteredColumn)
{
IFilteredColumn<T, S> filteredCol = (IFilteredColumn<T, S>)col;
filter = filteredCol.getFilter(FILTER_ID, form);
}

if (filter == null)
{
filter = new NoFilter(FILTER_ID);
}
else
{
if (!filter.getId().equals(FILTER_ID))
{
throw new IllegalStateException(
"filter component returned with an invalid component id. invalid component id [" +
filter.getId() +
"] required component id [" +
getId() +
"] generating column [" + col + "] ");
}
}

if (col instanceof IStyledColumn)
{
filter.add(new Behavior()
{
private static final long serialVersionUID = 1L;

/**
* @see Behavior#onComponentTag(Component, ComponentTag)
*/
@Override
public void onComponentTag(final Component component, final ComponentTag tag)
{
String className = ((IStyledColumn<?, S>)col).getCssClass();
if (!Strings.isEmpty(className))
{
tag.append("class", className, " ");
}
}
});
}

item.add(filter);
}
};
filters.setReuseItems(true);

add(filters);
}

@Override
protected void onBeforeRender()
{
if (findParent(FilterForm.class) == null)
{
throw new IllegalStateException("FilterToolbar must be contained within a FilterForm");
}
super.onBeforeRender();
}

}
Original file line number Diff line number Diff line change
@@ -37,6 +37,8 @@ public class Contact implements IClusterable

private String cellPhone;

private String age;

/**
* Constructor
*/
@@ -51,7 +53,7 @@ public Contact()
public String toString()
{
return "[Contact id=" + id + " firstName=" + firstName + " lastName=" + lastName +
" homePhone=" + homePhone + " cellPhone=" + cellPhone + "]";
" homePhone=" + homePhone + " cellPhone=" + cellPhone + " age=" + age + "]";
}

/**
@@ -74,7 +76,8 @@ public boolean equals(final Object obj)
return other.getFirstName().equals(getFirstName()) &&
other.getLastName().equals(getLastName()) &&
other.getHomePhone().equals(getHomePhone()) &&
other.getCellPhone().equals(getCellPhone());
other.getCellPhone().equals(getCellPhone()) &&
other.getAge().equals(getAge());

}
else
@@ -174,4 +177,20 @@ public void setLastName(final String lastName)
{
this.lastName = lastName;
}

/**
* @return age
*/
public String getAge()
{
return age;
}

/**
* @param age
*/
public void setAge(String age)
{
this.age = age;
}
}
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@ public Contact generate()
contact.setId(generateId());
contact.setHomePhone(generatePhoneNumber());
contact.setCellPhone(generatePhoneNumber());
contact.setAge(generateAge());
return contact;
}

@@ -101,6 +102,11 @@ private String generatePhoneNumber()
.toString();
}

private String generateAge()
{
return new StringBuilder().append(rint(1, 999)).toString();
}

private int rint(final int min, final int max)
{
return (int)(Math.random() * (max - min) + min);
Original file line number Diff line number Diff line change
@@ -85,12 +85,29 @@ public String getCssClass()

columns.add(new PropertyColumn<Contact, String>(new Model<>("Home Phone"), "homePhone"));
columns.add(new PropertyColumn<Contact, String>(new Model<>("Cell Phone"), "cellPhone"));
IColumn<Contact, String> ageColumn = new PropertyColumn<Contact, String>(new Model<>("Age"), "age")
{
private static final long serialVersionUID = 1L;

public boolean isVisible()
{
return false;
}
};
columns.add(ageColumn);

@SuppressWarnings({ "rawtypes", "unchecked" })
DefaultDataTable defaultDataTable = new DefaultDataTable("table", columns,
new SortableContactDataProvider(), 8)
{
private static final long serialVersionUID = 1L;

@Override
protected void onConfigure()
{
super.onConfigure();
}

@Override
protected IModel getCaptionModel()
{
Original file line number Diff line number Diff line change
@@ -186,4 +186,16 @@ public IResourceStream getMarkupResourceStream(MarkupContainer container,
}

}
/**
* Tests that a {@link DataTable} with non-visible column will not be rendered.
*/
@Test
public void testWicket6941()
{
DataTablePage page = new DataTablePage();
tester.startPage(page);
tester.assertRenderedPage(DataTablePage.class);
assertTrue(tester.getLastResponseAsString().contains("<span wicket:id=\"label\">ID</span>"));
assertFalse(tester.getLastResponseAsString().contains("<span wicket:id=\"label\">Age</span>"));
}
}