Hello,

I am trying to extend a data table to be able to respond to clicks anywhere on the row table:


public interface ClickHandler<T> extends Serializable {
        public void onClick( Item<T> item );
}




public class CustomDataTable<T> extends DataTable<T> {
        private FilterForm                                      filterForm;
        private ISortableDataProvider<T>  dataProvider;
        private ClickHandler<T>                           rowClickHandler;

        public ClickHandler<T> getRowClickHandler() {
                return rowClickHandler;
        }

        public void setRowClickHandler( ClickHandler<T> rowClickHandler ) {
                this.rowClickHandler = rowClickHandler;
        }

        public boolean isClickable() {
                return rowClickHandler != null;
        }

        public CustomDataTable( String id, IColumn<T>[] columns, 
ISortableDataProvider<T> dataProvider, int rowsPerPage,
                                                        FilterForm filterForm ) 
{
                super( id, columns, dataProvider, rowsPerPage );
                this.dataProvider = dataProvider;
                this.filterForm = filterForm;
                createToolbars();
        }

        private void createToolbars() {
                addTopToolbar( new NavigationToolbar( this ) );
                if ( this.filterForm != null )
                        addTopToolbar( new FilterToolbar( this, filterForm, 
(IFilterStateLocator) dataProvider ) );

                addTopToolbar( new HeadersToolbar( this, dataProvider ) );
                addBottomToolbar( new NoRecordsToolbar( this ) );
                addBottomToolbar( new NavigationToolbar( this ) );
        }

        public CustomDataTable( String id, IColumn<T>[] columns, 
ISortableDataProvider<T> dataProvider, int rowsPerPage ) {
                this( id, columns, dataProvider, rowsPerPage, null );
        }

        @Override
        protected Item<T> newRowItem( String id, int index, IModel<T> model ) {
                return isClickable() ? new ClickableItem<T>( id, index, model, 
rowClickHandler ) : new OddEvenItem<T>( id,
                                                index, model );
        }
}


public class ClickableItem<T> extends OddEvenItem<T> implements ILinkListener {
        private ClickHandler<T>   handler;

        public ClickableItem( String id, int index, IModel<T> model, 
ClickHandler<T> handler ) {
                super( id, index, model );
                this.handler = handler;
        }

        @Override
        public void onLinkClicked() {
                handler.onClick( this );
        }

        @Override
        protected void onComponentTag( ComponentTag tag ) {
                super.onComponentTag( tag );
                tag.put(        "onclick",
                                        String.format(  
"window.location.href='%1$s';return false",
                                                                        urlFor( 
ILinkListener.INTERFACE ) ) );

                String cls = "clickable";
                String currentClass = tag.getAttributes().getString( "class" );
                if ( currentClass != null )
                        cls += " " + currentClass;

                tag.put(        "class",
                                        cls );
        }
}




Now the problem:

the links created for clicks on table row look like this:
http://localhost/app/properties/wicket:interface/:3:properties:filterForm:dataTable:rows:2::ILinkListener::/

while the url for "normal" Link is:
http://localhost/app/properties.3.2?wicket:interface=:3:properties:filterForm:dataTable:rows:3:cells:3:cell:edit:2:ILinkListener::

Clicking on the table row makes no redirect. Usually there is a redirect to: http://localhost/app/properties.3.2


When I hit refresh I get:

WicketMessage: unable to find component with path properties:filterForm:dataTable:rows:5 on stateless page [Page class = eu.org.squash.appcomponents.properties.example.PropertiesPage, id = 3, version = 5, ajax = 0] it could be that the component is inside a repeater make your component return false in getStatelessHint()

the row index "properties:filterForm:dataTable:rows:5" keeps advancing every time. There are only 2 rows in my test DataTable.

Could anyone comment? Maybe I am simply building the link for the row incorrectly.

--
Leszek Gawron

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to