Please ignore the "<br/>" tags here.. ofcourse you'd use css to position your elements, but I wasn't very imaginative when writing this example. The proposed approach definitely doesn't imply that you should hardcode your html like that. Bad bad me for making such bad taste example ;)
** Martin 2010/2/9 Martin Makundi <martin.maku...@koodaripalvelut.com>: > Hi! > > Got a bit carried away with this new thang ;) > http://old.nabble.com/Wicket-without-markup-td27506286.html > > It's finally fun adding components onto a page/panel! > > I had a go at creating a Tabbed panel with it and it's pretty neat: > > HomePage.html: > <html> > <head> > <title>Wicket Quickstart Archetype Homepage</title> > </head> > <body> > <strong>Wicket Quickstart Archetype Homepage</strong> > <form wicket:id="form"> > <wicket:container wicket:id="root-content-id"></wicket:container> > </form> > </body> > </html> > > > public class HomePage extends WebPage implements ITabbedPanelTarget { > /** */ > private static final long serialVersionUID = 1L; > private final MarkupNoLongerRequiredContainer rootContainer; > private final MarkupNoLongerRequiredContainer row0; > private final MarkupNoLongerRequiredContainer row1; > private final MarkupNoLongerRequiredContainer row2; > private final MarkupNoLongerRequiredContainer row3; > private final Form<Void> form; > private final TabbedPanelTab firstTab; > private final MarkupNoLongerRequiredContainer tabContainer; > private Panel selectedTab; > > /** > * > */ > public HomePage() { > add(form = new Form<Void>("form")); > form.add(rootContainer = new > MarkupNoLongerRequiredContainer("root-content-id")); > { > rootContainer.add(row0 = new > MarkupNoLongerRequiredContainer()); > row0.add(firstTab = new TabbedPanelTab(this, > Model.of("First"), > FirstPanel.class)); > row0.add(new TabbedPanelTab(this, Model.of("Second"), > SecondPanel.class)); > row0.add(new TabbedPanelTab(this, Model.of("Third"), > ThirdPanel.class)); > } > { > rootContainer.add(row1 = new > MarkupNoLongerRequiredContainer()); > row1.add(new Label(GID, "Hello world")); > row1.add(0, new Label(GID, > "<br/>").setEscapeModelStrings(false)); > // Change row before > row1.add(0, new Label(GID, > "<br/>").setEscapeModelStrings(false)); > // Change row twice before > row1.add(new Label(GID, > "<br/>").setEscapeModelStrings(false)); // > Change row once after > } > { > rootContainer.add(row2 = new > MarkupNoLongerRequiredContainer()); > row2.add(new Label(GID, "Type your name here:")); > row2.add(new InputField(new TextField<String>(GID, > Model.of("...")))); > } > { > rootContainer.add(row3 = new > MarkupNoLongerRequiredContainer()); > row3.add(new Label(GID, > "<br/>").setEscapeModelStrings(false)); // > Change row before > row3.add(new InputField(new Button(GID, > Model.of("Clickme")) { > �...@override > protected void onComponentTag(ComponentTag > tag) { > tag.put("type", "button"); > super.onComponentTag(tag); > } > })); > row3.add(new Label(GID, > "<br/>").setEscapeModelStrings(false)); // > Change row before > row3.add(tabContainer = new > MarkupNoLongerRequiredContainer()); > } > > firstTab.select(); > } > > public Component getSelectedTab() { > return selectedTab; > } > > public void setSelectedTabAndPanel(Panel selectedTab, Panel > newInstance) { > this.selectedTab = selectedTab; > tabContainer.set(0, newInstance); > } > } > > > > public class TabbedPanelTab extends Panel { > /** */ > private static final long serialVersionUID = -6602527646776083146L; > private final Link<Void> link; > private final ITabbedPanelTarget tabbedPanelTarget; > private final Class<? extends Panel> panelClass; > > /** > * @param tabbedPanelTarget > * @param title > */ > public TabbedPanelTab(final ITabbedPanelTarget tabbedPanelTarget, > Model<String> title, final Class<? extends Panel> panelClass) { > super(GID); > this.tabbedPanelTarget = tabbedPanelTarget; > this.panelClass = panelClass; > add(link = new Link<Void>("tab-link") { > �...@override > public void onClick() { > select(); > } > > �...@override > public boolean isEnabled() { > return !(tabbedPanelTarget.getSelectedTab() == > TabbedPanelTab.this); > } > }); > link.add(new Label("title", title)); > } > > /** > */ > public void select() { > try { > > tabbedPanelTarget.setSelectedTabAndPanel(TabbedPanelTab.this, > panelClass.getConstructor(String.class).newInstance(GID)); > } catch (Exception e) { > throw new IllegalStateException(e); > } > } > } > > > TabbedPanelTab.html: > <wicket:panel> > <a wicket:id="tab-link"><wicket:container wicket:id="title"/></a> > </wicket:panel> > > MarkupNoLongerRequiredContainer.java: > public class MarkupNoLongerRequiredContainer extends Panel { > /** */ > public static final String GID = "generic-child-id"; > > /** */ > private static final long serialVersionUID = 1L; > > private final List<Component> children = new ArrayList<Component>(); > > private ListView<Component> listView; > > private LinkedList<Component> previouslyRenderedChildren; > > public MarkupNoLongerRequiredContainer() { > this(GID); > } > > �...@override > protected void onBeforeRender() { > if (isChanged()) { > listView.removeAll(); > } > > previouslyRenderedChildren = new > LinkedList<Component>(children); > > super.onBeforeRender(); > } > > public boolean isChanged() { > if (previouslyRenderedChildren != null) { > return !((children.size() == > previouslyRenderedChildren.size()) && > previouslyRenderedChildren.containsAll(children)); > } > > return false; > } > > /** > * @param id > */ > public MarkupNoLongerRequiredContainer(String id) { > super(id); > super.add(listView = new ListView<Component>("listview-id", > children) { > /** */ > private static final long serialVersionUID = 1L; > > �...@override > protected void populateItem(ListItem<Component> > listItem) { > Component component = > listItem.getModelObject(); > if (!component.getId().equals(GID)) { > throw new > IllegalStateException("Currently handles only children > with id " + GID); > } > listItem.add(component); > } > }.setReuseItems(true)); > } > > public boolean add(Component component) { > return children.add(component); > } > > public void add(int index, Component element) { > children.add(index, element); > } > > public boolean addAll(Collection<? extends Component> collection) { > return children.addAll(collection); > } > > public boolean addAll(int index, Collection<? extends Component> > collection) { > return children.addAll(index, collection); > } > > public void clear() { > children.clear(); > } > > public boolean contains(Object o) { > return children.contains(o); > } > > public boolean containsAll(Collection<?> collection) { > return children.containsAll(collection); > } > > public int indexOf(Object o) { > return children.indexOf(o); > } > > public boolean isEmpty() { > return children.isEmpty(); > } > > public int lastIndexOf(Object o) { > return children.lastIndexOf(o); > } > > public ListIterator<Component> listIterator() { > return children.listIterator(); > } > > public ListIterator<Component> listIterator(int index) { > return children.listIterator(index); > } > > public boolean remove(Object o) { > return children.remove(o); > } > > public Component remove(int index) { > return children.remove(index); > } > > public boolean removeAll(Collection<?> collection) { > return children.removeAll(collection); > } > > public boolean retainAll(Collection<?> collection) { > return children.retainAll(collection); > } > > public Component set(int index, Component element) { > if (children.size() <= index) { > add(index, element); > } > > return children.set(index, element); > } > > public List<Component> subList(int fromIndex, int toIndex) { > return children.subList(fromIndex, toIndex); > } > > public Object[] toArray() { > return children.toArray(); > } > > public <T> T[] toArray(T[] a) { > return children.toArray(a); > } > } > > > FirstPanel.html (.java trivial too) > <wicket:panel> > <div style="background: green; width: 100%; margin: 20px;">First panel</div> > </wicket:panel> > > SecondPanel.html (.java trivial too) > <wicket:panel> > <div style="background: yellow; width: 100%; margin: 20px;">Second > panel</div> > </wicket:panel> > > > ThirdPanel.html (.java trivial too) > <wicket:panel> > <div style="background: red; width: 100%; margin: 20px;">Third panel</div> > </wicket:panel> > > ** > Martin > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org