Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:wicketstuff/core

  • Loading branch information...
commit 4ec6b586d094e1e53b2fe4fc3a3a79d162089f4d 2 parents 8d0caf7 + 5b2474b
@martin-g martin-g authored
Showing with 225 additions and 105 deletions.
  1. +2 −2 ...hod-grid-examples/src/main/java/com/inmethod/grid/examples/pages/datagrid/DataGridColumnPropertiesPage.java
  2. +4 −4 ...t/inmethod-grid-examples/src/main/java/com/inmethod/grid/examples/pages/datagrid/DataGridSelectionPage.java
  3. +13 −14 ...hod-grid-examples/src/main/java/com/inmethod/grid/examples/pages/datagrid/DataGridWithUnknownItemCount.java
  4. +2 −2 ...nt/inmethod-grid-examples/src/main/java/com/inmethod/grid/examples/pages/datagrid/EditableDataGridPage.java
  5. +2 −2 ...rid-examples/src/main/java/com/inmethod/grid/examples/pages/datagrid/EditableDataGridWithSelectionPage.java
  6. +2 −2 ...rent/inmethod-grid-examples/src/main/java/com/inmethod/grid/examples/pages/datagrid/SimpleDataGridPage.java
  7. +2 −2 ...od-grid-examples/src/main/java/com/inmethod/grid/examples/pages/datagrid/VerticalScrollingDataGridPage.java
  8. +4 −3 jdk-1.5-parent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/DataProviderAdapter.java
  9. +56 −26 jdk-1.5-parent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/common/AbstractGrid.java
  10. +8 −1 ...-parent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/common/AbstractPageableView.java
  11. +14 −14 jdk-1.5-parent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/datagrid/DataGrid.java
  12. +10 −9 jdk-1.5-parent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/datagrid/DataGridBody.java
  13. +7 −7 ...1.5-parent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/datagrid/DefaultDataGrid.java
  14. +7 −5 ...1.5-parent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/toolbar/NoRecordsToolbar.java
  15. +6 −5 ...arent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/toolbar/paging/NavigatorLabel.java
  16. +9 −4 ...parent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/toolbar/paging/PagingToolbar.java
  17. +9 −2 ...minis-parent/minis/src/main/java/org/wicketstuff/minis/behavior/validator/StringValidatorWithMaxLength.java
  18. +63 −0 ...s-parent/minis/src/test/java/org/wicketstuff/minis/behavior/validator/StringValidatorWithMaxLengthTest.java
  19. +1 −1  ...1.5-parent/scala-extensions-parent/wicket-scala/src/main/scala/org/wicketstuff/scala/SimpleComponents.scala
  20. +4 −0 jdk-1.5-parent/scala-extensions-parent/wicket-scala/src/test/scala/org/wicketstuff/scala/ComponentSpecs.scala
View
4 ...-grid-examples/src/main/java/com/inmethod/grid/examples/pages/datagrid/DataGridColumnPropertiesPage.java
@@ -76,8 +76,8 @@ public String getCellCssClass(IModel<Contact> rowModel, int rowNum)
.setSizeUnit(SizeUnit.EM)
.setResizable(false));
- DataGrid<Contact> grid = new DefaultDataGrid<Contact>("grid", new ContactDataSource(),
- columns);
+ DataGrid<IDataSource<Contact>, Contact> grid = new DefaultDataGrid<IDataSource<Contact>, Contact>(
+ "grid", new ContactDataSource(), columns);
add(grid);
grid.setRowsPerPage(15);
View
8 ...nmethod-grid-examples/src/main/java/com/inmethod/grid/examples/pages/datagrid/DataGridSelectionPage.java
@@ -51,8 +51,8 @@ public DataGridSelectionPage()
columns.add(new PropertyColumn<IDataSource<Contact>, Contact, String>(new ResourceModel(
"cellPhone"), "cellPhone"));
- final DataGrid<Contact> grid = new DefaultDataGrid<Contact>("grid",
- new ContactDataSource(), columns)
+ final DataGrid<IDataSource<Contact>, Contact> grid = new DefaultDataGrid<IDataSource<Contact>, Contact>(
+ "grid", new ContactDataSource(), columns)
{
private static final long serialVersionUID = 1L;
@@ -91,7 +91,7 @@ public String getObject()
addOptionLinks(grid);
}
- private String selectedItemsAsString(DataGrid<Contact> grid)
+ private String selectedItemsAsString(DataGrid<IDataSource<Contact>, Contact> grid)
{
StringBuilder res = new StringBuilder();
Collection<IModel<Contact>> selected = grid.getSelectedItems();
@@ -109,7 +109,7 @@ private String selectedItemsAsString(DataGrid<Contact> grid)
return res.toString();
}
- private void addOptionLinks(final DataGrid<Contact> grid)
+ private void addOptionLinks(final DataGrid<IDataSource<Contact>, Contact> grid)
{
add(new Link<Void>("cleanSelectionOnPageChangeOn")
View
27 ...-grid-examples/src/main/java/com/inmethod/grid/examples/pages/datagrid/DataGridWithUnknownItemCount.java
@@ -5,7 +5,6 @@
import org.apache.wicket.model.ResourceModel;
-import com.inmethod.grid.IDataSource;
import com.inmethod.grid.IGridColumn;
import com.inmethod.grid.SizeUnit;
import com.inmethod.grid.column.PropertyColumn;
@@ -30,21 +29,21 @@
*/
public DataGridWithUnknownItemCount()
{
- List<IGridColumn<IDataSource<Contact>, Contact>> columns = new ArrayList<IGridColumn<IDataSource<Contact>, Contact>>();
+ List<IGridColumn<ContactDataSourceWithUnknownItemCount, Contact>> columns = new ArrayList<IGridColumn<ContactDataSourceWithUnknownItemCount, Contact>>();
- columns.add(new PropertyColumn<IDataSource<Contact>, Contact, Long>(
+ columns.add(new PropertyColumn<ContactDataSourceWithUnknownItemCount, Contact, Long>(
new ResourceModel("id"), "id"));
- columns.add(new PropertyColumn<IDataSource<Contact>, Contact, String>(new ResourceModel(
- "firstName"), "firstName", "firstName"));
- columns.add(new PropertyColumn<IDataSource<Contact>, Contact, String>(new ResourceModel(
- "lastName"), "lastName", "lastName"));
- columns.add(new PropertyColumn<IDataSource<Contact>, Contact, String>(new ResourceModel(
- "homePhone"), "homePhone"));
- columns.add(new PropertyColumn<IDataSource<Contact>, Contact, String>(new ResourceModel(
- "cellPhone"), "cellPhone"));
-
- DataGrid<Contact> grid = new DefaultDataGrid<Contact>("grid",
- new ContactDataSourceWithUnknownItemCount(), columns);
+ columns.add(new PropertyColumn<ContactDataSourceWithUnknownItemCount, Contact, String>(
+ new ResourceModel("firstName"), "firstName", "firstName"));
+ columns.add(new PropertyColumn<ContactDataSourceWithUnknownItemCount, Contact, String>(
+ new ResourceModel("lastName"), "lastName", "lastName"));
+ columns.add(new PropertyColumn<ContactDataSourceWithUnknownItemCount, Contact, String>(
+ new ResourceModel("homePhone"), "homePhone"));
+ columns.add(new PropertyColumn<ContactDataSourceWithUnknownItemCount, Contact, String>(
+ new ResourceModel("cellPhone"), "cellPhone"));
+
+ DataGrid<ContactDataSourceWithUnknownItemCount, Contact> grid = new DefaultDataGrid<ContactDataSourceWithUnknownItemCount, Contact>(
+ "grid", new ContactDataSourceWithUnknownItemCount(), columns);
add(grid);
grid.setRowsPerPage(50);
View
4 ...inmethod-grid-examples/src/main/java/com/inmethod/grid/examples/pages/datagrid/EditableDataGridPage.java
@@ -71,8 +71,8 @@ protected void addValidators(FormComponent<String> component)
new ResourceModel("cellPhone"), "cellPhone"));
columns.add(new SubmitCancelColumn<IDataSource<Contact>, Contact>("esd", Model.of("Edit")));
- DataGrid<Contact> grid = new DefaultDataGrid<Contact>("grid", new ContactDataSource(),
- columns);
+ DataGrid<IDataSource<Contact>, Contact> grid = new DefaultDataGrid<IDataSource<Contact>, Contact>(
+ "grid", new ContactDataSource(), columns);
form.add(grid);
grid.setAllowSelectMultiple(true);
View
4 ...-examples/src/main/java/com/inmethod/grid/examples/pages/datagrid/EditableDataGridWithSelectionPage.java
@@ -73,8 +73,8 @@ protected void addValidators(FormComponent<String> component)
new ResourceModel("cellPhone"), "cellPhone"));
columns.add(new SubmitCancelColumn<IDataSource<Contact>, Contact>("esd", Model.of("Edit")));
- DataGrid<Contact> grid = new DefaultDataGrid<Contact>("grid", new ContactDataSource(),
- columns);
+ DataGrid<IDataSource<Contact>, Contact> grid = new DefaultDataGrid<IDataSource<Contact>, Contact>(
+ "grid", new ContactDataSource(), columns);
form.add(grid);
grid.setAllowSelectMultiple(true);
View
4 ...t/inmethod-grid-examples/src/main/java/com/inmethod/grid/examples/pages/datagrid/SimpleDataGridPage.java
@@ -41,8 +41,8 @@ public SimpleDataGridPage()
columns.add(new PropertyColumn<IDataSource<Contact>, Contact, String>(new ResourceModel(
"cellPhone"), "cellPhone"));
- final DataGrid<Contact> grid = new DefaultDataGrid<Contact>("grid",
- new ContactDataSource(), columns);
+ final DataGrid<IDataSource<Contact>, Contact> grid = new DefaultDataGrid<IDataSource<Contact>, Contact>(
+ "grid", new ContactDataSource(), columns);
add(grid);
}
View
4 ...grid-examples/src/main/java/com/inmethod/grid/examples/pages/datagrid/VerticalScrollingDataGridPage.java
@@ -42,8 +42,8 @@ public VerticalScrollingDataGridPage()
columns.add(new PropertyColumn<IDataSource<Contact>, Contact, String>(new ResourceModel(
"cellPhone"), "cellPhone"));
- DataGrid<Contact> grid = new DefaultDataGrid<Contact>("grid", new ContactDataSource(),
- columns);
+ DataGrid<IDataSource<Contact>, Contact> grid = new DefaultDataGrid<IDataSource<Contact>, Contact>(
+ "grid", new ContactDataSource(), columns);
add(grid);
grid.setRowsPerPage(30);
View
7 jdk-1.5-parent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/DataProviderAdapter.java
@@ -54,10 +54,11 @@ public void detach()
return dataProvider.model(object);
}
- private void setSortState(ISortState dest, DataGrid<T> grid, IGridSortState gridSortState)
+ private void setSortState(ISortState dest, DataGrid<? extends IDataSource<T>, T> grid,
+ IGridSortState gridSortState)
{
Set<String> unsortedColumns = new HashSet<String>(grid.getAllColumns().size());
- for (IGridColumn<IDataSource<T>, T> column : grid.getAllColumns())
+ for (IGridColumn<? extends IDataSource<T>, T> column : grid.getAllColumns())
{
if (column.getSortProperty() != null)
{
@@ -98,7 +99,7 @@ public void query(IQuery query, IQueryResult<T> result)
ISortState state = locator.getSortState();
if (state != null)
{
- DataGrid<T> grid = ((DataGrid.IGridQuery<T>)query).getDataGrid();
+ DataGrid<? extends IDataSource<T>, T> grid = ((DataGrid.IGridQuery<? extends IDataSource<T>, T>)query).getDataGrid();
setSortState(state, grid, gridSortState);
}
}
View
82 jdk-1.5-parent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/common/AbstractGrid.java
@@ -26,9 +26,9 @@
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
-import org.apache.wicket.request.Response;
import org.apache.wicket.request.resource.JavaScriptResourceReference;
import org.apache.wicket.request.resource.PackageResourceReference;
+import org.apache.wicket.util.string.AppendingStringBuffer;
import org.apache.wicket.util.string.JavaScriptUtils;
import org.apache.wicket.util.string.Strings;
import org.apache.wicket.util.visit.IVisit;
@@ -106,15 +106,33 @@ protected void onComponentTag(ComponentTag tag)
add(bottomToolbarContainer = new RepeatingView("bottomToolbarContainer"));
add(headerToolbarContainer = new RepeatingView("headerToolbarContainer"));
- // renders the initialization javascript right after the grid itself
add(new Behavior()
{
private static final long serialVersionUID = 1L;
@Override
+ public void renderHead(Component component, IHeaderResponse response)
+ {
+ super.renderHead(component, response);
+ // since javascript can be rendered at the tail
+ // of HTML document, do not initialize data grid
+ // component until "DOM ready" event.
+ if (!getWebRequest().isAjax())
+ {
+ response.renderOnDomReadyJavaScript(getInitializationJavascript(false));
+ }
+ }
+
+ @Override
public void afterRender(Component component)
{
- renderInitializationJavascript(getResponse());
+ super.afterRender(component);
+ if (getWebRequest().isAjax())
+ {
+ // renders the initialization javascript right after the grid itself
+ getResponse().write(getInitializationJavascript(true));
+
+ }
}
});
@@ -453,49 +471,61 @@ protected void onSortStateChanged(AjaxRequestTarget target)
}
/**
- * Renders the javascript required to initialize the client state for this grid instance. Called
- * after every grid render.
+ * Generates the javascript required to initialize the client state for this grid instance.
+ * Called after every grid render.
*
- * @param response
+ * @param wrapInHtmlScriptTag
+ * if true the generated js will be wrapped inside a script tag
+ * @return generated javascript code
*/
- private void renderInitializationJavascript(Response response)
+ private String getInitializationJavascript(boolean wrapInHtmlScriptTag)
{
- JavaScriptUtils.writeOpenTag(response);
- response.write("(function() {\n");
+ AppendingStringBuffer sb = new AppendingStringBuffer(128);
+ if (wrapInHtmlScriptTag)
+ {
+ sb.append(JavaScriptUtils.SCRIPT_OPEN_TAG);
+ }
+ sb.append("(function() {\n");
// initialize the columns
- response.write("var columns = [\n");
+ sb.append("var columns = [\n");
Collection<IGridColumn<M, I>> columns = getActiveColumns();
int i = 0;
for (IGridColumn<M, I> column : columns)
{
++i;
- response.write(" {");
- response.write(" minSize: " + column.getMinSize());
- response.write(", maxSize: " + column.getMaxSize());
- response.write(", id: \"" + column.getId() + "\"");
- response.write(", resizable: " + column.isResizable());
- response.write(", reorderable: " + column.isReorderable());
- response.write(" }");
+ sb.append(" {");
+ sb.append(" minSize: " + column.getMinSize());
+ sb.append(", maxSize: " + column.getMaxSize());
+ sb.append(", id: \"" + column.getId() + "\"");
+ sb.append(", resizable: " + column.isResizable());
+ sb.append(", reorderable: " + column.isReorderable());
+ sb.append(" }");
if (i != columns.size())
{
- response.write(",");
+ sb.append(",");
}
- response.write("\n");
+ sb.append("\n");
}
;
- response.write("];\n");
+ sb.append("];\n");
// method that calls the proper listener when column state is changed
- response.write("var submitStateCallback = function(columnState) { ");
- response.write(submitColumnStateBehavior.getCallbackScript());
- response.write(" }\n");
+ sb.append("var submitStateCallback = function(columnState) { ");
+ sb.append(submitColumnStateBehavior.getCallbackScript());
+ sb.append(" }\n");
// initialization
- response.write("InMethod.XTableManager.instance.register(\"" + getMarkupId() +
+ sb.append("InMethod.XTableManager.instance.register(\"" + getMarkupId() +
"\", columns, submitStateCallback);\n");
- response.write("})();\n");
- JavaScriptUtils.writeCloseTag(response);
+ sb.append("})();\n");
+
+ if (wrapInHtmlScriptTag)
+ {
+ sb.append(JavaScriptUtils.SCRIPT_CLOSE_TAG);
+ }
+
+ return sb.toString();
};
/**
View
9 ...rent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/common/AbstractPageableView.java
@@ -414,7 +414,14 @@ public void process(IDataSource<T> source)
{
// in case no items have been loaded
// this is to have the last page displayed in paging navigator
- totalCount = getCurrentPageFirstItem() + 1;
+ if (totalCount == IQueryResult.NO_MORE_ITEMS)
+ {
+ totalCount = 0;
+ }
+ else
+ {
+ totalCount = getCurrentPageFirstItem() + 1;
+ }
}
else if (totalCount == IQueryResult.NO_MORE_ITEMS)
{
View
28 jdk-1.5-parent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/datagrid/DataGrid.java
@@ -23,12 +23,14 @@
/**
* Advanced grid component. Supports resizable and reorderable columns.
*
+ * @param <D>
+ * datasource model object type = grid type
* @param <T>
* row/item model object type
*
* @author Matej Knopp
*/
-public class DataGrid<T> extends AbstractGrid<IDataSource<T>, T> implements IPageable
+public class DataGrid<D extends IDataSource<T>, T> extends AbstractGrid<D, T> implements IPageable
{
private static final long serialVersionUID = 1L;
@@ -43,8 +45,7 @@
* @param columns
* list of grid columns
*/
- public DataGrid(String id, IModel<IDataSource<T>> model,
- List<IGridColumn<IDataSource<T>, T>> columns)
+ public DataGrid(String id, IModel<D> model, List<IGridColumn<D, T>> columns)
{
super(id, model, columns);
init();
@@ -60,13 +61,12 @@ public DataGrid(String id, IModel<IDataSource<T>> model,
* @param columns
* list of grid columns
*/
- public DataGrid(String id, IDataSource<T> dataSource,
- List<IGridColumn<IDataSource<T>, T>> columns)
+ public DataGrid(String id, D dataSource, List<IGridColumn<D, T>> columns)
{
this(id, Model.of(dataSource), columns);
}
- private class Body extends DataGridBody<T>
+ private class Body extends DataGridBody<D, T>
{
private static final long serialVersionUID = 1L;
@@ -77,13 +77,13 @@ private Body(String id)
}
@Override
- protected Collection<IGridColumn<IDataSource<T>, T>> getActiveColumns()
+ protected Collection<IGridColumn<D, T>> getActiveColumns()
{
return DataGrid.this.getActiveColumns();
}
@Override
- protected IDataSource<T> getDataSource()
+ protected D getDataSource()
{
return DataGrid.this.getDataSource();
}
@@ -119,9 +119,9 @@ protected void rowPopulated(WebMarkupContainer rowItem)
*
* @return {@link IDataSource} instance
*/
- public IDataSource<T> getDataSource()
+ public D getDataSource()
{
- return (IDataSource<T>)getDefaultModelObject();
+ return (D)getDefaultModelObject();
}
private int rowsPerPage = 20;
@@ -133,7 +133,7 @@ protected void rowPopulated(WebMarkupContainer rowItem)
* how many rows (max) should be displayed on one page
* @return <code>this</code> (useful for method chaining)
*/
- public DataGrid<T> setRowsPerPage(int rowsPerPage)
+ public DataGrid<D, T> setRowsPerPage(int rowsPerPage)
{
this.rowsPerPage = rowsPerPage;
return this;
@@ -256,7 +256,7 @@ public void setAllowSelectMultiple(boolean value)
* whether the current page change should deselect all selected items
* @return <code>this</code> (useful for method chaining)
*/
- public DataGrid<T> setCleanSelectionOnPageChange(boolean cleanSelectionOnPageChange)
+ public DataGrid<D, T> setCleanSelectionOnPageChange(boolean cleanSelectionOnPageChange)
{
this.cleanSelectionOnPageChange = cleanSelectionOnPageChange;
return this;
@@ -451,13 +451,13 @@ else if (selected == false && selectedItems.contains(itemModel) == true)
*
* @author Matej Knopp
*/
- public interface IGridQuery<T> extends IDataSource.IQuery
+ public interface IGridQuery<D extends IDataSource<T>, T> extends IDataSource.IQuery
{
/**
* @return data grid issuing the query
*/
- public DataGrid<T> getDataGrid();
+ public DataGrid<D, T> getDataGrid();
};
/**
View
19 ...1.5-parent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/datagrid/DataGridBody.java
@@ -21,12 +21,14 @@
/**
* Contains data grid rows.
*
+ * @param <D>
+ * datasource model object type = grid type
* @param <T>
* row/item model object type
*
* @author Matej Knopp
*/
-public abstract class DataGridBody<T> extends Panel implements IPageable
+public abstract class DataGridBody<D extends IDataSource<T>, T> extends Panel implements IPageable
{
private static final long serialVersionUID = 1L;
@@ -45,13 +47,13 @@ public DataGridBody(String id)
add(new Data("row"));
}
- protected abstract IDataSource<T> getDataSource();
+ protected abstract D getDataSource();
protected abstract int getRowsPerPage();
protected abstract IGridSortState getSortState();
- protected abstract Collection<IGridColumn<IDataSource<T>, T>> getActiveColumns();
+ protected abstract Collection<IGridColumn<D, T>> getActiveColumns();
protected abstract boolean isItemSelected(IModel<T> itemModel);
@@ -108,7 +110,7 @@ private Data(String id)
}
@Override
- protected IDataSource<T> getDataSource()
+ protected D getDataSource()
{
return DataGridBody.this.getDataSource();
}
@@ -128,7 +130,7 @@ protected IGridSortState getSortState()
@Override
protected IQuery wrapQuery(final IQuery original)
{
- return new DataGrid.IGridQuery<T>()
+ return new DataGrid.IGridQuery<D, T>()
{
public int getCount()
{
@@ -150,7 +152,7 @@ public int getTotalCount()
return original.getTotalCount();
}
- public DataGrid<T> getDataGrid()
+ public DataGrid<D, T> getDataGrid()
{
return DataGridBody.this.findParent(DataGrid.class);
}
@@ -160,13 +162,12 @@ public int getTotalCount()
@Override
protected void populateItem(final Item<T> item)
{
- item.add(new AbstractGridRow<IDataSource<T>, T>("item",
- (IModel<T>)item.getDefaultModel())
+ item.add(new AbstractGridRow<D, T>("item", (IModel<T>)item.getDefaultModel())
{
private static final long serialVersionUID = 1L;
@Override
- protected Collection<IGridColumn<IDataSource<T>, T>> getActiveColumns()
+ protected Collection<IGridColumn<D, T>> getActiveColumns()
{
return DataGridBody.this.getActiveColumns();
}
View
14 ...-parent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/datagrid/DefaultDataGrid.java
@@ -13,12 +13,14 @@
* Convenience implementation that adds {@link PagingToolbar} and {@link NoRecordsToolbar} to the
* grid.
*
+ * @param <D>
+ * datasource model object type = grid type
* @param <T>
* row/item model object type
*
* @author Matej Knopp
*/
-public class DefaultDataGrid<T> extends DataGrid<T>
+public class DefaultDataGrid<D extends IDataSource<T>, T> extends DataGrid<D, T>
{
private static final long serialVersionUID = 1L;
@@ -33,8 +35,7 @@
* @param columns
* list of grid columns
*/
- public DefaultDataGrid(String id, IModel<IDataSource<T>> model,
- List<IGridColumn<IDataSource<T>, T>> columns)
+ public DefaultDataGrid(String id, IModel<D> model, List<IGridColumn<D, T>> columns)
{
super(id, model, columns);
init();
@@ -50,8 +51,7 @@ public DefaultDataGrid(String id, IModel<IDataSource<T>> model,
* @param columns
* list of grid columns
*/
- public DefaultDataGrid(String id, IDataSource<T> dataSource,
- List<IGridColumn<IDataSource<T>, T>> columns)
+ public DefaultDataGrid(String id, D dataSource, List<IGridColumn<D, T>> columns)
{
super(id, dataSource, columns);
init();
@@ -59,7 +59,7 @@ public DefaultDataGrid(String id, IDataSource<T> dataSource,
private void init()
{
- addBottomToolbar(new NoRecordsToolbar<T>(this));
- addBottomToolbar(new PagingToolbar<T>(this));
+ addBottomToolbar(new NoRecordsToolbar<D, T>(this));
+ addBottomToolbar(new PagingToolbar<D, T>(this));
}
}
View
12 ...-parent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/toolbar/NoRecordsToolbar.java
@@ -29,13 +29,15 @@
* The message can be overridden by providing a resource with key
* <code>datagrid.no-records-found</code>
*
+ * @param <D>
+ * datasource model object type = grid type
* @param <T>
* row/item model object type
*
* @author Igor Vaynberg (ivaynberg)
* @author Matej Knopp
*/
-public class NoRecordsToolbar<T> extends AbstractToolbar<IDataSource<T>, T>
+public class NoRecordsToolbar<D extends IDataSource<T>, T> extends AbstractToolbar<D, T>
{
private static final long serialVersionUID = 1L;
@@ -48,7 +50,7 @@
* @param table
* data table this toolbar will be attached to
*/
- public NoRecordsToolbar(final DataGrid<T> table)
+ public NoRecordsToolbar(final DataGrid<D, T> table)
{
this(table, DEFAULT_MESSAGE_MODEL);
}
@@ -59,7 +61,7 @@ public NoRecordsToolbar(final DataGrid<T> table)
* @param messageModel
* model that will be used to display the "no records found" message
*/
- public NoRecordsToolbar(final DataGrid<T> grid, IModel<String> messageModel)
+ public NoRecordsToolbar(final DataGrid<D, T> grid, IModel<String> messageModel)
{
super(grid, null);
@@ -71,9 +73,9 @@ public NoRecordsToolbar(final DataGrid<T> grid, IModel<String> messageModel)
*
* @return {@link DataGrid} instance this toolbar belongs to.
*/
- public DataGrid<T> getDataGrid()
+ public DataGrid<D, T> getDataGrid()
{
- return (DataGrid<T>)super.getGrid();
+ return (DataGrid<D, T>)super.getGrid();
}
/**
View
11 ...nt/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/toolbar/paging/NavigatorLabel.java
@@ -21,6 +21,7 @@
import org.apache.wicket.model.Model;
import org.apache.wicket.model.StringResourceModel;
+import com.inmethod.grid.IDataSource;
import com.inmethod.grid.datagrid.DataGrid;
/**
@@ -43,25 +44,25 @@
* @param table
* pageable view
*/
- public <T> NavigatorLabel(final String id, final DataGrid<T> table)
+ public <D extends IDataSource<T>, T> NavigatorLabel(final String id, final DataGrid<D, T> table)
{
super(id);
setDefaultModel(new StringResourceModel("NavigatorLabel", this,
- new Model<LabelModelObject<T>>(new LabelModelObject<T>(table)),
+ new Model<LabelModelObject<D, T>>(new LabelModelObject<D, T>(table)),
"Showing ${from} to ${to} of ${of}"));
}
- private class LabelModelObject<T> implements IClusterable
+ private class LabelModelObject<D extends IDataSource<T>, T> implements IClusterable
{
private static final long serialVersionUID = 1L;
- private final DataGrid<T> table;
+ private final DataGrid<D, T> table;
/**
* Construct.
*
* @param table
*/
- public LabelModelObject(DataGrid<T> table)
+ public LabelModelObject(DataGrid<D, T> table)
{
this.table = table;
}
View
13 ...ent/inmethod-grid-parent/inmethod-grid/src/main/java/com/inmethod/grid/toolbar/paging/PagingToolbar.java
@@ -13,9 +13,14 @@
*
* This toolbar can only be added to {@link DataTable}
*
+ * @param <D>
+ * datasource model object type = grid type
+ * @param <T>
+ * row/item model object type
+ *
* @author Matej Knopp
*/
-public class PagingToolbar<T> extends AbstractToolbar<IDataSource<T>, T>
+public class PagingToolbar<D extends IDataSource<T>, T> extends AbstractToolbar<D, T>
{
private static final long serialVersionUID = 1L;
@@ -25,9 +30,9 @@
*
* @return data grid
*/
- public DataGrid<T> getDataGrid()
+ public DataGrid<D, T> getDataGrid()
{
- return (DataGrid<T>)super.getGrid();
+ return (DataGrid<D, T>)super.getGrid();
}
/**
@@ -36,7 +41,7 @@
* @param grid
* data grid
*/
- public PagingToolbar(DataGrid<T> grid)
+ public PagingToolbar(DataGrid<D, T> grid)
{
super(grid, null);
View
11 ...is-parent/minis/src/main/java/org/wicketstuff/minis/behavior/validator/StringValidatorWithMaxLength.java
@@ -16,6 +16,12 @@
*/
public class StringValidatorWithMaxLength
{
+
+ /**
+ * "maxlength" standard html input attribute name
+ */
+ public static final String MAX_LENGTH = "maxlength";
+
/**
* Adds a maxlength attribute to the tag.
*
@@ -28,7 +34,7 @@
*/
public static void addMaxLengthToTag(Component component, ComponentTag tag, int maxLength)
{
- tag.put("maxlength", maxLength);
+ tag.put(MAX_LENGTH, maxLength);
}
/**
@@ -49,6 +55,8 @@ public static StringValidator exactLength(int length)
@Override
public void onComponentTag(Component component, ComponentTag tag)
{
+ super.onComponentTag(component, tag);
+
addMaxLengthToTag(component, tag, getLength());
}
};
@@ -69,7 +77,6 @@ public static StringValidator lengthBetween(int minimum, int maximum)
{
return new LengthBetweenValidator(minimum, maximum)
{
-
private static final long serialVersionUID = 1L;
@Override
View
63 ...arent/minis/src/test/java/org/wicketstuff/minis/behavior/validator/StringValidatorWithMaxLengthTest.java
@@ -0,0 +1,63 @@
+package org.wicketstuff.minis.behavior.validator;
+
+import org.apache.wicket.markup.IMarkupFragment;
+import org.apache.wicket.markup.Markup;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.util.tester.TagTester;
+import org.apache.wicket.util.tester.WicketTester;
+import org.apache.wicket.validation.validator.StringValidator;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests for {@link StringValidatorWithMaxLength}.
+ *
+ * @author akiraly
+ */
+public class StringValidatorWithMaxLengthTest
+{
+ private final WicketTester tester = new WicketTester();
+ private final int maxLength = 50;
+
+ @After
+ public void after()
+ {
+ tester.destroy();
+ }
+
+ @Test
+ public void testExactLength()
+ {
+ testValidator(StringValidatorWithMaxLength.exactLength(maxLength));
+ }
+
+ @Test
+ public void testLengthBetween()
+ {
+ testValidator(StringValidatorWithMaxLength.lengthBetween(maxLength - 1, maxLength));
+ }
+
+ @Test
+ public void testMaximumLength()
+ {
+ testValidator(StringValidatorWithMaxLength.maximumLength(maxLength));
+ }
+
+ private void testValidator(StringValidator validator)
+ {
+ TextField<String> field = new TextField<String>("foo");
+ field.add(validator);
+
+ IMarkupFragment markup = Markup.of("<form><input type=\"text\" wicket:id=\"" +
+ field.getId() + "\" /></form>");
+
+ tester.startComponentInPage(field, markup);
+
+ TagTester tagTester = tester.getTagByWicketId(field.getId());
+
+ Assert.assertNotNull(tagTester);
+ Assert.assertEquals(Integer.toString(maxLength),
+ tagTester.getAttribute(StringValidatorWithMaxLength.MAX_LENGTH));
+ }
+}
View
2  ...-parent/scala-extensions-parent/wicket-scala/src/main/scala/org/wicketstuff/scala/SimpleComponents.scala
@@ -13,7 +13,7 @@ import org.apache.wicket.markup.html.link.Link
import org.apache.wicket.markup.html.list.{ListView, ListItem, PropertyListView}
import org.apache.wicket.model.{IModel, Model}
-class SForm[T](id:String, model:IModel[T] , onSubmitFunc: Unit) extends Form[T](id) {
+class SForm[T](id:String, model:IModel[T] , onSubmitFunc: Unit) extends Form[T](id, model:IModel[T]) {
override def onSubmit = onSubmitFunc
View
4 ....5-parent/scala-extensions-parent/wicket-scala/src/test/scala/org/wicketstuff/scala/ComponentSpecs.scala
@@ -92,6 +92,10 @@ class ComponentSpecs extends SpecificationWithJUnit with ScalaTest with ScalaWic
def fx = sf.onSubmit
clickCountUpdatingFunction(fx)
}
+ "pass model to a super-class" in {
+ val sf = new SForm("form", new Fodel[String]("test"), {})
+ sf.getModelObject mustEq "test"
+ }
}
"SListView component" should { doBefore{ new WicketTester() }
"take a closure for the #populateItem method" in {
Please sign in to comment.
Something went wrong with that request. Please try again.