Component specifications.
*
* @author Joni Freeman
* @author Timo Rantalaiho
*/
public abstract class ComponentSpecificationjava.lang.CharSequence) of the page created
* to host the specified component.
* @param rootComponentId Wicket id of the root component in the component markup hierarchy
* given by the pageMarkup parameter. This is the id of the component returned from
* newComponent method and used as context, often a MarkupContainer or Form.
*/
public T startComponent(final IModel model, final CharSequence pageMarkup, final String rootComponentId) {
return startComponent(model, new StringResourceStream(pageMarkup), rootComponentId);
}
/**
* Start component for context, using page with given markup.
*
* @param model The model passed to component that is used for context.
* @param pageMarkup Markup (as org.apache.wicket.util.resource.IResourceStream)
* of the page created to host the specified component.
* @param rootComponentId Wicket id of the root component in the component markup hierarchy
* given by the pageMarkup parameter. This is the id of the component returned from
* newComponent method and used as context, often a MarkupContainer or Form.
*/
public T startComponent(final IModel model, final IResourceStream pageMarkup, final String rootComponentId) {
WebPage page = new TestPage(pageMarkup);
specifiedComponent = newComponent(rootComponentId, model);
page.add(specifiedComponent);
wicket.startPage(page);
return specifiedComponent;
}
/**
* Start form for context, using given markup as form markup.
*
* @param model The model passed to newComponent method.
* @param formMarkup Markup (as java.lang.CharSequence)
* of the form returned from newComponent method, excluding the <form> tag.
*/
public Form startForm(final IModel model, final CharSequence formMarkup) {
return (Form) startComponent(model, "", "form");
}
/**
* Start component for context.
* * The markup file of a component is not needed. * * @param model The model passed to component that is used for context. */ public T startComponentWithoutMarkup(final IModel model) { specifiedComponent = newComponent("component",model); wicket.startComponent(specifiedComponent); return specifiedComponent; } protected void startBorder(final IModel model) { wicket.startPanel(new TestPanelSource() { public Panel getTestPanel(String panelId) { Panel panel = new Container(panelId); specifiedComponent = newComponent("component", model); panel.add(specifiedComponent); return panel; } }); } protected void startPanel(final IModel model) { wicket.startPanel(new TestPanelSource() { public Panel getTestPanel(String panelId) { specifiedComponent = newComponent(panelId, model); return (Panel) specifiedComponent; } }); } protected void startPage(final IModel model) { specifiedComponent = newComponent(null, model); TestPageSource testPageSource = new TestPageSource((Page) specifiedComponent); wicket.startPage(testPageSource); } private static class TestPageSource implements ITestPageSource { private Page page; public TestPageSource(Page page) { this.page = page; } public Page getTestPage() { return page; } } private static class TestPage extends WebPage implements IMarkupResourceStreamProvider { private final IResourceStream markup; public TestPage(final IResourceStream markup) { this.markup = markup; } @SuppressWarnings("unchecked") public IResourceStream getMarkupResourceStream(MarkupContainer container, Class containerClass) { return markup; } } /** * Specify that given container contains given model objects. *
* This is most often used with RefreshingViews and ListViews.
*
* * @param actual the container of Wicket components * @param containment any containment, see: http://www.jdave.org/documentation.html#containments */ public void specify(MarkupContainer actual, IContainment containment) { super.specify(modelObjects(actual.iterator()), containment); } /** * Select an item from a* * ListView list = new ListView("stooges", Arrays.asList("Larry", "Moe", "Curly")) { ... }; * specify(list, containsInOrder("Larry", "Moe", "Curly"); * *
RepeatingView.
*/
public Item itemAt(RepeatingView view, int index) {
Iterator> items = view.iterator();
for (int i = 0; i < index; i++) {
items.next();
}
return (Item) items.next();
}
/**
* Select an item from a ListView.
*/
public ListItem itemAt(ListView view, int index) {
Iterator> items = view.iterator();
for (int i = 0; i < index; i++) {
items.next();
}
return (ListItem) items.next();
}
/**
* Collect model objects from given components.
*/
public List> modelObjects(Iterator> components) {
@SuppressWarnings("unchecked")
Iterator extends Component> unsafe = (Iterator extends Component>) components;
List