Sven, thank you.
I had a look at the Ajax example. I think you mean that I need to use
the PanelDetails class as a model, and create all the properties in
it. This is very verbose as the Product class contains many fields
that I need to edit, and adding getters/setters to the PanelDetails
class will make it big, and the code is repeated.
Based on the example, my class should be:


public class ProductDetails extends Panel {

        @EJB
        private ProductServicesLocal productServices;
        private Product product;

        public ProductDetails(String id, Product product) {
                super(id);
                setOutputMarkupId(true);
                this.setCurrentProduct(product);
                add(new Label("id"));
                
                add(new AjaxEditableLabel<String>("codProduct"));

                add(new AjaxLink<String>("save") {
                        @Override
                        public void onClick(AjaxRequestTarget target) {
                                System.out.println("saving product .... ");
                        }
                });
        }

        public void setCurrentProduct(Product product) {
                this.product = product;
                setDefaultModel(new 
CompoundPropertyModel<ProductDetails>(this));
        }

        public void setCodProduct(String codProduct) {
                this.product.setCodProduct(codProduct);
        }
        public String getCodProduct() {
                return this.product.getCodProduct();
        }
}

This brings up a question, what is the best way to wrap domain objects
in a Model for easy CRUD and with a minimum amount of coding, and
reusing the component (ie, without having to recreate the object) ?


On Thu, Jul 15, 2010 at 10:12 PM, Sven Meier <s...@meiers.net> wrote:
> Hi,
>
> please see EditableLabelPage.java in wicket-examples for AjaxEditableLabels
> working with a CompoundPropertyModel.
>
>> Why would the reference be outdated, since ProperyModel is considered
>> dynamic module ?
>
> PropertyModel is dynamic in the property it provides, but it is hard-wired
> on the object you give to its constructor.
>
> Hope this helps
>
> Sven
>
>
> On 07/15/2010 08:36 PM, Mansour Al Akeel wrote:
>>
>> Sven,
>> thank you, but it worked when using this ?
>>
>> add(new Label("codProduct"));
>>
>> Is there an easy way to update the default model And the
>> AjaxEditableLabel in the similar fasion?  Nice to have an example.
>> Why would the reference be outdated, since ProperyModel is considered
>> dynamic module ?
>>
>> Thank you.
>>
>> On Thu, Jul 15, 2010 at 8:35 PM, Sven Meier<s...@meiers.net>  wrote:
>>
>>>
>>> Hi,
>>>
>>> it's the "outdated reference" problem (as often when something goes wrong
>>> with models):
>>>
>>>  new PropertyModel<String>(getDefaultModel(), "codProduct"))
>>>
>>> Note that you're putting the current default model into another model.
>>> Later on you change the default model:
>>>
>>>  setDefaultModel(new CompoundPropertyModel<Product>(product))
>>>
>>> How should your PropertyModel be aware of this change?
>>>
>>> BTW Martijn's statement is incorrect:
>>>
>>>>
>>>> If you look at the source code for AjaxEditableLabel you could've seen
>>>> that it is not suited for CompoundPropertyModel usage.
>>>>
>>>
>>> AjaxEditableLabel is very well capable of working with
>>> CompoundPropertyModels, see AjaxEditableLabel#getParentModel().
>>>
>>> Regards
>>>
>>> Sven
>>>
>>>
>>> On 07/15/2010 04:29 PM, Mansour Al Akeel wrote:
>>>
>>>>
>>>> Hello Martrin, and Ernesto,
>>>> it's still not working. I have this ProductPanel to be updated and
>>>> (possibly edited). It shows the product info when an item is clicked.
>>>> Here's the code for the Product Panel:
>>>>
>>>> public class ProductDetails extends Panel {
>>>>
>>>>       �...@ejb
>>>>        private ProductServicesLocal productServices;
>>>>
>>>>        public ProductDetails(String id, final Product product) {
>>>>                super(id);
>>>>                setOutputMarkupId(true);
>>>>                this.setCurrentProduct(product);
>>>>                add(new Label("id"));
>>>>
>>>>                add(new AjaxEditableLabel<String>("codProduct",
>>>>                                new
>>>> PropertyModel<String>(getDefaultModel(), "codProduct")));
>>>>
>>>>                add(new Label("tpVat"));
>>>>
>>>>                add(new AjaxLink<String>("save") {
>>>>                       �...@override
>>>>                        public void onClick(AjaxRequestTarget target) {
>>>>                                System.out.println("saving product ....
>>>> ");
>>>>                        }
>>>>                });
>>>>        }
>>>>
>>>>        public void setCurrentProduct(Product product) {
>>>>                setDefaultModel(new
>>>> CompoundPropertyModel<Product>(product));
>>>>        }
>>>> }
>>>>
>>>> And here's the code for the item to update the panel:
>>>>
>>>>
>>>>                                AjaxLink<String>    link = new
>>>> AjaxLink<String>("link") {
>>>>                                        {
>>>>                                                add(new Label("id", new
>>>> PropertyModel<String>(model,
>>>>                                                                "id")));
>>>>                                        }
>>>>                                       �...@override
>>>>                                        public void
>>>> onClick(AjaxRequestTarget target) {
>>>>                                                Product product =
>>>> item.getModelObject();
>>>>
>>>>  productDetails.setCurrentProduct(product);
>>>>
>>>>  target.addComponent(productDetails);
>>>>
>>>>  System.out.println(product.getId());
>>>>                                        }
>>>>                                };
>>>>                                item.add(link);
>>>>
>>>>
>>>> The problem with this code, is the Editable Label doesn't update with
>>>> the rest of the labels. I mean if I click on an item, it shows me the
>>>> results for the corresponding product in the Labels, but not in the
>>>> AjaxEditableLabel.
>>>>
>>>>
>>>>
>>>> On Thu, Jul 15, 2010 at 3:48 PM, Martin Makundi
>>>> <martin.maku...@koodaripalvelut.com>    wrote:
>>>>
>>>>
>>>>>
>>>>> you need to add the updated panel into target:
>>>>>
>>>>> target.addComponent(panelToBeUpdated);
>>>>>
>>>>>
>>>>>
>>>>> 2010/7/15 Mansour Al Akeel<mansour.alak...@gmail.com>:
>>>>>
>>>>>
>>>>>>
>>>>>> I just tried it. It doesn't update the panel. Here's the full code:
>>>>>>
>>>>>> public class ProductDetails extends Panel {
>>>>>>
>>>>>>       �...@ejb
>>>>>>        private ProductServicesLocal productServices;
>>>>>>
>>>>>>        public ProductDetails(String id, final Product product) {
>>>>>>                super(id);
>>>>>>                setOutputMarkupId(true);
>>>>>>                this.setCurrentProduct(product);
>>>>>>                add(new Label("id"));
>>>>>>
>>>>>>                add(new AjaxEditableLabel<String>("codProduct",
>>>>>>                                new
>>>>>> PropertyModel<String>((Product)getDefaultModelObject(),
>>>>>> "codProduct")));
>>>>>>
>>>>>>                add(new AjaxLink<String>("save") {
>>>>>>                       �...@override
>>>>>>                        public void onClick(AjaxRequestTarget target) {
>>>>>>                                System.out.println("saving product ....
>>>>>> ");
>>>>>>                        }
>>>>>>                });
>>>>>>        }
>>>>>>
>>>>>>        public void setCurrentProduct(Product product) {
>>>>>>                setDefaultModel(new
>>>>>> CompoundPropertyModel<Product>(product));
>>>>>>        }
>>>>>> }
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>>>>>> For additional commands, e-mail: users-h...@wicket.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>>>>> For additional commands, e-mail: users-h...@wicket.apache.org
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>>>> For additional commands, e-mail: users-h...@wicket.apache.org
>>>>
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>>> For additional commands, e-mail: users-h...@wicket.apache.org
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> For additional commands, e-mail: users-h...@wicket.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

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

Reply via email to