How to place form in own public class for extending
I am trying to move a form from an inner class that extends Form to a public class. This is so that I can override the onSubmit() method of my form. Below are my files. When I add the form to a wicket page with add(new TemplateEditForm(templateeditform, templatemodel)); and the corresponding html code form wicket:id=templateeditformeditform/form My wicket code doesn't pick the wicket:ids in the TemplateEditForm.html file up WicketMessage: The component(s) below failed to render. A common problem is that you have added a component in code but forgot to reference it in the markup (thus the component will never be rendered). 1. [MarkupContainer [Component id = name]] 2. [MarkupContainer [Component id = version]] 3. [MarkupContainer [Component id = author]] 4. [MarkupContainer [Component id = active]] 5. [MarkupContainer [Component id = description]] 6. [MarkupContainer [Component id = textarea]] 7. [MarkupContainer [Component id = type]] 8. [MarkupContainer [Component id = submit]] I am sure I am doing something stupid, but I cannot find the solution to this. Any ideas? = public class TemplateEditForm extends Form { private TemplateWebModel templatemodel; public TemplateEditForm(String id, TemplateWebModel templatemodel) { super(id); this.templatemodel = templatemodel; setModel(new CompoundPropertyModel(templatemodel)); add(new RequiredTextField(name)); add(new RequiredTextField(version, java.lang.Long.class)); add(new RequiredTextField(author)); add(new CheckBox(active)); add(new VariableTextFieldPanel(description, new PropertyModel( templatemodel.getObject(), description))); DropDownChoice ddc = new DropDownChoice(type, Arrays .asList(TemplateType.values()), new IChoiceRenderer() { public Object getDisplayValue(Object object) { return getString(object.toString()); } public String getIdValue(Object object, int index) { return object.toString(); } }); ddc.setRequired(true); add(ddc); add(new Button(submit, new ResourceModel(submit))); } @Override public void onSubmit() { WicketApplication.get().getTemplateFactory().store( templatemodel.getEntity()); setResponsePage(new TemplateListPage()); } } And the corresponding html code === wicket:extend table tr tdwicket:message key=name //td tdinput wicket:id=name //td /tr tr tdwicket:message key=version //td tdinput wicket:id=version //td /tr tr tdwicket:message key=author //td tdinput wicket:id=author //td /tr tr tdwicket:message key=active //td tdinput type=checkbox wicket:id=active //td /tr tr tdwicket:message key=description //td tdspan wicket:id=description/span/td /tr tr tdwicket:message key=type //td tdselect wicket:id=type option/option /select/td /tr tr td colspan=2input wicket:id=submit type=submit/td /tr /table /wicket:extend
Re: How to place form in own public class for extending
I usually make a panel, add the form to the panel and write up the form in the panel's markup. http://wicketstuff.org/wicket13/signin/?wicket:bookmarkablePage=:org.apache.wicket.examples.signin.SignIn Ryan Gravener http://ryangravener.com/flex | http://twitter.com/ryangravener On Wed, Feb 11, 2009 at 9:40 AM, pieter claassen pie...@claassen.co.ukwrote: I am trying to move a form from an inner class that extends Form to a public class. This is so that I can override the onSubmit() method of my form. Below are my files. When I add the form to a wicket page with add(new TemplateEditForm(templateeditform, templatemodel)); and the corresponding html code form wicket:id=templateeditformeditform/form My wicket code doesn't pick the wicket:ids in the TemplateEditForm.html file up WicketMessage: The component(s) below failed to render. A common problem is that you have added a component in code but forgot to reference it in the markup (thus the component will never be rendered). 1. [MarkupContainer [Component id = name]] 2. [MarkupContainer [Component id = version]] 3. [MarkupContainer [Component id = author]] 4. [MarkupContainer [Component id = active]] 5. [MarkupContainer [Component id = description]] 6. [MarkupContainer [Component id = textarea]] 7. [MarkupContainer [Component id = type]] 8. [MarkupContainer [Component id = submit]] I am sure I am doing something stupid, but I cannot find the solution to this. Any ideas? = public class TemplateEditForm extends Form { private TemplateWebModel templatemodel; public TemplateEditForm(String id, TemplateWebModel templatemodel) { super(id); this.templatemodel = templatemodel; setModel(new CompoundPropertyModel(templatemodel)); add(new RequiredTextField(name)); add(new RequiredTextField(version, java.lang.Long.class)); add(new RequiredTextField(author)); add(new CheckBox(active)); add(new VariableTextFieldPanel(description, new PropertyModel( templatemodel.getObject(), description))); DropDownChoice ddc = new DropDownChoice(type, Arrays .asList(TemplateType.values()), new IChoiceRenderer() { public Object getDisplayValue(Object object) { return getString(object.toString()); } public String getIdValue(Object object, int index) { return object.toString(); } }); ddc.setRequired(true); add(ddc); add(new Button(submit, new ResourceModel(submit))); } @Override public void onSubmit() { WicketApplication.get().getTemplateFactory().store( templatemodel.getEntity()); setResponsePage(new TemplateListPage()); } } And the corresponding html code === wicket:extend table tr tdwicket:message key=name //td tdinput wicket:id=name //td /tr tr tdwicket:message key=version //td tdinput wicket:id=version //td /tr tr tdwicket:message key=author //td tdinput wicket:id=author //td /tr tr tdwicket:message key=active //td tdinput type=checkbox wicket:id=active //td /tr tr tdwicket:message key=description //td tdspan wicket:id=description/span/td /tr tr tdwicket:message key=type //td tdselect wicket:id=type option/option /select/td /tr tr td colspan=2input wicket:id=submit type=submit/td /tr /table /wicket:extend
Re: How to place form in own public class for extending
But how do you then extend the form in the panel and more importantly, how do you override the onSubmit() method of that form? Cheers, Pieter On Wed, Feb 11, 2009 at 3:50 PM, Ryan Gravener r...@ryangravener.comwrote: I usually make a panel, add the form to the panel and write up the form in the panel's markup. http://wicketstuff.org/wicket13/signin/?wicket:bookmarkablePage=:org.apache.wicket.examples.signin.SignIn Ryan Gravener http://ryangravener.com/flex | http://twitter.com/ryangravener On Wed, Feb 11, 2009 at 9:40 AM, pieter claassen pie...@claassen.co.uk wrote: I am trying to move a form from an inner class that extends Form to a public class. This is so that I can override the onSubmit() method of my form. Below are my files. When I add the form to a wicket page with add(new TemplateEditForm(templateeditform, templatemodel)); and the corresponding html code form wicket:id=templateeditformeditform/form My wicket code doesn't pick the wicket:ids in the TemplateEditForm.html file up WicketMessage: The component(s) below failed to render. A common problem is that you have added a component in code but forgot to reference it in the markup (thus the component will never be rendered). 1. [MarkupContainer [Component id = name]] 2. [MarkupContainer [Component id = version]] 3. [MarkupContainer [Component id = author]] 4. [MarkupContainer [Component id = active]] 5. [MarkupContainer [Component id = description]] 6. [MarkupContainer [Component id = textarea]] 7. [MarkupContainer [Component id = type]] 8. [MarkupContainer [Component id = submit]] I am sure I am doing something stupid, but I cannot find the solution to this. Any ideas? = public class TemplateEditForm extends Form { private TemplateWebModel templatemodel; public TemplateEditForm(String id, TemplateWebModel templatemodel) { super(id); this.templatemodel = templatemodel; setModel(new CompoundPropertyModel(templatemodel)); add(new RequiredTextField(name)); add(new RequiredTextField(version, java.lang.Long.class)); add(new RequiredTextField(author)); add(new CheckBox(active)); add(new VariableTextFieldPanel(description, new PropertyModel( templatemodel.getObject(), description))); DropDownChoice ddc = new DropDownChoice(type, Arrays .asList(TemplateType.values()), new IChoiceRenderer() { public Object getDisplayValue(Object object) { return getString(object.toString()); } public String getIdValue(Object object, int index) { return object.toString(); } }); ddc.setRequired(true); add(ddc); add(new Button(submit, new ResourceModel(submit))); } @Override public void onSubmit() { WicketApplication.get().getTemplateFactory().store( templatemodel.getEntity()); setResponsePage(new TemplateListPage()); } } And the corresponding html code === wicket:extend table tr tdwicket:message key=name //td tdinput wicket:id=name //td /tr tr tdwicket:message key=version //td tdinput wicket:id=version //td /tr tr tdwicket:message key=author //td tdinput wicket:id=author //td /tr tr tdwicket:message key=active //td tdinput type=checkbox wicket:id=active //td /tr tr tdwicket:message key=description //td tdspan wicket:id=description/span/td /tr tr tdwicket:message key=type //td tdselect wicket:id=type option/option /select/td /tr tr td colspan=2input wicket:id=submit type=submit/td /tr /table /wicket:extend
Re: How to place form in own public class for extending
what is the problem of having the form as an inner class? public class mypage extends webpage { private class myform extends form { ... } public mypage() { add(new myform(..) { protected void onsubmit() {...}}); } } -igor On Wed, Feb 11, 2009 at 6:40 AM, pieter claassen pie...@claassen.co.uk wrote: I am trying to move a form from an inner class that extends Form to a public class. This is so that I can override the onSubmit() method of my form. Below are my files. When I add the form to a wicket page with add(new TemplateEditForm(templateeditform, templatemodel)); and the corresponding html code form wicket:id=templateeditformeditform/form My wicket code doesn't pick the wicket:ids in the TemplateEditForm.html file up WicketMessage: The component(s) below failed to render. A common problem is that you have added a component in code but forgot to reference it in the markup (thus the component will never be rendered). 1. [MarkupContainer [Component id = name]] 2. [MarkupContainer [Component id = version]] 3. [MarkupContainer [Component id = author]] 4. [MarkupContainer [Component id = active]] 5. [MarkupContainer [Component id = description]] 6. [MarkupContainer [Component id = textarea]] 7. [MarkupContainer [Component id = type]] 8. [MarkupContainer [Component id = submit]] I am sure I am doing something stupid, but I cannot find the solution to this. Any ideas? = public class TemplateEditForm extends Form { private TemplateWebModel templatemodel; public TemplateEditForm(String id, TemplateWebModel templatemodel) { super(id); this.templatemodel = templatemodel; setModel(new CompoundPropertyModel(templatemodel)); add(new RequiredTextField(name)); add(new RequiredTextField(version, java.lang.Long.class)); add(new RequiredTextField(author)); add(new CheckBox(active)); add(new VariableTextFieldPanel(description, new PropertyModel( templatemodel.getObject(), description))); DropDownChoice ddc = new DropDownChoice(type, Arrays .asList(TemplateType.values()), new IChoiceRenderer() { public Object getDisplayValue(Object object) { return getString(object.toString()); } public String getIdValue(Object object, int index) { return object.toString(); } }); ddc.setRequired(true); add(ddc); add(new Button(submit, new ResourceModel(submit))); } @Override public void onSubmit() { WicketApplication.get().getTemplateFactory().store( templatemodel.getEntity()); setResponsePage(new TemplateListPage()); } } And the corresponding html code === wicket:extend table tr tdwicket:message key=name //td tdinput wicket:id=name //td /tr tr tdwicket:message key=version //td tdinput wicket:id=version //td /tr tr tdwicket:message key=author //td tdinput wicket:id=author //td /tr tr tdwicket:message key=active //td tdinput type=checkbox wicket:id=active //td /tr tr tdwicket:message key=description //td tdspan wicket:id=description/span/td /tr tr tdwicket:message key=type //td tdselect wicket:id=type option/option /select/td /tr tr td colspan=2input wicket:id=submit type=submit/td /tr /table /wicket:extend - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: How to place form in own public class for extending
What if you want to reuse the inner class form in another page (you have to make it public and non-inner for visibility) and then you want to override the onSubmit() method. If I just create a public class MyForm and stick the form contents (minus the form tags) in MyForm.html, then wicket cannot find any wicket variables on the form (see first post). If you encapsulate the form in a panel, then the only problem is that you cannot get to the onSubmit() method of the form (but if you delegate all the work to a public method on the panel, then you can override that). Not so pretty. This is a bit of a corner case, but the fact is that forms are not readily accessible wicket objects like panels and pages ( you cannot easily extend your own publically accessible forms) or am I missing something? Pieter On Wed, Feb 11, 2009 at 4:28 PM, Igor Vaynberg igor.vaynb...@gmail.comwrote: what is the problem of having the form as an inner class? public class mypage extends webpage { private class myform extends form { ... } public mypage() { add(new myform(..) { protected void onsubmit() {...}}); } } -igor On Wed, Feb 11, 2009 at 6:40 AM, pieter claassen pie...@claassen.co.uk wrote: I am trying to move a form from an inner class that extends Form to a public class. This is so that I can override the onSubmit() method of my form. Below are my files. When I add the form to a wicket page with add(new TemplateEditForm(templateeditform, templatemodel)); and the corresponding html code form wicket:id=templateeditformeditform/form My wicket code doesn't pick the wicket:ids in the TemplateEditForm.html file up WicketMessage: The component(s) below failed to render. A common problem is that you have added a component in code but forgot to reference it in the markup (thus the component will never be rendered). 1. [MarkupContainer [Component id = name]] 2. [MarkupContainer [Component id = version]] 3. [MarkupContainer [Component id = author]] 4. [MarkupContainer [Component id = active]] 5. [MarkupContainer [Component id = description]] 6. [MarkupContainer [Component id = textarea]] 7. [MarkupContainer [Component id = type]] 8. [MarkupContainer [Component id = submit]] I am sure I am doing something stupid, but I cannot find the solution to this. Any ideas? = public class TemplateEditForm extends Form { private TemplateWebModel templatemodel; public TemplateEditForm(String id, TemplateWebModel templatemodel) { super(id); this.templatemodel = templatemodel; setModel(new CompoundPropertyModel(templatemodel)); add(new RequiredTextField(name)); add(new RequiredTextField(version, java.lang.Long.class)); add(new RequiredTextField(author)); add(new CheckBox(active)); add(new VariableTextFieldPanel(description, new PropertyModel( templatemodel.getObject(), description))); DropDownChoice ddc = new DropDownChoice(type, Arrays .asList(TemplateType.values()), new IChoiceRenderer() { public Object getDisplayValue(Object object) { return getString(object.toString()); } public String getIdValue(Object object, int index) { return object.toString(); } }); ddc.setRequired(true); add(ddc); add(new Button(submit, new ResourceModel(submit))); } @Override public void onSubmit() { WicketApplication.get().getTemplateFactory().store( templatemodel.getEntity()); setResponsePage(new TemplateListPage()); } } And the corresponding html code === wicket:extend table tr tdwicket:message key=name //td tdinput wicket:id=name //td /tr tr tdwicket:message key=version //td tdinput wicket:id=version //td /tr tr tdwicket:message key=author //td tdinput wicket:id=author //td /tr tr tdwicket:message key=active //td tdinput type=checkbox wicket:id=active //td /tr tr tdwicket:message key=description //td tdspan wicket:id=description/span/td /tr tr tdwicket:message key=type //td tdselect wicket:id=type option/option /select/td /tr tr td colspan=2input wicket:id=submit type=submit/td /tr /table /wicket:extend - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: How to place form in own public class for extending
On Wed, Feb 11, 2009 at 8:52 AM, pieter claassen pieter.claas...@gmail.com wrote: What if you want to reuse the inner class form in another page (you have to make it public and non-inner for visibility) and then you want to override the onSubmit() method. If I just create a public class MyForm and stick the form contents (minus the form tags) in MyForm.html, then wicket cannot find any wicket variables on the form (see first post). yes, what if what if. notice i replied to your original email, in which you make no mention of reusability. If you encapsulate the form in a panel, then the only problem is that you cannot get to the onSubmit() method of the form (but if you delegate all the work to a public method on the panel, then you can override that). Not so pretty. so something like this is horrible right: class myform extends panel { protected void onsubmit() {} public myform(string id) { super(id); add(new form(form) { onsubmit() { myform.this.onsubmit(); }}); } } yes, it looks horrific. This is a bit of a corner case, but the fact is that forms are not readily accessible wicket objects like panels and pages ( you cannot easily extend your own publically accessible forms) or am I missing something? in wicket there are two kinds of components: ones that provide their own markup and ones that do not. the core team feels that we have covered all the core usecases with pages, panels, fragments, and formcomponentpanels. your usecase can be handled by selecting the reusability unit to be a formcomponentpanel which contains the innards of your form rather then the form itself. that said, you can easily implement a form variant which provides its own markup. see FormComponentPanel for clues. -igor Pieter On Wed, Feb 11, 2009 at 4:28 PM, Igor Vaynberg igor.vaynb...@gmail.comwrote: what is the problem of having the form as an inner class? public class mypage extends webpage { private class myform extends form { ... } public mypage() { add(new myform(..) { protected void onsubmit() {...}}); } } -igor On Wed, Feb 11, 2009 at 6:40 AM, pieter claassen pie...@claassen.co.uk wrote: I am trying to move a form from an inner class that extends Form to a public class. This is so that I can override the onSubmit() method of my form. Below are my files. When I add the form to a wicket page with add(new TemplateEditForm(templateeditform, templatemodel)); and the corresponding html code form wicket:id=templateeditformeditform/form My wicket code doesn't pick the wicket:ids in the TemplateEditForm.html file up WicketMessage: The component(s) below failed to render. A common problem is that you have added a component in code but forgot to reference it in the markup (thus the component will never be rendered). 1. [MarkupContainer [Component id = name]] 2. [MarkupContainer [Component id = version]] 3. [MarkupContainer [Component id = author]] 4. [MarkupContainer [Component id = active]] 5. [MarkupContainer [Component id = description]] 6. [MarkupContainer [Component id = textarea]] 7. [MarkupContainer [Component id = type]] 8. [MarkupContainer [Component id = submit]] I am sure I am doing something stupid, but I cannot find the solution to this. Any ideas? = public class TemplateEditForm extends Form { private TemplateWebModel templatemodel; public TemplateEditForm(String id, TemplateWebModel templatemodel) { super(id); this.templatemodel = templatemodel; setModel(new CompoundPropertyModel(templatemodel)); add(new RequiredTextField(name)); add(new RequiredTextField(version, java.lang.Long.class)); add(new RequiredTextField(author)); add(new CheckBox(active)); add(new VariableTextFieldPanel(description, new PropertyModel( templatemodel.getObject(), description))); DropDownChoice ddc = new DropDownChoice(type, Arrays .asList(TemplateType.values()), new IChoiceRenderer() { public Object getDisplayValue(Object object) { return getString(object.toString()); } public String getIdValue(Object object, int index) { return object.toString(); } }); ddc.setRequired(true); add(ddc); add(new Button(submit, new ResourceModel(submit))); } @Override public void onSubmit() { WicketApplication.get().getTemplateFactory().store( templatemodel.getEntity()); setResponsePage(new TemplateListPage()); } } And the corresponding html code === wicket:extend table tr tdwicket:message key=name //td tdinput wicket:id=name //td /tr tr tdwicket:message key=version //td tdinput wicket:id=version