I'm trying to wrap my head around how I would create a page where I could either edit an existing record or create a new one.

Currently, I've got a form where I can add a record to the database - that part is working great.  I'd like to refactor it now to also edit an existing record, if there is one.  The user would choose a record from a ListView below the form and the form would be populated w/ the values of that entity bean.  The user would change values and then submit the form.

My first idea was to pass the object into the constructor of the page class:

public EditProduct(Product editProduct)

...and then decide inside the constructor whether or not to create a new Product object or use the one passed in:

        //edit or new?
        Product p = null;       
        if (editProduct == null)
            p = new Product();
        else
            p = editProduct;

I would then pass the Product into the form:

add(new EditProductForm("editProductForm", p));

...which would be bound like so:

        public EditProductForm(String name, Product product)
        {
            super(name, new CompoundPropertyModel(product));
..........

However, I didn't realize you had to do everything within the *default* constructor of the WebPage derived class...oops!  I start to see this exception all over again:

wicket.markup.MarkupException : Unable to find component with id 'headerPanel' in......

Am I making this more complicated than it needs to be?  What is a better approach?

Thanks!

Reply via email to