I have simple case, which worked for me in another project but failed in the
current one. Both use same set of libraries. I am doing something wrong,
could not trace it down. Please help to debug this.

I am designing a reusable form & textfield component, which will have
provision to show feedback beneath each text field and so on. The problem I
am facing is, MyTextField is a border which in turn contains TextField, this
text field is set as required = true, when i submit the form, onSubmit from
the submit button gets called instead of onError. 

But if I add a plain raw textfield directly to MyFormBorder it works as
expected, i.e onError is called when no value is entered. 

How do I debug this problem ? Please assist. I am using wicket 1.4.19

Code Below
------------

public class MyFormBorder extends Border {

        FeedbackPanel fbp;
        Form form;
        
        public MyFormBorder(String id, IModel model) {
                super(id);
                fbp = new FeedbackPanel("feedback");
                fbp.setOutputMarkupId(true);
                add(fbp);
                
                form = new Form("form", model);
                form.add(getBodyContainer());
                add(form);
        }
        
        public void onError(AjaxRequestTarget target, Form form) {
                if(form.hasFeedbackMessage()) {
                        
fbp.info(form.getFeedbackMessage().getMessage().toString());
                }
                target.addComponent(fbp);
        }
        
        public Form getForm() {
                return form;
        }
}


Html
-----
<wicket:border>
        <div wicket:id="feedback"></div>
        <form wicket:id="form" class="form">
                <wicket:body/>
        </form>
</wicket:border>


TextField
---------
public class MyTextField extends Border {

        ComponentFeedbackPanel cfbp;
        TextField textField;
        WebMarkupContainer cntr = new WebMarkupContainer("cntr");
        
        public MyTextField(String id, String label, IModel model, boolean 
required)
{
                super(id);
                cntr.setOutputMarkupId(true);
                cntr.add(new Label("label", label));
                
                textField = new TextField("textfield", model);
                textField.setLabel(new Model(label));
                textField.setRequired(required);
                cntr.add(textField);
                
                cfbp = new ComponentFeedbackPanel("cfbp", textField);
                cfbp.setOutputMarkupId(true);
                cfbp.setVisible(false);
                cntr.add(cfbp);
                
                cntr.add(getBodyContainer());
                add(cntr);
        }
        

}

HTML
-----
<wicket:border>
        <div wicket:id="cntr" class="type-text">
                <strong wicket:id="cfbp" class="message"></strong>
                <label for="" wicket:id="label"></label>
                <input wicket:id="textfield" style="" type="text"></input>
                <wicket:body/>
                <wicket:child/>
        </div>
</wicket:border>


I am using these myformborder & mytextfield as below

Menu menu = new Menu();
                
MyFormBorder myFormBorder = new MyFormBorder("ffborder", new Model(menu));
                
MyTextField ftf = new MyTextField("name", "Menu Name", new
PropertyModel(menu, "name"), true);
myFormBorder.add(ftf);
        
// Without the following textfield getting directly added, onError is not
called for the above text field 
TextField tf = new TextField("desc", new PropertyModel(menu,
"description"));
tf.setRequired(true);
forceFormBorder.add(tf);
                
AjaxSubmitButton submit = new AjaxSubmitButton("submit",
forceFormBorder.getForm()) {
                        
        @Override
        protected void onSubmit(AjaxRequestTarget arg0, Form<?> arg1) {
                System.out.println("onSubmit...");
        }
                        
        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
                System.out.println("onError...");
        }
};
forceFormBorder.add(submit);
add(forceFormBorder);

HTML
-----
<div wicket:id="ffborder">
        <div wicket:id="name"></div>
        <input type="text" wicket:id="desc"/>
         # Submit 
</div>



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/wicket-form-debug-tp3915041p3915041.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to