Hello all, thanks for this nice framework.
My project is an interface to insert the data of a questionnaire into a database. The pages are mostly forms forms forms...
Now i want to have on one page something like an editable combo box (at least that would be the widget of choice in Swing) (in fact several of them - there are several similar blocks on that page). So i put a combo box on the page and a textfield with a button there. All of them are part of a bigger form so that i have to use a wicket button inside a wicket form for it (imho). It should be possible to change the combo boxes by typing into the textfields and hitting the button next to it.
My page class is structured like: Constructor() - add the BigForm instanceprivate class BigForm - add the blocks (for several questions of the questionnaire) through several calls to the method addModule() - addModule() adds a textarea, the combobox, the textfield and the button private class MyButton - overwrites onSubmit to make the textfield value persistent (Dao, Hibernate etc.) and to reload the appropriate Combobox (using combobox.updateModel())
My class uses a CompoundPropertyModel which is backed by the Pojo that represents all the properties set by the BigForm instance - except of course the textfield which in fact is just a helper for the user to add new values to the comboboxes more quickly. Thus, the textfield has no property neither in the model nor in the backing pojo.
I tried to use a PropertyModel just for the Textfield and use that again inside the button class to get hold of the textfield value. But this obviously does not work? do i have to add the textfield directly to my page not to the BigForm instance?
I'd appreciate any help or enlightment on the handling of the models. I'm a Java Swing developer and rather poor on the html side.
I attach the class and the html template to this mail as it might help to look at the code. (Don't wonder about the names - i used some simple names in the mail. The actual names are different.)
Thanks in advance, Chantal
Fragebogen-ID id
2.1.1 Was bedeutet dieser Begriff ("Navigation") in dieser Situation für Sie?
Die wortwörtliche Antwort
2.1.2 Was erwarten Sie, wenn Sie diesen Menüpunkt auswählen?
Die wortwörtliche Antwort
2.2.1 Untermenü Zielliste
Die wortwörtliche Antwort
2.2.2 Untermenü Bordinfo
Die wortwörtliche Antwort
2.2.3 Untermenü Adressbuch
Die wortwörtliche Antwort
2.2.4 Untermenü Informationen
Die wortwörtliche Antwort
2.2.5 Untermenü Verkehrsinfo
Die wortwörtliche Antwort
2.2.6 Untermenü Neues Ziel
Die wortwörtliche Antwort
2.4.1 Untermenü Neues Ziel (Begriffsklärung)
Die wortwörtliche Antwort
2.4.2 Untermenü Zieleingabe (Begriffsklärung)
Die wortwörtliche Antwort
2.4.3 Informationen unterhalb von Navigation
Die wortwörtliche Antwort
2.4.4 Informationen unterhalb von Neues Ziel
Die wortwörtliche Antwort
package de.ipsk.tummic.menufragebogen.page; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import wicket.markup.html.basic.Label; import wicket.markup.html.form.*; import wicket.markup.html.panel.FeedbackPanel; import wicket.model.CompoundPropertyModel; import wicket.model.IModel; import wicket.model.PropertyModel; import de.ipsk.tummic.menufragebogen.model.*; public class NaviPage extends FbPage { public NaviPage(Person p) { super("2 Navigationssystem (Teil 1)"); log.info("NaviPage()"); add(new Label("id", "" + p.getId())); final Navi navi = (Navi)getDao().findNaviForPerson(p); IModel naviModel = new CompoundPropertyModel(navi); add(new NaviForm(naviModel, p)); FeedbackPanel feedback = new FeedbackPanel("feedback"); add(feedback); } private class NaviForm extends Form { public NaviForm(IModel model, final Person p) { // super("form", model, feedback); super("form", model); log.info("NaviForm()"); addQuestionBlock("semNavi", new IdStringSemNavi()); addQuestionBlock("funcNavi", new IdStringFuncNavi()); addQuestionBlock("semZielliste", new IdStringSemZielliste()); addQuestionBlock("semBordinfo", new IdStringSemBordinfo()); addQuestionBlock("semAdressbuch", new IdStringSemAdressbuch()); addQuestionBlock("semInfo", new IdStringSemInfo()); addQuestionBlock("semVerkehrsinfo", new IdStringSemVerkehrsinfo()); addQuestionBlock("semNeuziel", new IdStringSemNeuziel()); addQuestionBlock("semNeuziel2", new IdStringSemNeuziel2()); addQuestionBlock("semZieleingabe", new IdStringSemZieleingabe()); addQuestionBlock("semNaviInfo", new IdStringSemNaviInfo()); addQuestionBlock("semZielInfo", new IdStringSemZielInfo()); } // @Override public void onSubmit() { log.info("NaviForm.onSubmit()"); Navi navi = (Navi)getDao().merge(getModelObject()); setResponsePage(new UnterfuncNaviPage(navi.getPerson())); } public void addQuestionBlock(String qid, Object catObject) { add(new TextArea(qid + "Original")); Class c = catObject.getClass(); List l = getDao().findAllFromClass(c).setUsePaging(false); DropDownChoice choice = new DropDownChoice(qid, l); add(choice); IModel tfModel = new PropertyModel(catObject, "text"); add(new TextField(qid + "Cat", tfModel)); add(new NewCategoryButton(qid + "Button", tfModel, c, choice)); } } private class NewCategoryButton extends Button { private final DropDownChoice choice; private final Class cl; public NewCategoryButton(String id, IModel model, Class c, DropDownChoice choice) { super(id, model); log.info("NewCategoryButton():" + getId()); log.info("model: " + model); setDefaultFormProcessing(false); this.choice = choice; this.cl = c; } // @Override public void onSubmit() { log.info("NewCategoryButton.onSubmit():" + getId()); log.info("Model: " + getModel()); getDao().merge(getModelObject()); choice.setChoices(getDao().findAllFromClass(cl)); choice.updateModel(); } } private final static Log log = LogFactory.getLog(NaviPage.class); }