You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by James Carman <ja...@carmanconsulting.com> on 2008/05/04 08:00:22 UTC

[PROPOSAL] FragmentColumn...

I came up with the following class that I find very useful in our application:

public abstract class FragmentColumn<T> extends AbstractColumn<T>
{
    private static final long serialVersionUID = 1L;

    protected FragmentColumn( IModel<String> displayModel )
    {
        super(displayModel);
    }

    protected FragmentColumn( IModel<String> displayModel, String sortProperty )
    {
        super(displayModel, sortProperty);
    }

    protected abstract Fragment<T> createFragment( String componentId,
IModel<T> model );

    public void populateItem( Item<ICellPopulator<T>> item, String
componentId, IModel<T> itemModel )
    {
        item.add(createFragment(componentId, itemModel));
    }
}

Basically, it allows you to provide a Fragment (or a choice of
Fragments) as the contents of your column.  At runtime, you decide (by
overriding the createFragment() abstract method) which Fragment will
be displayed for the current row.  An example would be:

public class ActionsColumn extends FragmentColumn<Person>
{
        private static final long serialVersionUID = 1L;

        public ActionsColumn()
        {
            super(new Model<String>("Actions"));
        }

        protected Fragment<Person> createFragment(String componentId,
IModel<Person> itemModel)
        {
            if (isEditable(itemModel.getObject())) // isEditable
implementation not provided!
            {
                final Fragment<Person> fragment = new
Fragment<Person>(componentId, "actions", PersonListPage.this,
itemModel);
                fragment.add(EditPersonPage.createLink("edit", itemModel.
                return fragment;
            }
            else
            {
                return new Fragment<Person>(componentId, "doNothing",
AnalysisJobListPage.this, itemModel);
            }
        }
}

In the markup:

<wicket:fragment wicket:id="actions"><a href="#"
wicket:id="edit">edit</a></wicket:fragment>
<wicket:fragment wicket:id="doNothing">&nbsp;</wicket:fragment>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org