use of org.apache.wicket.markup.html.basic.Label in project wicket by apache.
the class BookDetails method link.
/**
* Creates an external page link
*
* @param name
* The name of the link component to create
* @param book
* The book to link to
* @param noBookTitle
* The title to show if book is null
* @return The external page link
*/
public static BookmarkablePageLink<Void> link(final String name, final Book book, final String noBookTitle) {
final BookmarkablePageLink<Void> link = new BookmarkablePageLink<>(name, BookDetails.class);
if (book != null) {
link.getPageParameters().add("id", book.getId());
link.add(new Label("title", new Model<>(book)));
} else {
link.add(new Label("title", noBookTitle));
link.setEnabled(false);
}
return link;
}
use of org.apache.wicket.markup.html.basic.Label in project wicket by apache.
the class ExportToolbar method onInitialize.
/**
* {@inheritDoc }
*/
@Override
protected void onInitialize() {
super.onInitialize();
WebMarkupContainer td = new WebMarkupContainer("td");
add(td);
td.add(AttributeModifier.replace("colspan", new IModel<String>() {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
return String.valueOf(getTable().getColumns().size()).intern();
}
}));
td.add(new Label("exportTo", messageModel));
RepeatingView linkContainers = new RepeatingView("linkContainer");
td.add(linkContainers);
for (IDataExporter exporter : dataExporters) {
WebMarkupContainer span = new WebMarkupContainer(linkContainers.newChildId());
linkContainers.add(span);
span.add(createExportLink("exportLink", exporter));
}
}
use of org.apache.wicket.markup.html.basic.Label in project wicket by apache.
the class AjaxTimerBehaviorTest method restartResultsInAddTimeout.
/**
* Validates the response, then makes sure the timer injects itself again when called. Tests
* {@link AbstractAjaxTimerBehavior#restart(AjaxRequestTarget)} method
*
* WICKET-1525, WICKET-2152
*/
@Test
public void restartResultsInAddTimeout() {
final Integer labelInitialValue = Integer.valueOf(0);
final Label label = new Label(MockPageWithLinkAndComponent.COMPONENT_ID, new Model<Integer>(labelInitialValue));
// the duration doesn't matter because we manually trigger the behavior
final AbstractAjaxTimerBehavior timerBehavior = new AbstractAjaxTimerBehavior(Duration.seconds(2)) {
private static final long serialVersionUID = 1L;
@Override
protected void onTimer(AjaxRequestTarget target) {
// increment the label's model object
label.setDefaultModelObject(((Integer) label.getDefaultModelObject()) + 1);
target.add(label);
}
};
final MockPageWithLinkAndComponent page = new MockPageWithLinkAndComponent();
page.add(label);
page.add(new AjaxLink<Void>(MockPageWithLinkAndComponent.LINK_ID) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
if (timerBehavior.isStopped()) {
timerBehavior.restart(target);
} else {
timerBehavior.stop(target);
}
}
});
label.setOutputMarkupId(true);
label.add(timerBehavior);
tester.startPage(page);
final String labelPath = MockPageWithLinkAndComponent.COMPONENT_ID;
// assert label == initial value (i.e. 0)
tester.assertLabel(labelPath, String.valueOf(labelInitialValue));
// increment to 1
tester.executeBehavior(timerBehavior);
// assert label == 1
tester.assertLabel(labelPath, String.valueOf(labelInitialValue + 1));
// stop the timer
tester.clickLink(MockPageWithLinkAndComponent.LINK_ID);
// trigger it, but it is stopped
tester.executeBehavior(timerBehavior);
// assert label is still 1
tester.assertLabel(labelPath, String.valueOf(labelInitialValue + 1));
// restart the timer
tester.clickLink(MockPageWithLinkAndComponent.LINK_ID);
assertMatches("Wicket.Timer.set", 1);
// WICKET-5439 label is not updated automatically
assertMatches("wicket:id=\"component\"", 0);
// increment to 2
tester.executeBehavior(timerBehavior);
// assert label is now 2
tester.assertLabel(labelPath, String.valueOf(labelInitialValue + 2));
}
use of org.apache.wicket.markup.html.basic.Label in project wicket by apache.
the class AjaxTimerBehaviorTest method setVisibleSetsTimeout.
/**
*/
@Test
public void setVisibleSetsTimeout() {
Duration dur = Duration.seconds(20);
final AjaxSelfUpdatingTimerBehavior timer = new AjaxSelfUpdatingTimerBehavior(dur);
final MockPageWithLinkAndComponent page = new MockPageWithLinkAndComponent();
final Label label = new Label(MockPageWithLinkAndComponent.COMPONENT_ID, "Hello");
page.add(label);
page.add(new AjaxLink<Void>(MockPageWithLinkAndComponent.LINK_ID) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
}
});
label.setOutputMarkupId(true);
label.setVisible(false);
label.add(timer);
tester.startPage(page);
assertMatches("Wicket.Timer.set", 0);
tester.clickLink(MockPageWithLinkAndComponent.LINK_ID);
assertMatches("Wicket.Timer.set", 0);
label.setVisible(true);
tester.startPage(page);
// no visible, so timeout is set
assertMatches("Wicket.Timer.set", 1);
}
use of org.apache.wicket.markup.html.basic.Label in project wicket by apache.
the class AjaxTimerBehaviorTest method setDisabledClearsTimeout.
/**
*/
@Test
public void setDisabledClearsTimeout() {
final AbstractAjaxTimerBehavior timer = new AbstractAjaxTimerBehavior(Duration.seconds(20)) {
private boolean enabled = true;
@Override
protected void onTimer(AjaxRequestTarget target) {
enabled = false;
}
@Override
public boolean isEnabled(Component component) {
return enabled;
}
};
final MockPageWithLinkAndComponent page = new MockPageWithLinkAndComponent();
final Label label = new Label(MockPageWithLinkAndComponent.COMPONENT_ID, "Hello");
page.add(label);
page.add(new Link<Void>(MockPageWithLinkAndComponent.LINK_ID) {
private static final long serialVersionUID = 1L;
@Override
public void onClick() {
}
});
label.setOutputMarkupId(true);
label.add(timer);
tester.startPage(page);
assertMatches("Wicket.Timer.set", 1);
tester.executeBehavior(timer);
assertMatches("Wicket.Timer.clear", 0);
assertMatches("Wicket.Timer.set", 0);
}
Aggregations