如何将CSS类添加到AbstractColumn表头

时间:2017-01-18 14:26:21

标签: java wicket wicket-6

我需要动态更改Wicket数据表的CSS类。有什么建议吗?

示例代码:

public class TextColumn<T> extends PropertyColumn<T, String>

private static final long serialVersionUID = 1L;

public TextColumn(IModel<String> displayModel, String propertyExpression)
{
    super(displayModel, propertyExpression);
}

public TextColumn(IModel<String> displayModel, String sortProperty, String propertyExpression)
{
    super(displayModel, sortProperty, propertyExpression);
}

@Override
public String getCssClass()
{
    return getPropertyExpression();
}

@Override
public void populateItem(Item<ICellPopulator<T>> item, String componentId, IModel<T> rowModel)
{
    item.add(new Label(componentId, getDataModel(rowModel)).setEscapeModelStrings(false));
}

@Override
public IModel<Object> getDataModel(IModel<T> rowModel)
{
    final IModel<Object> model = super.getDataModel(rowModel);

    final Object object = model.getObject();

    return model;

    if((object != null) )
    {
        return Model.of(new Model<String>("label here"));
    }
    else
    {
        return model;
    }
}       

}

1 个答案:

答案 0 :(得分:2)

您需要覆盖org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn#getHeader()

@Override 
public Component getHeader(final String componentId)
{
    Component header = super.getHeader(componentId);
    header.add(AttributeModifier.replace("class", "myCssClass"));
    return header;
}