You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jeremy Lee <je...@nz1.ibm.com> on 2007/11/17 06:51:46 UTC
How to add filtering to AjaxFallbackDefaultDataTable
Hi,
I am wanting to add a filtering component to my page which filters a
AjaxFallbackDefaultDataTable. I have seen the filter toolbar - but it is
not exactly what I need.
I have set up the filter object itself in my data provider (implemented as
IFilterStateLocator) so the actual filtering should not be a problem.
I am trying now to use a "FilterForm" accompanied with a couple of
TextFilter components however I am not too sure if this is the way to go.
It seems to me that I could just potentially use a normal form with
textfields and upon pressing the filter button I call my data provider.
(a) Could you please give me some advice with how to proceed from here.
(b) An explanation regarding how FilterForm (in particular the FOCUS-TRACKER
and FOCUS-RESTORE) and TextFilter work - as I could not really understand
the javadocs.
(c) Is the use of FilterForm and TextFilter even correct?
Look forward to some responses.
Thanks and regards,
Jeremy
--
View this message in context: http://www.nabble.com/How-to-add-filtering-to-AjaxFallbackDefaultDataTable-tf4825529.html#a13806422
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: How to add filtering to AjaxFallbackDefaultDataTable
Posted by Vincenzo Vitale <vi...@gmail.com>.
Hi,
I tried to use the FilterForm adding a TextFilter instead of the normal
TextField but then I had problems with the bindings between the FilterText
and the filter field on my (java) page... so actually I renounced and I just
put a normal Form with just a text field and in the submit implementation of
the search button I set the filter value(s) in my data provider.
So this is not exactly the answer to your questions but maybe it can help...
Here some code:
In my BaseListPage (then extended by different specific ListPages):
/**
* Creates the filter form and adds it to the page.
*
* @param accountDataProvider The dataprovider to use.
* @param dataView the data view to use for this filter form.
*/
private Form createFilterForm(
final AccountDataProvider accountDataProvider,
final DataView dataView) {
keyFilter = new ApiKey();
keyFilter.setKey("");
accountDataProvider.setFilterState(keyFilter);
keyFilterModel = new BoundCompoundPropertyModel(keyFilter);
Form returnedFilterForm = new Form("filterForm", keyFilterModel);
key = new TextField("filterByKey");
keyFilterModel.bind(key, "key");
returnedFilterForm.add(key);
cancelFilterButton = new ImageButton("cancelFilterButton") {
/**
*
*/
private static final long serialVersionUID =
-6964798131219341486L;
@Override
public void onSubmit() {
keyFilter.setKey("");
dataView.setCurrentPage(0);
setResponsePage(getPage());
}
};
cancelFilterButton.add(key);
returnedFilterForm.add(cancelFilterButton);
filterButton = new ImageButton("filterButton") {
/**
*
*/
private static final long serialVersionUID =
-6964798131219341486L;
@Override
public void onSubmit() {
dataView.setCurrentPage(0);
setResponsePage(getPage());
}
};
returnedFilterForm.add(key);
returnedFilterForm.add(filterButton);
return returnedFilterForm;
}
And then the dataprovider structure:
public abstract class AccountDataProvider extends SortableDataProvider
implements IFilterStateLocator {
/** Service that will be used to retrieve the list of accounts */
protected AccountService<? extends ApiAbstractAccount> accountService;
/**
* Reuse the key entity to store filter information.
*/
private ApiKey keyFilter;
public AccountDataProvider(
AccountService<? extends ApiAbstractAccount> accountService) {
this.accountService = accountService;
}
/**
* Retrieves the accounts from the database considering the
filterFielmodel
* passed.
*
* @param first offset for the first row of data to retrieve
* @param count number of rows to retrieve
* @param The filter model to be used.
* @return A collection of accounts.
*/
protected Collection<? extends ApiAbstractAccount> retrieveAccounts(
int first, int count, ApiKey keyFilter) {
SortParam sp = getSort();
QueryParam queryParam =
new QueryParam(first, count, sp.getProperty(),
sp.isAscending());
Collection<? extends ApiAbstractAccount> accounts = null;
accounts = accountService.find(queryParam, keyFilter);
return accounts;
}
/**
* Gets total number of items in the collection taking into account the
* filter value currently set.
*
* @return total item count
*/
public int size() {
return accountService.count(keyFilter);
}
public ApiKey getFilterState() {
return keyFilter;
}
public void setFilterState(Object state) {
keyFilter = (ApiKey) state;
}
}
and:
public class BusinessAccountDataProvider extends AccountDataProvider {
/**
* Eclipse Generated Id.
*/
private static final long serialVersionUID = -2177966069711283834L;
public BusinessAccountDataProvider(
BusinessAccountService<ApiBusinessAccount>
businessAccountService) {
super(businessAccountService);
// set the default sort
setSort("contactName", true);
}
/**
* Gets an iterator for the subset of accounts.
*
* @param first offset for the first row of data to retrieve
* @param count number of rows to retrieve
* @return iterator capable of iterating over {first, first+count}
accounts
*/
public Iterator<ApiBusinessAccountAdapterImpl> iterator(int first, int
count) {
SortParam sp = getSort();
Collection<ApiBusinessAccount> accounts =
(Collection<ApiBusinessAccount>) retrieveAccounts(first,
count,
getFilterState());
Collection<ApiBusinessAccountAdapterImpl> accountAdapters =
new ArrayList<ApiBusinessAccountAdapterImpl>();
// Vincenzo Vitale(vita) Jul 13, 2007 10:00:10 AM: Constructing the
list
// of adapters.
for (Iterator<ApiBusinessAccount> iter = accounts.iterator(); iter
.hasNext();) {
ApiBusinessAccount account = (ApiBusinessAccount) iter.next();
accountAdapters.add(new ApiBusinessAccountAdapterImpl(account));
}
return accountAdapters.iterator();
}
/**
* Converts the object in the collection to its model representation. A
good
* place to wrap the object in a detachable model.
*
* @param object The object that needs to be wrapped
* @return The model representation of the object
*/
public IModel model(Object object) {
return new DetachableAccountModel<ApiBusinessAccountAdapterImpl>(
ApiBusinessAccountAdapterImpl.class,
(ApiBusinessAccountAdapterImpl) object, accountService);
}
}
Ciao,
Vincenzo.
On Dec 10, 2007 10:16 AM, Jeremy Lee <je...@nz1.ibm.com> wrote:
>
> Hi Vincenzo,
>
> I have not had a response to date regarding this unfortunately. I am
> currently on leave so cannot work on it, however would be very interested to
> see how you go!
>
> Cheers,
>
> Jeremy Lee
> Associate Consultant
> Global Business Services
> IBM New Zealand Ltd
> DDI: +64 9 359 8569 (IBM)
> DDI: +64 9 306 5060 (Air New Zealand)
> Mob: +64 21 237 7049
> Email: jeremyl@nz1.ibm.com
On Nov 17, 2007 6:51 AM, Jeremy Lee <je...@nz1.ibm.com> wrote:
>
> Hi,
>
> I am wanting to add a filtering component to my page which filters a
> AjaxFallbackDefaultDataTable. I have seen the filter toolbar - but it is
> not exactly what I need.
>
> I have set up the filter object itself in my data provider (implemented as
> IFilterStateLocator) so the actual filtering should not be a problem.
>
> I am trying now to use a "FilterForm" accompanied with a couple of
> TextFilter components however I am not too sure if this is the way to go.
> It seems to me that I could just potentially use a normal form with
> textfields and upon pressing the filter button I call my data provider.
>
> (a) Could you please give me some advice with how to proceed from here.
> (b) An explanation regarding how FilterForm (in particular the
> FOCUS-TRACKER
> and FOCUS-RESTORE) and TextFilter work - as I could not really understand
> the javadocs.
> (c) Is the use of FilterForm and TextFilter even correct?
>
> Look forward to some responses.
>
> Thanks and regards,
>
> Jeremy
> --
> View this message in context:
> http://www.nabble.com/How-to-add-filtering-to-AjaxFallbackDefaultDataTable-tf4825529.html#a13806422
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>