I have used something similar to
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.EmptyPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;
import com.google.inject.Inject;
public class EditPanel extends Panel {
private IArticleEditFactory factory;
private IArticle selected;
private Form<IArticle> form;
/**
* @param id
*/
public EditPanel(String id) {
super(id);
setOutputMarkupId(true);
form = new Form<IArticle>("form");
DropDownChoice<IArticle> choice = new
DropDownChoice<IArticle>("article", new Model<IArticle>() {
public IArticle getObject() {
return EditPanel.this.selected;
};
public void setObject(IArticle object) {
EditPanel.this.selected = object;
};
}, listWithArticles );
choice.add(new OnChangeAjaxBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
if(target != null) {
target.addComponent(EditPanel.this);
}
}
});
form.add(choice);
}
@Override
protected void onBeforeRender() {
if(selected != null) {
form.addOrReplace(factory.createArticleEditPanel("content",
selected));
} else {
form.addOrReplace(new EmptyPanel("content"));
}
super.onBeforeRender();
}
}
for such situations... I delegate creation to a factory class (so that new
products can be plugged in).
Best,
Ernesto
On Wed, Nov 11, 2009 at 2:53 PM, srm <[email protected]> wrote:
> How would you approach the following:
> PageA is used to insert an article. At first, the user chooses what kind of
> article to insert (DropDownChoice).
> When the User made his choice, a coresponding form should be loaded/visible
> underneath the
> DropDownChoice. That's all to be solved without JavaScript.
> My current idea is currently to add an Panel (AddArticlePanel) which holds
> all fields for any kind of article
> and make them visible depending on what the user has chosen (using
> onSelectionChanged).
> But that seems like a brute approach so I wanted to get your opinions on
> this.
>
> Further information will be happily provided.
>
> Regards,
> Stephan
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>