So, I'm trying to figure out if I should do with my form buttons.  I have two buttons ('save' and 'cancel') but only the onSubmit event handler is fired.  I have a button inside of the form's constructor that has an onClick event but that never happens...apparently because the onSubmit 'trumps' the onClick event.

Here's my class as it stands:

    private static class EditProductForm extends Form
    {
        public EditProductForm(String name, Product product)
        {
            super(name, new CompoundPropertyModel(product));
           
            //get collection of Category items
            IModel catsModel = new LoadableDetachableModel()
            {
                protected Object load()
                {
                    return ProductProxy.getAllCategories(); //via proxy
                }
            };
           
            //add form components
            add(new TextField("productCode").add(RequiredValidator.getInstance ()));
            add(new TextField("name").add(RequiredValidator.getInstance()));
            add(new TextArea("summary").add(RequiredValidator.getInstance()));
            add(new Button("saveButton"));
           
            //add reset button DOESN'T WORK!
            add(new Button("cancelButton")
            {
                public void onClick()
                {
                    modelChanged();
                    setResponsePage(new EditProduct());
                }
            });
        }
       
        public void onSubmit()
        {
            //save form values, redirect
            Product product = (Product)getModelObject();
            ProductProxy.addProduct(product);
            setResponsePage(new EditProduct());
        }
    }

Should I leave onSubmit empty and use two onClick events for the form buttons?

The form is doing validation, also, if that effects anything.

Thanks!

Reply via email to