Skip to content

Usage Initialize wicket iziToast

Ryo Tsunoda edited this page Jan 27, 2021 · 1 revision

Initialize wicket-iziToast

In your application initialize process (org.apache.wicket.Application#init())

Ex. Use the IziToastBehavior to convert all feedback messages to toast.

IziToastSetting.createInitializer(this)
	.setAutoAppendBehavior(true)
	.initialize();

Ex. Use the IziToastBehavior to convert only info feedback messages to toast.

IziToastSetting.createInitializer(this)
	.setAutoAppendBehavior(true)
	.setMessageFilter(feedbackMessage -> feedbackMessage.getLevel() == FeedbackMessage.INFO)
	.initialize();

Ex. Use the IziToastBehavior to add only iziToast resources(.js .css) to page.

The all feedback messages are not converted. Only add iziToast resources to page.

IziToastSetting.createInitializer(this)
	.setAutoAppendBehavior(true)
	.setMessageFilter(feedbackMessage -> false)
	.initialize();

Ex. Set the global iziToast options.

ToastOption option = new ToastOption();
option.setPosition("topRight");
option.setCloseOnClick(true);
option.setTimeout(4000);
option.setProgressBar(true);
option.setTransitionIn("fadeIn");

IziToastSetting.createInitializer(this)
	.setAutoAppendBehavior(true)
	.setGlobalOption(option)
	.initialize();

The configuration script is executed on the client side.

iziToast.settings(options);

Ex. Set default options for each level.

Require user action only when hide error toast.

ToastOption option = new ToastOption();
option.setPosition("topRight");
option.setCloseOnClick(true);
option.setTimeout(4000);
option.setProgressBar(true);
option.setTransitionIn("fadeIn");

ToastOption errorOption = new ToastOption();
errorOption.setTimeout(0);
errorOption.setProgressBar(false);

EachLevelToastOptions eachLevelOptions = EachLevelToastOptions.builder().setErrorOption(errorOption).get();

IziToastSetting.createInitializer(this)
	.setAutoAppendBehavior(true)
	.setGlobalOption(option)
	.setGlobalEachLevelOptions(eachLevelOptions)
	.initialize();

Ex. Aggregate messages to the same level.

ToastMessageCombiner combiner = new ToastMessageCombiner();
combiner.setPrefix("・");

IziToastSetting.createInitializer(this)
	.setAutoAppendBehavior(true)
	.setToastMessageCombiner(combiner)
	.initialize();

Ex. Add the IziToastBehavior to any page by yourself.

IziToastSetting.createInitializer(this)
	.setAutoAppendBehavior(false)
	.initialize();

In your page

@Override
protected void onInitialize() {
	super.onInitialize();
 	add(new IziToastBehavior());
}