Hi Martin,
Programmatically generating the markup as you've done below is not
really "the Wicket way", which is probably why you're bumping up against
other Wicket design decisions. I've solved similar problems using a
RepeatingView as follows:
ButtonPanel.html
<wicket:panel>
<div class="buttons">
<input wicket:id="button" type="submit"/>
</div>
</wicket:panel>
ButtonPanel.java
public class ButtonPanel extends Panel {
private RepeatingView buttons;
public ButtonPanel(String id) {
super(id);
buttons = new RepeatingView("button");
}
public void addButton(Button button) {
buttons.add(button);
}
public String newButtonId() {
return buttons.newChildId();
}
}
Then you can add whatever types of buttons you want:
ButtonPanel buttons = new ButtonPanel("buttons");
buttons.add(new Button(buttons.newButtonId()) { ... });
buttons.add(new AjaxButton(buttons.newButtonId()) { ... });
The CSS classes you add can be applied via AttributeAppender behaviors.
jk
On Wed, Oct 08, 2008 at 09:11:11AM +0200, Martin Dietze wrote:
> On Tue, October 07, 2008, Jeremy Thomerson wrote:
>
> > Maybe supply some code as an example of what you're doing. I really didn't
> > understand your scenario below.
>
> See the code below. I use a button panel which allows me to setup form
> buttons in different ways within a page class hierarchy, i.e. an edit page
> inherits from a create page but has a button more. Now I want to be able
> to add ajax buttons to the button panel.
>
> public class MyButton extends Button {
> private final String buttonType;
> public static enum ButtonType {
> BUTTON("button"),
> SUBMIT("submit"),
> RESET("reset");
> private final String buttonType;
> private ButtonType(String buttonType) {
> this.buttonType = buttonType;
> }
> public String getButtonType() {
> return this.buttonType;
> }
> }
> public MyButton(String id, IModel model, ButtonType buttonType) {
> super(id, model);
> this.buttonType = buttonType.getButtonType();
> }
> public String getButtonType() {
> return this.buttonType;
> }
> }
>
> public class ButtonPanel extends Panel implements
> IMarkupResourceStreamProvider {
> private static final String CSS_CLASS = "buttonPanel";
> private final String cssClass;
> private List<ButtonWithType> buttons;
> public ButtonPanel(String id, List<ButtonWithType> buttons, String
> cssClass) {
> super(id);
> this.buttons = buttons;
> this.cssClass = cssClass;
> if (buttons != null && buttons.size() > 0) {
> for (ButtonWithType b : buttons) {
> add(b);
> }
> }
> }
> @Override
> public IResourceStream getMarkupResourceStream(MarkupContainer container,
> Class containerClass) {
> StringBuilder result = new StringBuilder();
> result.append(" <div class=\"" + this.cssClass + "\">\n");
> int i = 0;
> for (ButtonWithType b : this.buttons) {
> result.append(" <div class=\"" + this.cssClass + (i == 0 ? "
> button leftButton" : " button") + "\">\n");
> result.append(" <input wicket:id=\"" + b.getId() + "\"\n");
> result.append(" type=\"" + b.getButtonType() + "\"
> class=\"" + this.cssClass + "\" />\n");
> result.append(" </div>\n");
> ++i;
> }
> result.append(" </div>\n");
> return new StringResourceStream("<wicket:panel>\n"
> + result.toString();
> + "</wicket:panel>\n");
>
> }
> }
>
>
> Martin
>
> --
> ----------- / http://herbert.the-little-red-haired-girl.org / -------------
> =+=
> Wer bist du, ungezaehltes Frauenzimmer? Du bist - bist du? - Die Leute sagen,
> du waerest - lass sie sagen, sie wissen nicht, wie der Kirchturm steht.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]