Example usage for org.apache.wicket Page add

List of usage examples for org.apache.wicket Page add

Introduction

In this page you can find the example usage for org.apache.wicket Page add.

Prototype

public MarkupContainer add(final Component... children) 

Source Link

Document

Adds the child component(s) to this container.

Usage

From source file:com.premiumminds.webapp.wicket.testing.ExtendedWicketTester.java

License:Open Source License

/**
 * Process a component. A web page will be automatically created with the {@code pageMarkup}
 * provided. In case {@code pageMarkup} is null, the markup will be automatically created with
 * {@link #createFormPageMarkup(String)}.
 * <p>/* ww w  .  j  a v a2s . c o m*/
 *     <strong>Note</strong>: the component id is set by the user. To
 *     reach any of its children use this id + their relative path to the component itself. For example
 *     if the started component has id <em>compId</em> and a Link child component component with id "link"
 *     then after starting the component you can click it with: <code>tester.clickLink("compId:link")</code>
 * </p>
 * 
 * @param <C>
 *            the type of the component
 * @param component
 *            the component to be tested
 * @param inputType
 *            the type of HTML input to be associated with the component to be tested
 * @param pageMarkup
 *            the markup for the Page that will be automatically created. May be {@code null}.
 * @return The component processed
 */
@SuppressWarnings("deprecation")
public final <C extends Component> C startComponentInForm(final C component, final String inputType,
        IMarkupFragment pageMarkup) {
    Args.notNull(component, "component");

    // Create a page object and assign the markup
    Page page = createFormPage();
    if (page == null) {
        fail("The automatically created page should not be null.");
    }

    // Automatically create the page markup if not provided
    if (pageMarkup == null) {
        String markup = createFormPageMarkup(component.getId(), inputType);
        if (markup == null) {
            fail("The markup for the automatically created page should not be null.");
        }

        try {
            // set a ContainerInfo to be able to use HtmlHeaderContainer so header contribution
            // still work. WICKET-3700
            ContainerInfo containerInfo = new ContainerInfo(page);
            MarkupResourceStream markupResourceStream = new MarkupResourceStream(
                    new StringResourceStream(markup), containerInfo, page.getClass());

            MarkupParser markupParser = getApplication().getMarkupSettings().getMarkupFactory()
                    .newMarkupParser(markupResourceStream);
            pageMarkup = markupParser.parse();
        } catch (Exception e) {
            fail("Error while parsing the markup for the autogenerated page: " + e.getMessage());
        }
    }

    if (page instanceof StartComponentInForm) {
        ((StartComponentInForm) page).setPageMarkup(pageMarkup);
    } else {
        page.setMarkup(pageMarkup);
    }

    // Add the child component
    Form<Void> form = new Form<Void>("form");
    page.add(form);
    form.add(component);

    // Preserve 'componentInForm' because #startPage() needs to null-fy it
    ComponentInForm oldComponentInForm = componentInForm;

    // Process the page
    startPage(page);

    // Remember the "root" component processes and return it
    if (oldComponentInForm != null) {
        componentInForm = oldComponentInForm;
    } else {
        componentInForm = new ComponentInForm();
        componentInForm.component = component;
    }
    return component;
}

From source file:com.userweave.pages.test.jquery.JQuery.java

License:Open Source License

public static boolean addKonquerorHacks(final Page page, IHeaderResponse response) {
    if (page.getSession().getClientInfo() instanceof WebClientInfo
            && ((WebClientInfo) page.getSession().getClientInfo()).getProperties().isBrowserKonqueror()) {
        page.add(new Behavior() {
            private static final long serialVersionUID = 1L;

            @Override/*from   w  w w . jav  a2 s  .co m*/
            public void renderHead(Component component, IHeaderResponse response) {
                response.renderCSSReference(
                        new PackageResourceReference(BasePageSurvey.class, "konquerorhacks.css"));

                if (page.getApplication().getConfigurationType().equals(RuntimeConfigurationType.DEVELOPMENT)) {
                    response.renderJavaScriptReference(
                            "http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js");
                }
            }
        });

        return true;
    }

    return false;
}

From source file:name.martingeisse.wicket.component.contextmenu.FileUploadMenuItem.java

License:Open Source License

@Override
protected void onConfigure(Component component) {
    super.onConfigure(component);
    if (!behaviorAddedToPage) {
        Page page = component.getPage();
        page.add(behavior);
        behaviorAddedToPage = true;//from   w  w  w  .ja  va2  s .  co m
    }
}

From source file:org.apache.isis.extensions.wicket.view.calendarviews.components.collection.CollectionOfEntitiesAsCalendar.java

License:Apache License

private void buildGui() {

    final List<CalendarableEvent> allEvents = Lists.newArrayList();
    EntityCollectionModel model = getModel();
    List<ObjectAdapter> adapterList = model.getObject();
    for (ObjectAdapter adapter : adapterList) {
        //            allEvents.add(new CalendarableEvent(adapter, getOidStringifier()));
        allEvents.add(new CalendarableEvent(adapter));
    }//from w w  w.  j a  v  a2s  .c o  m
    Collections.sort(allEvents);

    class CalendarableEventProvider extends LoadableDetachableModel<Collection<? extends IEvent>>
            implements IEventProvider {

        private static final long serialVersionUID = 1L;

        @Override
        protected Collection<? extends IEvent> load() {
            return allEvents;
        }

        @Override
        public void initializeWithDateRange(final Date start, final Date end) {
            // nothing to do
        }
    }

    TimePeriod tp = determineTimePeriod(allEvents);
    final IEventProvider eventProvider = new CalendarableEventProvider();

    add(new CalendarView(ID_CALENDAR_VIEW, tp, eventProvider) {
        private static final long serialVersionUID = 1L;

        @Override
        protected WebMarkupContainer createEventLink(String id, final IModel<IEvent> model) {

            final CalendarableEvent calendarEvent = (CalendarableEvent) model.getObject();

            WebMarkupContainer wmc = new WebMarkupContainer(id);

            final Class<? extends Page> pageClass = getPageClassRegistry().getPageClass(PageType.ENTITY);
            final PageParameters pageParameters = calendarEvent.getPageParameters();

            final Link<?> link = new Link<String>("link") {
                private static final long serialVersionUID = 1L;

                @Override
                public void onClick() {
                    setResponsePage(pageClass, pageParameters);
                }
            };
            wmc.add(link);
            link.add(createStartTimeLabel("startTime", model));
            link.add(new Label("title", Model.of(calendarEvent.getTitle())));

            return wmc;
        }

        /**
         * Borrowed from LargeView...
         */
        private Label createStartTimeLabel(String id, final IModel<IEvent> model) {
            return new Label(id, new LoadableDetachableModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                protected String load() {
                    // TODO : make this implementation more internationalized... this one is too static
                    //         use dateformat or something
                    DateTime start = new DateTime(model.getObject().getStartTime());
                    StringBuffer sb = new StringBuffer();
                    int hr = start.getHourOfDay();
                    sb.append(hr > 12 ? hr - 12 : hr);
                    int min = start.getMinuteOfHour();
                    if (min != 0) {
                        sb.append(':');
                        if (min < 0) {
                            sb.append('0');
                        }
                        sb.append(min);
                    }
                    sb.append(hr > 12 ? 'p' : 'a');
                    return sb.toString();
                }
            });
        }

        @Override
        protected Page createMoreDetailPage(IModel<DateMidnight> model, IModel<List<IEvent>> eventsModel) {
            Page page = super.createMoreDetailPage(model, eventsModel);
            page.add(CSSPackageResource.getHeaderContribution(EXAMPLES_CSS_REFERENCE));
            return page;
        }
    });
}

From source file:org.apache.karaf.webconsole.core.brand.DefaultBrandProvider.java

License:Apache License

public void modify(Page page) {
    page.add(new CssBehavior(BasePage.class, "style.css"));
}

From source file:org.wicketstuff.calendarviews.exampleapp.HomePage.java

License:Apache License

public HomePage(int weeks) {
    TimePeriod tp = LargeView.createMonthViewDates();
    if (weeks != 0) {
        tp = LargeView.createWeeksViewDates(weeks);
    }/*www .  j av  a2 s. co m*/
    add(new LargeView("large", tp, new PersistentRandomTestEventProvider()) {
        private static final long serialVersionUID = 1L;

        @Override
        protected Page createMoreDetailPage(IModel<DateMidnight> model, IModel<List<IEvent>> eventsModel) {
            Page page = super.createMoreDetailPage(model, eventsModel);
            page.add(new Behavior() {
                private static final long serialVersionUID = 1L;

                @Override
                public void renderHead(Component component, IHeaderResponse response) {
                    response.render(CssHeaderItem.forReference(EXAMPLES_CSS_REFERENCE));
                }
            });
            return page;
        }

        @Override
        protected WebMarkupContainer createEventLink(String id, final IModel<IEvent> model) {
            WebMarkupContainer wmc = new WebMarkupContainer(id);
            wmc.add(new AttributeModifier("onclick", new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    return "alert('" + JavaScriptUtils.escapeQuotes(model.getObject().getTitle()) + "');";
                }

            }));
            return wmc;
        }
    });

    addLinks();
}