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

task/4.x/date filter #436

Open
wants to merge 2 commits into
base: dgtkit-4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.devgateway.toolkit.forms.wicket.components.table;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.extensions.markup.html.repeater.data.table.filter.FilterForm;
import org.apache.wicket.extensions.markup.html.repeater.data.table.filter.TextFilteredPropertyColumn;
import org.apache.wicket.model.IModel;
Expand Down Expand Up @@ -32,7 +33,12 @@ public Component getFilter(final String componentId, final FilterForm<?> form) {
final DateFieldBootstrapFormComponent dateField =
new DateFieldBootstrapFormComponent(componentId, getFilterModel(form));
dateField.hideLabel();
dateField.getField().add(AttributeModifier.replace("onchange", "this.form.submit();"));
dateField.getField().add(new AjaxFormComponentUpdatingBehavior("change") {
@Override
protected void onUpdate(final AjaxRequestTarget target) {
target.add(form);
}
});
return dateField;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.devgateway.toolkit.forms.wicket.components.table;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.extensions.markup.html.repeater.data.table.filter.FilterForm;
import org.apache.wicket.extensions.markup.html.repeater.data.table.filter.TextFilteredPropertyColumn;
import org.apache.wicket.model.IModel;
Expand All @@ -28,7 +29,12 @@ public Component getFilter(final String componentId, final FilterForm<?> form) {
final LocalDateFieldBootstrapFormComponent dateField =
new LocalDateFieldBootstrapFormComponent(componentId, getFilterModel(form));
dateField.hideLabel();
dateField.getField().add(AttributeModifier.replace("onchange", "this.form.submit();"));
dateField.getField().add(new AjaxFormComponentUpdatingBehavior("change") {
@Override
protected void onUpdate(final AjaxRequestTarget target) {
target.add(form);
}
});
return dateField;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import javax.persistence.criteria.Predicate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
Expand All @@ -18,6 +19,8 @@ public class TestFormFilterState extends JpaFilterState<TestForm> {
private static final long serialVersionUID = 8005371716983257722L;
private String textField;

private Date date;

@Override
public Specification<TestForm> getSpecification() {
return (root, query, cb) -> {
Expand All @@ -29,6 +32,9 @@ public Specification<TestForm> getSpecification() {
if (StringUtils.isNotBlank(textField)) {
predicates.add(cb.like(root.get(TestForm_.textField), "%" + textField + "%"));
}
if (date != null) {
predicates.add(cb.equal(root.get(TestForm_.date), date));
}
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
};
}
Expand All @@ -40,4 +46,12 @@ public String getTextField() {
public void setTextField(final String textField) {
this.textField = textField;
}

public Date getDate() {
return date;
}

public void setDate(final Date date) {
this.date = date;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.devgateway.toolkit.forms.security.SecurityConstants;
import org.devgateway.toolkit.forms.wicket.components.table.DateFilteredBootstrapPropertyColumn;
import org.devgateway.toolkit.forms.wicket.components.table.TextFilteredBootstrapPropertyColumn;
import org.devgateway.toolkit.forms.wicket.components.table.filter.JpaFilterState;
import org.devgateway.toolkit.forms.wicket.components.table.filter.TestFormFilterState;
Expand All @@ -42,6 +44,7 @@ public ListTestFormPage(final PageParameters pageParameters) {
this.editPageClass = EditTestFormPage.class;

columns.add(new TextFilteredBootstrapPropertyColumn<>(new Model<>("Text Field"), "textField", "textField"));
columns.add(new DateFilteredBootstrapPropertyColumn<>(new StringResourceModel("date"), "date", "date"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
# Development Gateway - initial API and implementation
###############################################################################
page.title=DG Toolkit Components Test
name=Name
name=Name
date=Date