Skip to content
PMJMendes edited this page Dec 17, 2014 · 7 revisions

AbstractDrawer

AbstractDrawer is the base class from which drawers used with DrawerManager must derive.

How to use

DrawerManager is an abstract class and is not meant to be used directly. Instead, each actual drawer class must derive from it and extend it, in the same manner as any other component that derives from a wicket Panel. At the very least, derived classes should override onInitialize() to create and initialize their content.

Projects may also implement their own intermediate abstract classes if they want common functionality in all drawers across the application, as shown in the following example:

<wicket:panel>
    <button data-dismiss="modal-drawer" aria-hidden="true">
        <span><wicket:container wicket:id="back">back</wicket:container></span>
    </button>
    <wicket:container wicket:id="title"></wicket:container>
    <wicket:container wicket:id="subtitle"></wicket:container>
    <button class="btn-flat submit" wicket:id="submit">
        <wicket:message key="submit" />
    </button>
    <div wicket:id="content"></div>
</wicket:panel>
public abstract class AppBaseDrawer extends AbstractDrawer {
	private static final long serialVersionUID = 1L;
	public static final String CONTENT_ID = "content";
	public static final String SMALL_SIZE_CSS = "small-stack";
	
	@Override
	protected void onInitialize() {
		super.onInitialize();
		add(new Label("title", getTitle()));
		add(new Label("subtitle", getSubtitle()));
		add(getSubmitComponent("submit")); 
		
		add(new Label("back", getClose()));
		add(getContent(CONTENT_ID));
	} 

	
	public String getTitle(){
		return getString("title", getDefaultModel(), "");
	}

	private String getSubtitle() {
		return getString("subtitle", getDefaultModel(), "");
	}

	/*
	 * Override me to add a submit 
	 */
	public Component getSubmitComponent(String string) {
		return new EmptyPanel(string).setVisible(false);
	}
	
	private String getClose() {
		return getString("back", getDefaultModel(), "BACK");
	}
	
	public abstract Panel getContent(String id);
}

Note that the data-dismiss element on the back button is important to make the button invoke the javascript that ultimately calls the AJAX behaviour on the server which causes the drawer to be closed.

Clone this wiki locally